auth.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: auth.c /main/6 1997/03/14 13:44:25 barstow $ */
  24. /* (c) Copyright 1997 The Open Group */
  25. /* *
  26. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  27. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  28. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  29. * (c) Copyright 1993, 1994 Novell, Inc. *
  30. */
  31. /*
  32. * @DEC_COPYRIGHT@
  33. */
  34. /*
  35. * HISTORY
  36. * $Log$
  37. * Revision 1.1.2.3 1995/06/06 20:21:58 Chris_Beute
  38. * Code snapshot merge from March 15 and SIA changes
  39. * [1995/05/31 20:09:58 Chris_Beute]
  40. *
  41. * Revision 1.1.2.2 1995/04/21 13:05:15 Peter_Derr
  42. * dtlogin auth key fixes from deltacde
  43. * [1995/04/12 19:20:51 Peter_Derr]
  44. *
  45. * R6 version of auth.c to handle multiple authentication protocols.
  46. * [1995/04/12 18:05:30 Peter_Derr]
  47. *
  48. * $EndLog$
  49. */
  50. /*
  51. Copyright (c) 1988 X Consortium
  52. Permission is hereby granted, free of charge, to any person obtaining
  53. a copy of this software and associated documentation files (the
  54. "Software"), to deal in the Software without restriction, including
  55. without limitation the rights to use, copy, modify, merge, publish,
  56. distribute, sublicense, and/or sell copies of the Software, and to
  57. permit persons to whom the Software is furnished to do so, subject to
  58. the following conditions:
  59. The above copyright notice and this permission notice shall be included
  60. in all copies or substantial portions of the Software.
  61. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  62. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  63. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  64. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  65. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  66. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  67. OTHER DEALINGS IN THE SOFTWARE.
  68. Except as contained in this notice, the name of the X Consortium shall
  69. not be used in advertising or otherwise to promote the sale, use or
  70. other dealings in this Software without prior written authorization
  71. from the X Consortium.
  72. */
  73. /*
  74. * xdm - display manager daemon
  75. * Author: Keith Packard, MIT X Consortium
  76. *
  77. * auth.c
  78. *
  79. * maintain the authorization generation daemon
  80. */
  81. #include "dm.h"
  82. #include "vgmsg.h"
  83. #include <X11/X.h>
  84. #include <sys/types.h>
  85. #include <sys/stat.h>
  86. #include <errno.h>
  87. #ifdef X_NOT_STDC_ENV
  88. extern int errno;
  89. #endif
  90. #include <sys/socket.h>
  91. #ifndef ESIX
  92. # include <sys/ioctl.h>
  93. #endif /* !ESIX */
  94. #ifdef TCPCONN
  95. # include <netinet/in.h>
  96. #endif
  97. #ifdef DNETCONN
  98. # include <netdnet/dn.h>
  99. # include <netdnet/dnetdb.h>
  100. #endif
  101. #if (defined(_POSIX_SOURCE) && !defined(AIXV3)) || defined(hpux) || defined(USG) || defined(SVR4)
  102. #define NEED_UTSNAME
  103. #include <sys/utsname.h>
  104. #endif
  105. #if defined(SYSV) && defined(SYSV386)
  106. # include <sys/stream.h>
  107. # ifdef ISC
  108. # include <sys/sioctl.h>
  109. # endif /* ISC */
  110. # ifdef ESIX
  111. # include <lan/net_ioctl.h>
  112. # endif /* ESIX */
  113. #endif /* SYSV386 */
  114. #ifdef SVR4
  115. # include <netdb.h>
  116. # include <sys/sockio.h>
  117. #endif
  118. #ifdef __convex__
  119. # include <sync/queue.h>
  120. # include <sync/sema.h>
  121. #endif
  122. #include <net/if.h>
  123. #ifdef SECURE_RPC
  124. extern int SecureRPCInitAuth ();
  125. extern Xauth *SecureRPCGetAuth ();
  126. #endif
  127. #ifdef K5AUTH
  128. extern int Krb5InitAuth ();
  129. extern Xauth *Krb5GetAuth ();
  130. #endif
  131. struct AuthProtocol {
  132. unsigned short name_length;
  133. char *name;
  134. int (*InitAuth)(
  135. #if NeedWidePrototypes
  136. unsigned int name_len,
  137. #else
  138. unsigned short name_len,
  139. #endif /* NeedWidePrototypes */
  140. char *name) ;
  141. Xauth *(*GetAuth)(
  142. #if NeedWidePrototypes
  143. unsigned int namelen,
  144. #else
  145. unsigned short namelen,
  146. #endif /* NeedWidePrototypes */
  147. char *name) ;
  148. void (*GetXdmcpAuth)();
  149. int inited;
  150. };
  151. static struct AuthProtocol AuthProtocols[] = {
  152. { (unsigned short) 18, "MIT-MAGIC-COOKIE-1",
  153. MitInitAuth, MitGetAuth, NULL
  154. },
  155. #ifdef HASXDMAUTH
  156. { (unsigned short) 19, "XDM-AUTHORIZATION-1",
  157. XdmInitAuth, XdmGetAuth, XdmGetXdmcpAuth,
  158. },
  159. #endif
  160. #ifdef SECURE_RPC
  161. { (unsigned short) 9, "SUN-DES-1",
  162. SecureRPCInitAuth, SecureRPCGetAuth, NULL,
  163. },
  164. #endif
  165. #ifdef K5AUTH
  166. { (unsigned short) 14, "MIT-KERBEROS-5",
  167. Krb5InitAuth, Krb5GetAuth, NULL,
  168. },
  169. #endif
  170. };
  171. #define NUM_AUTHORIZATION (sizeof (AuthProtocols) / sizeof (AuthProtocols[0]))
  172. static struct AuthProtocol *
  173. findProtocol (unsigned short name_length, const char *name)
  174. {
  175. int i;
  176. for (i = 0; i < NUM_AUTHORIZATION; i++)
  177. if (AuthProtocols[i].name_length == name_length &&
  178. memcmp(AuthProtocols[i].name, name, name_length) == 0)
  179. {
  180. return &AuthProtocols[i];
  181. }
  182. return (struct AuthProtocol *) 0;
  183. }
  184. #if NeedWidePrototypes
  185. int
  186. ValidAuthorization (unsigned int name_length, char *name)
  187. #else
  188. int
  189. ValidAuthorization (unsigned short name_length, char *name)
  190. #endif /* NeedWidePrototypes */
  191. {
  192. if (findProtocol (name_length, name))
  193. return TRUE;
  194. return FALSE;
  195. }
  196. static Xauth *
  197. GenerateAuthorization (unsigned short name_length, char *name)
  198. {
  199. struct AuthProtocol *a;
  200. Xauth *auth = 0;
  201. int i;
  202. Debug ("GenerateAuthorization %*.*s\n",
  203. name_length, name_length, name);
  204. a = findProtocol (name_length, name);
  205. if (a)
  206. {
  207. if (!a->inited)
  208. {
  209. (*a->InitAuth) (name_length, name);
  210. a->inited = TRUE;
  211. }
  212. auth = (*a->GetAuth) (name_length, name);
  213. if (auth)
  214. {
  215. Debug ("Got 0x%x (%d %*.*s) ", auth,
  216. auth->name_length, auth->name_length,
  217. auth->name_length, auth->name);
  218. for (i = 0; i < (int)auth->data_length; i++)
  219. Debug (" %02x", auth->data[i] & 0xff);
  220. Debug ("\n");
  221. }
  222. else
  223. Debug ("Got (null)\n");
  224. }
  225. else
  226. {
  227. Debug ("Unknown authorization %*.*s\n", name_length, name_length, name);
  228. }
  229. return auth;
  230. }
  231. #if NeedWidePrototypes
  232. void
  233. SetProtoDisplayAuthorization (struct protoDisplay *pdpy, unsigned int authorizationNameLen, char *authorizationName)
  234. #else
  235. void
  236. SetProtoDisplayAuthorization (struct protoDisplay *pdpy, unsigned short authorizationNameLen, char *authorizationName)
  237. #endif /* NeedWidePrototypes */
  238. {
  239. struct AuthProtocol *a;
  240. Xauth *auth;
  241. a = findProtocol (authorizationNameLen, authorizationName);
  242. pdpy->xdmcpAuthorization = pdpy->fileAuthorization = 0;
  243. if (a)
  244. {
  245. if (!a->inited)
  246. {
  247. (*a->InitAuth) (authorizationNameLen, authorizationName);
  248. a->inited = TRUE;
  249. }
  250. if (a->GetXdmcpAuth)
  251. {
  252. (*a->GetXdmcpAuth) (pdpy, authorizationNameLen, authorizationName);
  253. auth = pdpy->xdmcpAuthorization;
  254. }
  255. else
  256. {
  257. auth = (*a->GetAuth) (authorizationNameLen, authorizationName);
  258. pdpy->fileAuthorization = auth;
  259. pdpy->xdmcpAuthorization = 0;
  260. }
  261. if (auth)
  262. Debug ("Got 0x%x (%d %*.*s)\n", auth,
  263. auth->name_length, auth->name_length,
  264. auth->name_length, auth->name);
  265. else
  266. Debug ("Got (null)\n");
  267. }
  268. }
  269. void
  270. CleanUpFileName (char *src, char *dst, int len)
  271. {
  272. while (*src) {
  273. if (--len <= 0)
  274. break;
  275. switch (*src & 0x7f)
  276. {
  277. case '/':
  278. *dst++ = '_';
  279. break;
  280. case '-':
  281. *dst++ = '.';
  282. break;
  283. default:
  284. *dst++ = (*src & 0x7f);
  285. }
  286. ++src;
  287. }
  288. *dst = '\0';
  289. }
  290. static char authdir1[] = "authdir";
  291. static char authdir2[] = "authfiles";
  292. static int
  293. MakeServerAuthFile (struct display *d)
  294. {
  295. int len;
  296. #ifdef SYSV
  297. #define NAMELEN 14
  298. #else
  299. #define NAMELEN 255
  300. #endif
  301. char cleanname[NAMELEN];
  302. int r;
  303. struct stat statb;
  304. if (d->clientAuthFile && *d->clientAuthFile)
  305. len = strlen (d->clientAuthFile) + 1;
  306. else
  307. {
  308. CleanUpFileName (d->name, cleanname, NAMELEN - 8);
  309. len = strlen (authDir) + strlen (authdir1) + strlen (authdir2)
  310. + strlen (cleanname) + 14;
  311. }
  312. if (d->authFile)
  313. free (d->authFile);
  314. d->authFile = malloc ((unsigned) len);
  315. if (!d->authFile)
  316. return FALSE;
  317. if (d->clientAuthFile && *d->clientAuthFile)
  318. strcpy (d->authFile, d->clientAuthFile);
  319. else
  320. {
  321. sprintf (d->authFile, "%s/%s", authDir, authdir1);
  322. r = stat(d->authFile, &statb);
  323. if (r == 0) {
  324. if (statb.st_uid != 0) {
  325. if(-1 == chown(d->authFile, 0, statb.st_gid)) {
  326. perror(strerror(errno));
  327. return FALSE;
  328. }
  329. }
  330. if ((statb.st_mode & 0077) != 0) {
  331. if(-1 == chmod(d->authFile, statb.st_mode & 0700)) {
  332. perror(strerror(errno));
  333. return FALSE;
  334. }
  335. }
  336. } else {
  337. if (errno == ENOENT)
  338. r = mkdir(d->authFile, 0700);
  339. if (r < 0) {
  340. free (d->authFile);
  341. d->authFile = NULL;
  342. return FALSE;
  343. }
  344. }
  345. sprintf (d->authFile, "%s/%s/%s", authDir, authdir1, authdir2);
  346. r = mkdir(d->authFile, 0700);
  347. if (r < 0 && errno != EEXIST) {
  348. free (d->authFile);
  349. d->authFile = NULL;
  350. return FALSE;
  351. }
  352. sprintf (d->authFile, "%s/%s/%s/A%s-XXXXXX",
  353. authDir, authdir1, authdir2, cleanname);
  354. (void) mktemp (d->authFile);
  355. }
  356. return TRUE;
  357. }
  358. int
  359. SaveServerAuthorizations (struct display *d, Xauth **auths, int count)
  360. {
  361. FILE *auth_file;
  362. int mask;
  363. int ret;
  364. int i;
  365. mask = umask (0077);
  366. if (!d->authFile && !MakeServerAuthFile (d))
  367. return FALSE;
  368. (void) unlink (d->authFile);
  369. auth_file = fopen (d->authFile, "w");
  370. umask (mask);
  371. if (!auth_file) {
  372. Debug ("Can't creat auth file %s\n", d->authFile);
  373. LogError (ReadCatalog(MC_LOG_SET,MC_LOG_SRV_OPEN,MC_DEF_LOG_SRV_OPEN),
  374. d->authFile);
  375. free (d->authFile);
  376. d->authFile = NULL;
  377. ret = FALSE;
  378. }
  379. else
  380. {
  381. Debug ("File: %s auth: %x\n", d->authFile, auths);
  382. ret = TRUE;
  383. for (i = 0; i < count; i++)
  384. {
  385. /*
  386. * User-based auths may not have data until
  387. * a user logs in. In which case don't write
  388. * to the auth file so xrdb and setup programs don't fail.
  389. */
  390. if (auths[i]->data_length > 0)
  391. if (!XauWriteAuth (auth_file, auths[i]) ||
  392. fflush (auth_file) == EOF)
  393. {
  394. LogError (
  395. ReadCatalog(MC_LOG_SET,MC_LOG_SRV_WRT,MC_DEF_LOG_SRV_WRT),
  396. d->authFile);
  397. ret = FALSE;
  398. free (d->authFile);
  399. d->authFile = NULL;
  400. }
  401. }
  402. fclose (auth_file);
  403. }
  404. return ret;
  405. }
  406. void
  407. SetLocalAuthorization (struct display *d)
  408. {
  409. Xauth *auth, **auths;
  410. int i, j;
  411. if (d->authorizations)
  412. {
  413. for (i = 0; i < d->authNum; i++)
  414. XauDisposeAuth (d->authorizations[i]);
  415. free ((char *) d->authorizations);
  416. d->authorizations = (Xauth **) NULL;
  417. d->authNum = 0;
  418. }
  419. if (!d->authNames)
  420. return;
  421. for (i = 0; d->authNames[i]; i++)
  422. ;
  423. d->authNameNum = i;
  424. if (d->authNameLens)
  425. free ((char *) d->authNameLens);
  426. d->authNameLens = (unsigned short *) malloc
  427. (d->authNameNum * sizeof (unsigned short));
  428. if (!d->authNameLens)
  429. return;
  430. for (i = 0; i < d->authNameNum; i++)
  431. d->authNameLens[i] = strlen (d->authNames[i]);
  432. auths = (Xauth **) malloc (d->authNameNum * sizeof (Xauth *));
  433. if (!auths)
  434. return;
  435. j = 0;
  436. for (i = 0; i < d->authNameNum; i++)
  437. {
  438. auth = GenerateAuthorization (d->authNameLens[i], d->authNames[i]);
  439. if (auth)
  440. auths[j++] = auth;
  441. }
  442. if (SaveServerAuthorizations (d, auths, j))
  443. {
  444. d->authorizations = auths;
  445. d->authNum = j;
  446. }
  447. else
  448. {
  449. for (i = 0; i < j; i++)
  450. XauDisposeAuth (auths[i]);
  451. free ((char *) auths);
  452. }
  453. }
  454. /*
  455. * Set the authorization to use for xdm's initial connection
  456. * to the X server. Cannot use user-based authorizations
  457. * because no one has logged in yet, so we don't have any
  458. * user credentials.
  459. * Well, actually we could use SUN-DES-1 because we tell the server
  460. * to allow root in. This is bogus and should be fixed.
  461. */
  462. void
  463. SetAuthorization (struct display *d)
  464. {
  465. Xauth **auth = d->authorizations;
  466. int i;
  467. for (i = 0; i < d->authNum; i++)
  468. {
  469. if (auth[i]->name_length == 9 &&
  470. memcmp(auth[i]->name, "SUN-DES-1", 9) == 0)
  471. continue;
  472. if (auth[i]->name_length == 14 &&
  473. memcmp(auth[i]->name, "MIT-KERBEROS-5", 14) == 0)
  474. continue;
  475. XSetAuthorization (auth[i]->name, (int) auth[i]->name_length,
  476. auth[i]->data, (int) auth[i]->data_length);
  477. }
  478. }
  479. static int
  480. openFiles (char *name, char *new_name, FILE **oldp, FILE **newp)
  481. {
  482. int mask;
  483. int null_data = 0;
  484. strcpy (new_name, name);
  485. strcat (new_name, "-n");
  486. mask = umask (0077);
  487. (void) unlink (new_name);
  488. *newp = fopen (new_name, "w");
  489. (void) umask (mask);
  490. if (!*newp) {
  491. Debug ("can't open new file %s\n", new_name);
  492. return 0;
  493. }
  494. /*
  495. * Make sure that the device is not 100% full by actually writing
  496. * to the file.
  497. */
  498. if ((sizeof(int) != fwrite(&null_data, 1, sizeof(int), *newp))
  499. || fflush(*newp)) {
  500. Debug ("can't write to new file %s\n", new_name);
  501. fclose(*newp);
  502. (void) unlink (new_name);
  503. return 0;
  504. }
  505. rewind(*newp);
  506. *oldp = fopen (name, "r");
  507. Debug ("opens succeeded %s %s\n", name, new_name);
  508. return 1;
  509. }
  510. int
  511. binaryEqual (char *a, char *b, unsigned short len)
  512. {
  513. while (len-- > 0)
  514. if (*a++ != *b++)
  515. return 0;
  516. return 1;
  517. }
  518. static void
  519. dumpBytes (unsigned short len, char *data)
  520. {
  521. unsigned short i;
  522. Debug ("%d: ", len);
  523. for (i = 0; i < len; i++)
  524. Debug ("%02x ", data[i] & 0377);
  525. Debug ("\n");
  526. }
  527. static void
  528. dumpAuth (Xauth *auth)
  529. {
  530. Debug ("family: %d\n", auth->family);
  531. Debug ("addr: ");
  532. dumpBytes (auth->address_length, auth->address);
  533. Debug ("number: ");
  534. dumpBytes (auth->number_length, auth->number);
  535. Debug ("name: ");
  536. dumpBytes (auth->name_length, auth->name);
  537. Debug ("data: ");
  538. dumpBytes (auth->data_length, auth->data);
  539. }
  540. struct addrList {
  541. unsigned short family;
  542. unsigned short address_length;
  543. char *address;
  544. unsigned short number_length;
  545. char *number;
  546. unsigned short name_length;
  547. char *name;
  548. struct addrList *next;
  549. };
  550. static struct addrList *addrs;
  551. static void
  552. initAddrs (void)
  553. {
  554. addrs = 0;
  555. }
  556. static void
  557. doneAddrs (void)
  558. {
  559. struct addrList *a, *n;
  560. for (a = addrs; a; a = n) {
  561. n = a->next;
  562. if (a->address)
  563. free (a->address);
  564. if (a->number)
  565. free (a->number);
  566. free ((char *) a);
  567. }
  568. }
  569. static int checkEntry (Xauth *auth);
  570. static void
  571. saveEntry (Xauth *auth)
  572. {
  573. struct addrList *new;
  574. new = (struct addrList *) malloc (sizeof (struct addrList));
  575. if (!new) {
  576. LogOutOfMem (ReadCatalog(
  577. MC_LOG_SET,MC_LOG_SAVE_ADDR,MC_DEF_LOG_SAVE_ADDR));
  578. return;
  579. }
  580. if ((new->address_length = auth->address_length) > 0) {
  581. new->address = malloc (auth->address_length);
  582. if (!new->address) {
  583. LogOutOfMem (ReadCatalog(
  584. MC_LOG_SET,MC_LOG_SAVE_ADDR,MC_DEF_LOG_SAVE_ADDR));
  585. free ((char *) new);
  586. return;
  587. }
  588. memmove( new->address, auth->address, (int) auth->address_length);
  589. } else
  590. new->address = 0;
  591. if ((new->number_length = auth->number_length) > 0) {
  592. new->number = malloc (auth->number_length);
  593. if (!new->number) {
  594. LogOutOfMem (ReadCatalog(
  595. MC_LOG_SET,MC_LOG_SAVE_ADDR,MC_DEF_LOG_SAVE_ADDR));
  596. free (new->address);
  597. free ((char *) new);
  598. return;
  599. }
  600. memmove( new->number, auth->number, (int) auth->number_length);
  601. } else
  602. new->number = 0;
  603. if ((new->name_length = auth->name_length) > 0) {
  604. new->name = malloc (auth->name_length);
  605. if (!new->name) {
  606. LogOutOfMem (ReadCatalog(
  607. MC_LOG_SET,MC_LOG_SAVE_ADDR,MC_DEF_LOG_SAVE_ADDR));
  608. free (new->number);
  609. free (new->address);
  610. free ((char *) new);
  611. return;
  612. }
  613. memmove( new->name, auth->name, (int) auth->name_length);
  614. } else
  615. new->name = 0;
  616. new->family = auth->family;
  617. new->next = addrs;
  618. addrs = new;
  619. }
  620. static int
  621. checkEntry (Xauth *auth)
  622. {
  623. struct addrList *a;
  624. for (a = addrs; a; a = a->next) {
  625. if (a->family == auth->family &&
  626. a->address_length == auth->address_length &&
  627. binaryEqual (a->address, auth->address, auth->address_length) &&
  628. a->number_length == auth->number_length &&
  629. binaryEqual (a->number, auth->number, auth->number_length) &&
  630. a->name_length == auth->name_length &&
  631. binaryEqual (a->name, auth->name, auth->name_length))
  632. {
  633. return 1;
  634. }
  635. }
  636. return 0;
  637. }
  638. static int doWrite;
  639. static
  640. writeAuth (FILE *file, Xauth *auth)
  641. {
  642. if (debugLevel >= 15) { /* normally too verbose */
  643. Debug ("writeAuth: doWrite = %d\n", doWrite);
  644. dumpAuth (auth); /* does Debug only */
  645. }
  646. if (doWrite) {
  647. if (!XauWriteAuth (file, auth) || fflush (file) == EOF) {
  648. LogError(
  649. ReadCatalog(MC_LOG_SET,MC_LOG_SRV_WRT,MC_DEF_LOG_SRV_WRT),
  650. file);
  651. return 0;
  652. }
  653. else
  654. {
  655. return 1;
  656. }
  657. }
  658. return 1;
  659. }
  660. static void
  661. writeAddr (int family, int addr_length, char *addr, FILE *file, Xauth *auth)
  662. {
  663. auth->family = (unsigned short) family;
  664. auth->address_length = addr_length;
  665. auth->address = addr;
  666. Debug ("writeAddr: writing and saving an entry\n");
  667. writeAuth (file, auth);
  668. saveEntry (auth);
  669. }
  670. static void
  671. DefineLocal (FILE *file, Xauth *auth)
  672. {
  673. char displayname[100];
  674. /* stolen from xinit.c */
  675. /* Make sure this produces the same string as _XGetHostname in lib/X/XlibInt.c.
  676. * Otherwise, Xau will not be able to find your cookies in the Xauthority file.
  677. *
  678. * Note: POSIX says that the ``nodename'' member of utsname does _not_ have
  679. * to have sufficient information for interfacing to the network,
  680. * and so, you may be better off using gethostname (if it exists).
  681. */
  682. #ifdef NEED_UTSNAME
  683. /* hpux:
  684. * Why not use gethostname()? Well, at least on my system, I've had to
  685. * make an ugly kernel patch to get a name longer than 8 characters, and
  686. * uname() lets me access to the whole string (it smashes release, you
  687. * see), whereas gethostname() kindly truncates it for me.
  688. */
  689. {
  690. struct utsname name;
  691. uname(&name);
  692. strcpy(displayname, name.nodename);
  693. }
  694. writeAddr (FamilyLocal, strlen (displayname), displayname, file, auth);
  695. #endif
  696. #if (!defined(NEED_UTSNAME) || defined (hpux))
  697. /* AIXV3:
  698. * In AIXV3, _POSIX_SOURCE is defined, but uname gives only first
  699. * field of hostname. Thus, we use gethostname instead.
  700. */
  701. /*
  702. * For HP-UX, HP's Xlib expects a fully-qualified domain name, which
  703. * is achieved by using gethostname(). For compatability, we must
  704. * also still create the entry using uname() above.
  705. */
  706. gethostname(displayname, sizeof(displayname));
  707. writeAddr (FamilyLocal, strlen (displayname), displayname, file, auth);
  708. #endif
  709. }
  710. #ifdef WINTCP /* NCR with Wollongong TCP */
  711. #include <sys/un.h>
  712. #include <stropts.h>
  713. #include <tiuser.h>
  714. #include <sys/stream.h>
  715. #include <net/if.h>
  716. #include <netinet/ip.h>
  717. #include <netinet/ip_var.h>
  718. #include <netinet/in.h>
  719. #include <netinet/in_var.h>
  720. static void
  721. DefineSelf (int fd, FILE *file, Xauth *auth)
  722. {
  723. /*
  724. * The Wolongong drivers used by NCR SVR4/MP-RAS don't understand the
  725. * socket IO calls that most other drivers seem to like. Because of
  726. * this, this routine must be special cased for NCR. Eventually,
  727. * this will be cleared up.
  728. */
  729. struct ipb ifnet;
  730. struct in_ifaddr ifaddr;
  731. struct strioctl str;
  732. unsigned char *addr;
  733. int family, len, ipfd;
  734. if ((ipfd = open ("/dev/ip", O_RDWR, 0 )) < 0)
  735. LogError ((unsigned char *)"Getting interface configuration");
  736. /* Indicate that we want to start at the begining */
  737. ifnet.ib_next = (struct ipb *) 1;
  738. while (ifnet.ib_next)
  739. {
  740. str.ic_cmd = IPIOC_GETIPB;
  741. str.ic_timout = 0;
  742. str.ic_len = sizeof (struct ipb);
  743. str.ic_dp = (char *) &ifnet;
  744. if (ioctl (ipfd, (int) I_STR, (char *) &str) < 0)
  745. {
  746. close (ipfd);
  747. LogError ((unsigned char *) "Getting interface configuration");
  748. }
  749. ifaddr.ia_next = (struct in_ifaddr *) ifnet.if_addrlist;
  750. str.ic_cmd = IPIOC_GETINADDR;
  751. str.ic_timout = 0;
  752. str.ic_len = sizeof (struct in_ifaddr);
  753. str.ic_dp = (char *) &ifaddr;
  754. if (ioctl (ipfd, (int) I_STR, (char *) &str) < 0)
  755. {
  756. close (ipfd);
  757. LogError ((unsigned char *) "Getting interface configuration");
  758. }
  759. /*
  760. * Ignore the 127.0.0.1 entry.
  761. */
  762. if (IA_SIN(&ifaddr)->sin_addr.s_addr == htonl(0x7f000001) )
  763. continue;
  764. writeAddr (FamilyInternet, 4, (char *)&(IA_SIN(&ifaddr)->sin_addr), file, auth);
  765. }
  766. close(ipfd);
  767. }
  768. #else /* WINTCP */
  769. #ifdef SIOCGIFCONF
  770. /* think of something... */
  771. #define DECnetInstalled True
  772. /* Define this host for access control. Find all the hosts the OS knows about
  773. * for this fd and add them to the selfhosts list.
  774. */
  775. static void
  776. DefineSelf (int fd, FILE *file, Xauth *auth)
  777. {
  778. char buf[2048];
  779. struct ifconf ifc;
  780. int n;
  781. int len;
  782. char *addr;
  783. int family;
  784. struct ifreq *ifr;
  785. ifc.ifc_len = sizeof (buf);
  786. ifc.ifc_buf = buf;
  787. if (ioctl (fd, SIOCGIFCONF, (char *) &ifc) < 0)
  788. LogError ((unsigned char *)"Trouble getting network interface configuration");
  789. for (ifr = ifc.ifc_req
  790. #if defined(BSD44SOCKETS) || defined(CSRG_BASED)
  791. ; (char *)ifr < ifc.ifc_buf + ifc.ifc_len;
  792. ifr = (struct ifreq *)((char *)ifr + sizeof (struct ifreq) +
  793. (ifr->ifr_addr.sa_len > sizeof (ifr->ifr_addr) ?
  794. ifr->ifr_addr.sa_len - sizeof (ifr->ifr_addr) : 0))
  795. #else
  796. , n = ifc.ifc_len / sizeof (struct ifreq); --n >= 0; ifr++
  797. #endif
  798. )
  799. {
  800. #ifdef DNETCONN
  801. /*
  802. * this is ugly but SIOCGIFCONF returns decnet addresses in
  803. * a different form from other decnet calls
  804. */
  805. if (ifr->ifr_addr.sa_family == AF_DECnet) {
  806. len = sizeof (struct dn_naddr);
  807. addr = (char *)ifr->ifr_addr.sa_data;
  808. family = FamilyDECnet;
  809. } else
  810. #endif
  811. {
  812. if (ConvertAddr ((XdmcpNetaddr) &ifr->ifr_addr, &len, &addr) < 0)
  813. continue;
  814. if (len == 0)
  815. {
  816. Debug ("Skipping zero length address\n");
  817. continue;
  818. }
  819. /*
  820. * don't write out 'localhost' entries, as
  821. * they may conflict with other local entries.
  822. * DefineLocal will always be called to add
  823. * the local entry anyway, so this one can
  824. * be tossed.
  825. */
  826. if (len == 4 &&
  827. addr[0] == 127 && addr[1] == 0 &&
  828. addr[2] == 0 && addr[3] == 1)
  829. {
  830. Debug ("Skipping localhost address\n");
  831. continue;
  832. }
  833. family = FamilyInternet;
  834. }
  835. Debug ("DefineSelf: write network address, length %d\n", len);
  836. writeAddr (family, len, addr, file, auth);
  837. }
  838. }
  839. #else /* SIOCGIFCONF */
  840. /* Define this host for access control. Find all the hosts the OS knows about
  841. * for this fd and add them to the selfhosts list.
  842. */
  843. static void
  844. DefineSelf (int fd, int file, int auth)
  845. {
  846. int n;
  847. int len;
  848. caddr_t addr;
  849. int family;
  850. struct utsname name;
  851. struct hostent *hp;
  852. union {
  853. struct sockaddr sa;
  854. struct sockaddr_in in;
  855. } saddr;
  856. struct sockaddr_in *inetaddr;
  857. /* hpux:
  858. * Why not use gethostname()? Well, at least on my system, I've had to
  859. * make an ugly kernel patch to get a name longer than 8 characters, and
  860. * uname() lets me access to the whole string (it smashes release, you
  861. * see), whereas gethostname() kindly truncates it for me.
  862. */
  863. uname(&name);
  864. hp = gethostbyname (name.nodename);
  865. if (hp != NULL) {
  866. saddr.sa.sa_family = hp->h_addrtype;
  867. inetaddr = (struct sockaddr_in *) (&(saddr.sa));
  868. memmove( (char *) &(inetaddr->sin_addr), (char *) hp->h_addr, (int) hp->h_length);
  869. family = ConvertAddr ( &(saddr.sa), &len, &addr);
  870. if ( family >= 0) {
  871. writeAddr (FamilyInternet, sizeof (inetaddr->sin_addr),
  872. (char *) (&inetaddr->sin_addr), file, auth);
  873. }
  874. }
  875. }
  876. #endif /* SIOCGIFCONF else */
  877. #endif /* WINTCP */
  878. static void
  879. setAuthNumber (Xauth *auth, char *name)
  880. {
  881. char *colon;
  882. char *dot, *number;
  883. Debug ("setAuthNumber %s\n", name);
  884. colon = strrchr(name, ':');
  885. if (colon) {
  886. ++colon;
  887. dot = strchr(colon, '.');
  888. if (dot)
  889. auth->number_length = dot - colon;
  890. else
  891. auth->number_length = strlen (colon);
  892. number = malloc (auth->number_length + 1);
  893. if (number) {
  894. strncpy (number, colon, auth->number_length);
  895. number[auth->number_length] = '\0';
  896. } else {
  897. LogOutOfMem (ReadCatalog(
  898. MC_LOG_SET,MC_LOG_NET_CFG,MC_DEF_LOG_NET_CFG));
  899. auth->number_length = 0;
  900. }
  901. auth->number = number;
  902. Debug ("setAuthNumber: %s\n", number);
  903. }
  904. }
  905. static void
  906. writeLocalAuth (FILE *file, Xauth *auth, char *name)
  907. {
  908. int fd;
  909. Debug ("writeLocalAuth: %s %.*s\n", name, auth->name_length, auth->name);
  910. setAuthNumber (auth, name);
  911. #ifdef STREAMSCONN
  912. fd = t_open ("/dev/tcp", O_RDWR, 0);
  913. t_bind(fd, NULL, NULL);
  914. DefineSelf (fd, file, auth);
  915. t_unbind (fd);
  916. t_close (fd);
  917. #endif
  918. #ifdef TCPCONN
  919. fd = socket (AF_INET, SOCK_STREAM, 0);
  920. if(fd != -1) {
  921. DefineSelf (fd, file, auth);
  922. close (fd);
  923. }
  924. #endif
  925. #ifdef DNETCONN
  926. fd = socket (AF_DECnet, SOCK_STREAM, 0);
  927. DefineSelf (fd, file, auth);
  928. close (fd);
  929. #endif
  930. DefineLocal (file, auth);
  931. }
  932. #ifdef XDMCP
  933. static void
  934. writeRemoteAuth (FILE *file, Xauth *auth, XdmcpNetaddr peer, int peerlen, char *name)
  935. {
  936. int family = FamilyLocal;
  937. char *addr;
  938. Debug ("writeRemoteAuth: %s %.*s\n", name, auth->name_length, auth->name);
  939. if (!peer || peerlen < 2)
  940. return;
  941. setAuthNumber (auth, name);
  942. family = ConvertAddr (peer, &peerlen, &addr);
  943. Debug ("writeRemoteAuth: family %d\n", family);
  944. if (family != FamilyLocal)
  945. {
  946. Debug ("writeRemoteAuth: %d, %d, %x\n",
  947. family, peerlen, *(int *)addr);
  948. writeAddr (family, peerlen, addr, file, auth);
  949. }
  950. else
  951. {
  952. writeLocalAuth (file, auth, name);
  953. }
  954. }
  955. #endif /* XDMCP */
  956. void
  957. SetUserAuthorization (struct display *d, struct verify_info *verify)
  958. {
  959. FILE *old, *new;
  960. char home_name[1024], backup_name[1024], new_name[1024];
  961. char home_name_temp[sizeof(home_name)];
  962. char *name;
  963. char *home;
  964. char *envname = 0;
  965. int lockStatus;
  966. Xauth *entry, **auths;
  967. int setenv;
  968. char **setEnv (), *getEnv ();
  969. struct stat statb;
  970. int i;
  971. int magicCookie;
  972. int data_len;
  973. Debug ("SetUserAuthorization\n");
  974. auths = d->authorizations;
  975. if (auths) {
  976. home = getEnv (verify->userEnviron, "HOME");
  977. lockStatus = LOCK_ERROR;
  978. if (home) {
  979. snprintf(home_name, sizeof(home_name), "%s", home);
  980. if (home[strlen(home) - 1] != '/') {
  981. snprintf(home_name_temp, sizeof(home_name_temp), "%s/", home_name);
  982. strcpy(home_name, home_name_temp);
  983. }
  984. snprintf(home_name_temp, sizeof(home_name_temp), "%s.Xauthority", home_name);
  985. strcpy(home_name, home_name_temp);
  986. Debug ("XauLockAuth %s\n", home_name);
  987. lockStatus = XauLockAuth (home_name, 1, 2, 10);
  988. Debug ("Lock is %d\n", lockStatus);
  989. if (lockStatus == LOCK_SUCCESS) {
  990. if (openFiles (home_name, new_name, &old, &new)) {
  991. name = home_name;
  992. setenv = 0;
  993. } else {
  994. Debug ("openFiles failed\n");
  995. XauUnlockAuth (home_name);
  996. lockStatus = LOCK_ERROR;
  997. }
  998. }
  999. }
  1000. if (lockStatus != LOCK_SUCCESS) {
  1001. sprintf (backup_name, "%s/.XauthXXXXXX", d->userAuthDir);
  1002. (void) mktemp (backup_name);
  1003. Debug ("XauLockAuth %s\n", backup_name);
  1004. lockStatus = XauLockAuth (backup_name, 1, 2, 10);
  1005. Debug ("backup lock is %d\n", lockStatus);
  1006. if (lockStatus == LOCK_SUCCESS) {
  1007. if (openFiles (backup_name, new_name, &old, &new)) {
  1008. name = backup_name;
  1009. setenv = 1;
  1010. } else {
  1011. XauUnlockAuth (backup_name);
  1012. lockStatus = LOCK_ERROR;
  1013. }
  1014. }
  1015. /*
  1016. * Won't be using this file so unlock it.
  1017. */
  1018. XauUnlockAuth (home_name);
  1019. }
  1020. if (lockStatus != LOCK_SUCCESS) {
  1021. Debug ("can't lock auth file %s or backup %s\n",
  1022. home_name, backup_name);
  1023. LogError (ReadCatalog
  1024. (MC_LOG_SET,MC_LOG_LCK_AUTH,MC_DEF_LOG_LCK_AUTH),
  1025. home_name, backup_name);
  1026. return;
  1027. }
  1028. initAddrs ();
  1029. doWrite = 1;
  1030. Debug ("%d authorization protocols for %s\n", d->authNum, d->name);
  1031. /*
  1032. * Write MIT-MAGIC-COOKIE-1 authorization first, so that
  1033. * R4 clients which only knew that, and used the first
  1034. * matching entry will continue to function
  1035. */
  1036. magicCookie = -1;
  1037. for (i = 0; i < d->authNum; i++)
  1038. {
  1039. if (auths[i]->name_length == 18 &&
  1040. !strncmp (auths[i]->name, "MIT-MAGIC-COOKIE-1", 18))
  1041. {
  1042. magicCookie = i;
  1043. if (d->displayType.location == Local)
  1044. writeLocalAuth (new, auths[i], d->name);
  1045. #ifdef XDMCP
  1046. else
  1047. writeRemoteAuth (new, auths[i], d->peer, d->peerlen, d->name);
  1048. #endif
  1049. break;
  1050. }
  1051. }
  1052. /* now write other authorizations */
  1053. for (i = 0; i < d->authNum; i++)
  1054. {
  1055. Debug("SetUserAuthorization: checking authorization # %d\n", i+1);
  1056. if (i != magicCookie)
  1057. {
  1058. data_len = auths[i]->data_length;
  1059. /* client will just use default Kerberos cache, so don't
  1060. * even write cache info into the authority file.
  1061. */
  1062. if (auths[i]->name_length == 14 &&
  1063. !strncmp (auths[i]->name, "MIT-KERBEROS-5", 14))
  1064. auths[i]->data_length = 0;
  1065. if (d->displayType.location == Local)
  1066. writeLocalAuth (new, auths[i], d->name);
  1067. #ifdef XDMCP
  1068. else
  1069. writeRemoteAuth (new, auths[i], d->peer, d->peerlen, d->name);
  1070. #endif
  1071. auths[i]->data_length = data_len;
  1072. }
  1073. }
  1074. Debug ("SetUserAuthorization: old = %x\n", old);
  1075. if (old) {
  1076. if (fstat (fileno (old), &statb) != -1)
  1077. chmod (new_name, (int) (statb.st_mode & 0777));
  1078. /*SUPPRESS 560*/
  1079. while (entry = XauReadAuth (old)) {
  1080. if (!checkEntry (entry))
  1081. {
  1082. Debug ("Writing an entry\n");
  1083. writeAuth (new, entry);
  1084. }
  1085. XauDisposeAuth (entry);
  1086. }
  1087. fclose (old);
  1088. }
  1089. doneAddrs ();
  1090. fclose (new);
  1091. Debug ("SetUserAuthorization: name = %s\n", name);
  1092. Debug ("SetUserAuthorization: new_name = %s\n", new_name);
  1093. Debug ("SetUserAuthorization: unlink(%s)\n", name);
  1094. if (unlink (name) == -1)
  1095. Debug ("SetUserAuthorization: unlink(%s) failed!\n", name);
  1096. envname = name;
  1097. if (link (new_name, name) == -1) {
  1098. Debug ("link failed %s %s\n", new_name, name);
  1099. LogError (
  1100. ReadCatalog(MC_LOG_SET,MC_LOG_NOT_AUTH,MC_DEF_LOG_NOT_AUTH));
  1101. setenv = 1;
  1102. envname = new_name;
  1103. } else {
  1104. Debug ("SetUserAuthorization: link(%s,%s) OK\n", new_name, name);
  1105. Debug ("SetUserAuthorization: unlink(%s)\n", new_name);
  1106. unlink (new_name);
  1107. }
  1108. if (setenv) {
  1109. Debug ("SetUserAuthorization: setenv(XAUTHORITY=%s)\n", envname);
  1110. verify->userEnviron = setEnv (verify->userEnviron,
  1111. "XAUTHORITY", envname);
  1112. verify->systemEnviron = setEnv (verify->systemEnviron,
  1113. "XAUTHORITY", envname);
  1114. }
  1115. Debug ("SetUserAuthorization: XauUnLockAuth(%s)\n", name);
  1116. XauUnlockAuth (name);
  1117. Debug ("SetUserAuthorization: envname = %s\n", envname);
  1118. if (envname) {
  1119. #ifdef NGROUPS
  1120. Debug ("SetUserAuthorization: chown(%s,%d,%d)\n",
  1121. envname, verify->uid, verify->groups[0]);
  1122. if(-1 == chown (envname, verify->uid, verify->groups[0])) {
  1123. perror(strerror(errno));
  1124. }
  1125. #else
  1126. Debug ("SetUserAuthorization: chown(%s,%d,%d)\n",
  1127. envname, verify->uid, verify->gid);
  1128. if(-1 == chown (envname, verify->uid, verify->gid)) {
  1129. perror(strerror(errno));
  1130. }
  1131. #endif /* NGROUPS */
  1132. }
  1133. }
  1134. Debug ("done SetUserAuthorization\n");
  1135. }
  1136. void
  1137. RemoveUserAuthorization (struct display *d, struct verify_info *verify)
  1138. {
  1139. char *home;
  1140. Xauth **auths, *entry;
  1141. char name[1024], new_name[1024];
  1142. char name_temp[sizeof(name)];
  1143. int lockStatus;
  1144. FILE *old, *new;
  1145. struct stat statb;
  1146. int i;
  1147. char *getEnv ();
  1148. if (!(auths = d->authorizations))
  1149. return;
  1150. home = getEnv (verify->userEnviron, "HOME");
  1151. if (!home)
  1152. return;
  1153. Debug ("RemoveUserAuthorization\n");
  1154. snprintf(name, sizeof(name), "%s", home);
  1155. if (home[strlen(home) - 1] != '/') {
  1156. snprintf(name_temp, sizeof(name_temp), "%s/", name);
  1157. strcpy(name, name_temp);
  1158. }
  1159. snprintf(name_temp, sizeof(name_temp), "%s.Xauthority", name);
  1160. strcpy(name, name_temp);
  1161. Debug ("XauLockAuth %s\n", name);
  1162. lockStatus = XauLockAuth (name, 1, 2, 10);
  1163. Debug ("Lock is %d\n", lockStatus);
  1164. if (lockStatus != LOCK_SUCCESS)
  1165. return;
  1166. if (openFiles (name, new_name, &old, &new))
  1167. {
  1168. initAddrs ();
  1169. doWrite = 0;
  1170. for (i = 0; i < d->authNum; i++)
  1171. {
  1172. if (d->displayType.location == Local)
  1173. writeLocalAuth (new, auths[i], d->name);
  1174. #ifdef XDMCP
  1175. else
  1176. writeRemoteAuth (new, auths[i], d->peer, d->peerlen, d->name);
  1177. #endif
  1178. }
  1179. doWrite = 1;
  1180. if (old) {
  1181. if (fstat (fileno (old), &statb) != -1)
  1182. chmod (new_name, (int) (statb.st_mode & 0777));
  1183. /*SUPPRESS 560*/
  1184. while (entry = XauReadAuth (old)) {
  1185. if (!checkEntry (entry))
  1186. {
  1187. Debug ("Writing an entry\n");
  1188. writeAuth (new, entry);
  1189. }
  1190. XauDisposeAuth (entry);
  1191. }
  1192. fclose (old);
  1193. }
  1194. doneAddrs ();
  1195. fclose (new);
  1196. if (unlink (name) == -1)
  1197. Debug ("unlink %s failed\n", name);
  1198. if (link (new_name, name) == -1) {
  1199. Debug ("link failed %s %s\n", new_name, name);
  1200. LogError (
  1201. ReadCatalog(MC_LOG_SET,MC_LOG_NOT_AUTH,MC_DEF_LOG_NOT_AUTH));
  1202. } else {
  1203. Debug ("new is in place, go for it!\n");
  1204. unlink (new_name);
  1205. }
  1206. }
  1207. XauUnlockAuth (name);
  1208. }