Hi Matthieu, Here are some miscellaenous fixes to xdm that Debian's been using for a while, but have been needing to submit upstream. None of them are Debian-specific; I keep those in a separate patch file.
The patch is MIME-attached and has comprehensive descriptions of everything it changes. These are against xf-4_3-branch. -- G. Branden Robinson | There is no housing shortage in Debian GNU/Linux | Lincoln today -- just a rumor that [EMAIL PROTECTED] | is put about by people who have http://people.debian.org/~branden/ | nowhere to live. -- G. L. Murfin
$Id: 002_xdm_fixes.diff 564 2003-09-21 22:15:53Z branden $ This patch by Branden Robinson, Matthieu Herrb, and Richard Braakman. These patches do a number of things: Not submitted upstream yet. * xc/config/cf/gnu.cf: The Hurd has a pollable /dev/random device. * xc/config/cf/linux.cf: Linux 2.0 and later has a pollable /dev/random device. * xc/programs/xdm/auth.c: - Add a couple of comments to assuage some of the fears of security auditors, and people who follow up on the GNU linker's ritual complaints about mktemp(). - Protect against race-based symlink attacks in SaveServerAuthorizations(). - Change openFiles() to avoid race-based symlink attacks. - Change openFiles() to accept NULL for its third argument, and check for a NULL value before fopen()ing the first argument. - In SetUserAuthorization(), when falling back to /tmp for creation of the authorization file, pass openFiles() NULL as arg 3, and set "old" to NULL, since the we know the temp file just created to contain auth credentials will be empty and have no authorization records in it. - Richard Braakman observes the following about the above changes: "I can think of only one case where the new behaviour could be a problem: if a user already has a file ".Xauthority-n" in $HOME and the user's home directory is not writable for self (so the unlink fails) and the .Xauthority-n file _is_ writable then the old fopen would have succeeded (and truncated the file), while the new code would fail. Well, tough titties." Since "-n" files are cleaned shortly after they are created, the existence of any such file would be an anomaly (the result of an xdm or xinit process getting killed at an inopportune moment). This doesn't seem like an important concession. - Also note that xdm is only susceptible to the aforementioned race-condition-based symlink attacks if: 1) the administrator configures the authDir or authFile resources to be in publicly-writable directories; or 2) the user's home directory is unwritable (NFS failure, over quota, etc.) - Make several LogError() and Debug() messages more informative. - Fix typo in debug message. * xc/programs/xdm/choose.c: Use xdm's _SysErrorMsg() function instead of strerror(). * xc/programs/xdm/config/Imakefile: - Handle GNUMachArchitecture the same as LinuxArchitecture. * xc/programs/xdm/config/Xres.cpp: - Use fonts for the greeter that look good (or, at least, less horrible). I experimented with this quite a bit to get something that looks good when the ordinary bitmap fonts aren't scaled. - Move some XPM-extension stuff inside the XPM #ifdef. - Don't use a bitmap in the greeter if the root window is small. * xc/programs/xdm/daemon.c: - Stop manipulating the standard file descriptiors, since this can interfere with logging. - Log error if daemon() call fails. * xc/programs/xdm/dm.c: - Matthieu Herrb rewrote the StorePid() function based on my changes; he made it more careful with the size of Pid_t, and treats an existing pid file as a failure. I then made some more changes: use _SysErrorMsg() instead of strerror(), catch errors from the daemon() function, do not close standard file descriptiors on daemonization, add a comment explaining why, and don't assume that the process id we write to the pidFile is 5 digits. - Miscellaenous fixes: Add indentation to (heavily-used) preprocessor statements. Initialize the log file sooner. Update log messages to indicate when an immediate exit is taking place. Add log messages for xdm startup, shutdown, and normal exit. Add a debugging message when xdm enters its main loop. Fix a typo in a log message. Move a "default" case in a switch() to be the final case evaluated, as is customary in C code. Made brace usage a little more internally consistent. Change a LogError() to a LogInfo() when we expect a child X server process to become a zombie. Use the PID file as most other Unix daemons do. Use _SysErrorMsg() instead of strerror(). Wrap some code at 80 columns. * xc/programs/xdm/dm_auth.h: - Add function prototypes for exposed interfaces in xdmauth.c. - Copy declarations from Xdmcp library's Wrap.h header. * xc/programs/xdm/dm_error.h: Remove protoype for unused Panic() function. * xc/programs/xdm/error.c: - Add timestamping to logging functions, except for LogOutOfMem(). - Remove unused Panic() function. - Append to the log file if it already exists. - Style fix: put function names flush left when they're being defined. * xc/programs/xdm/genauth.c: - Include <fcntl.h> for definitions of O_ flags to open(). - Remove partial set of delcarations from Xdmcp library's Wrap.h header; now in dm_auth.h instead. * xc/programs/xdm/greeter/verify.c: Use _SysErrorMsg() instead of strerror(). * xc/programs/xdm/session.c: Indent pre-processor statements. Use _SysErrorMsg() instead of strerror(). Recognize that GNU LibC-based systems as well as Linux systems in general have the endpwent() function. Recognize that GNU LibC-based systems as well as CSRG_BASED ones have the getpwnam() and crypt() functions. Style fix: put function names flush left when they're being defined. * xc/programs/xdm/util.c: The setpgrp define wouldn't be necessary if GlibC's setpgrp was equivalent to setpgid as described in the GlibC (info, of course) documentation. -- Robert Millan <[EMAIL PROTECTED]> * xc/programs/xdm/xdm.man: - Use dot macros instead of backslash roff sequences to mark up literals that use __projectroot__ or DEV_RANDOM, because cpp won't recognize them otherwise, and telling roff to underline leading spaces is ugly. * xc/programs/xdm/xdmauth.c: - Declare functions used only internally as static. - Delcare function prototypes for internal functions. - Move from K&R to ANSI style function headers. * xc/programs/xdm/xdmcp.c: When terminating an active session, report this fact with LogInfo() rather than Debug(). * xc/programs/xdm/xdmshell.c: #include <string.h> for strerror() prototype. (xdmshell can't use _SysErrorMsg because it is a standalone program that doesn't include server.c.) (access.c,auth.c,choose.c,daemon.c,dm.c,file.c,genauth.c,greeter/Login.c, greeter/greet.c,greeter/verify.c,resource.c,rpcauth.c,server.c,session.c, socket.c,streams.c,xdmauth.c): - Change LogError() invocations to use _SysErrorMsg() where errno might be set (and not clobbered by intermediate calls). Also make LogError() the first thing we do after an error condition in those cases. - Use xdm's _SysErrorMsg() function instead of strerror or merely printing the raw error number. - (cosmetic) Don't capitalize or put periods at the ends of log messages, since they aren't sentences. --- xc/config/cf/gnu.cf~ 2003-09-21 15:53:53.000000000 -0500 +++ xc/config/cf/gnu.cf 2003-09-21 15:53:35.000000000 -0500 @@ -33,6 +33,9 @@ XCOMM #define ThreadsLibraries -lpthread XCOMM #define SystemMTDefines -D_REENTRANT +#define HasDevRandom YES +#define PollDevRandom YES + #ifndef HasLibCrypt #define HasLibCrypt YES #endif --- xc/config/cf/linux.cf~ 2003-09-21 15:40:11.000000000 -0500 +++ xc/config/cf/linux.cf 2003-09-21 15:41:15.000000000 -0500 @@ -86,6 +86,12 @@ XCOMM libc: (LinuxCLibMajorVersion./**/LinuxCLibMinorVersion./**/LinuxCLibTeenyVersion) XCOMM binutils: (LinuxBinUtilsMajorVersion) +/* Linux >= 2.0 supports /dev/random, which is poll()able */ +#if OSMajorVersion >= 2 +# define HasDevRandom YES +# define PollDevRandom YES +#endif + #if LinuxDistribution == LinuxDebian # define SystemManDirectory /usr/share/man # define HasPam YES diff -urN xc/programs/xdm~/access.c xc/programs/xdm/access.c --- xc/programs/xdm~/access.c 2003-09-21 15:39:22.000000000 -0500 +++ xc/programs/xdm/access.c 2003-09-21 15:40:41.000000000 -0500 @@ -297,8 +297,8 @@ if (!addr) { - Debug ("No such host %s\n", hostOrAlias); - LogError ("Access file \"%s\", host \"%s\" not found\n", accessFile, hostOrAlias); + Debug ("no such host %s\n", hostOrAlias); + LogError ("access file \"%s\", host \"%s\" not found\n", accessFile, hostOrAlias); free ((char *) h); goto tryagain; } @@ -390,7 +390,7 @@ } if (addr == NULL) { - LogError ("Access file %s, display %s unknown\n", accessFile, displayOrAlias); + LogError ("access file %s, display %s unknown\n", accessFile, displayOrAlias); free ((char *) d); return NULL; } @@ -440,7 +440,7 @@ *prev = h; prev = &h->next; } else { - Debug("Wildcard host specified in Xaccess for type other than LISTEN -- ignoring\n"); + Debug("wildcard host specified in Xaccess for type other than LISTEN -- ignoring\n"); FreeHostEntry (h); } } else { @@ -477,7 +477,7 @@ datafile = fopen (accessFile, "r"); if (!datafile) { - LogError ("Cannot open access control file %s, no XDMCP reqeusts will be granted\n", accessFile); + LogError ("cannot open access control file %s, no XDMCP reqeusts will be granted\n", accessFile); return 0; } ReadAccessDatabase (datafile); diff -urN xc/programs/xdm~/auth.c xc/programs/xdm/auth.c --- xc/programs/xdm~/auth.c 2003-09-21 15:39:22.000000000 -0500 +++ xc/programs/xdm/auth.c 2003-09-21 15:40:41.000000000 -0500 @@ -46,6 +46,7 @@ #include "dm_error.h" #include <errno.h> +#include <fcntl.h> #include <sys/ioctl.h> @@ -196,7 +197,7 @@ auth = (*a->GetAuth) (name_length, name); if (auth) { - Debug ("Got %p (%d %*.*s) ", auth, + Debug ("got %p (%d %*.*s) ", auth, auth->name_length, auth->name_length, auth->name_length, auth->name); for (i = 0; i < (int)auth->data_length; i++) @@ -204,11 +205,11 @@ Debug ("\n"); } else - Debug ("Got (null)\n"); + Debug ("got (null)\n"); } else { - Debug ("Unknown authorization %*.*s\n", name_length, name_length, name); + Debug ("unknown authorization %*.*s\n", name_length, name_length, name); } return auth; } @@ -245,11 +246,11 @@ pdpy->xdmcpAuthorization = 0; } if (auth) - Debug ("Got %p (%d %*.*s)\n", auth, + Debug ("got %p (%d %*.*s)\n", auth, auth->name_length, auth->name_length, auth->name_length, auth->name); else - Debug ("Got (null)\n"); + Debug ("got (null)\n"); } } @@ -333,8 +334,16 @@ d->authFile = NULL; return FALSE; } - sprintf (d->authFile, "%s/%s/%s/A%s-XXXXXX", + sprintf (d->authFile, "%s/%s/%s/A%s-XXXXXX", authDir, authdir1, authdir2, cleanname); + /* + * Security auditors should note that mktemp() is not used unsafely + * here. The authFile is created in authDir, which defaults to + * a non-user-writeable location (see xdm.man). Only root, the + * owner of xdm's configuration files, or someone with permission + * to execute xdm (which is not installed setuid or setgid by + * default) can change the authDir or authFile resources. + */ (void) mktemp (d->authFile); } return TRUE; @@ -350,42 +359,50 @@ int mask; int ret; int i; + int fd; mask = umask (0077); if (!d->authFile && !MakeServerAuthFile (d)) return FALSE; (void) unlink (d->authFile); - auth_file = fopen (d->authFile, "w"); - umask (mask); - if (!auth_file) { - Debug ("Can't creat auth file %s\n", d->authFile); - LogError ("Cannot open server authorization file %s\n", d->authFile); + fd = open (d->authFile, O_WRONLY | O_CREAT | O_EXCL, 0600); + if (fd >= 0) + auth_file = fdopen (fd, "w"); + else + { + LogError ("cannot create server authorization file %s: %s\n", + d->authFile, _SysErrorMsg (errno)); + Debug ("can't create auth file %s\n", d->authFile); + } + (void) umask (mask); + if (!auth_file) + { free (d->authFile); d->authFile = NULL; ret = FALSE; } else { - Debug ("File: %s auth: %p\n", d->authFile, auths); + Debug ("file: %s auth: %p\n", d->authFile, auths); ret = TRUE; for (i = 0; i < count; i++) { /* - * User-based auths may not have data until - * a user logs in. In which case don't write - * to the auth file so xrdb and setup programs don't fail. + * User-based auths may not have data until a user logs in, in + * which case don't write to the auth file so xrdb and setup + * programs don't fail. */ if (auths[i]->data_length > 0) if (!XauWriteAuth (auth_file, auths[i]) || fflush (auth_file) == EOF) { - LogError ("Cannot write server authorization file %s\n", + LogError ("cannot write to server authorization file %s\n", d->authFile); ret = FALSE; free (d->authFile); d->authFile = NULL; } - } + } fclose (auth_file); } return ret; @@ -472,19 +489,36 @@ openFiles (char *name, char *new_name, FILE **oldp, FILE **newp) { int mask; + int newfd; strcpy (new_name, name); strcat (new_name, "-n"); mask = umask (0077); (void) unlink (new_name); - *newp = fopen (new_name, "w"); + newfd = open (new_name, O_WRONLY | O_CREAT | O_EXCL, 0600); + if (newfd >= 0) + *newp = fdopen (newfd, "w"); + else + { + LogError ("cannot create file %s: %s\n", new_name, + _SysErrorMsg (errno)); + Debug ("can't create file %s\n", new_name); + *newp = NULL; + } (void) umask (mask); - if (!*newp) { - Debug ("can't open new file %s\n", new_name); - return 0; + if (!*newp) + { + Debug ("can't open new file %s\n", new_name); + return 0; + } + else + Debug ("open succeeded: %s\n", new_name); + if (oldp) + { + *oldp = fopen (name, "r"); + if (*oldp) + Debug ("open succeeded: %s\n", name); } - *oldp = fopen (name, "r"); - Debug ("opens succeeded %s %s\n", name, new_name); return 1; } @@ -818,10 +852,11 @@ struct in_ifaddr ifaddr; struct strioctl str; unsigned char *addr; - int len, ipfd; + int len, ipfd; if ((ipfd = open ("/dev/ip", O_RDWR, 0 )) < 0) - LogError ("Getting interface configuration"); + LogError ("cannot get interface configuration; cannot open /dev/ip: " + "%s\n", _SysErrorMsg (errno)); /* Indicate that we want to start at the begining */ ifnet.ib_next = (struct ipb *) 1; @@ -835,8 +870,9 @@ if (ioctl (ipfd, (int) I_STR, (char *) &str) < 0) { + LogError ("cannot get interface configuration; ioctl failed: %s\n", + _SysErrorMsg (errno)); close (ipfd); - LogError ("Getting interface configuration"); } ifaddr.ia_next = (struct in_ifaddr *) ifnet.if_addrlist; @@ -847,8 +883,9 @@ if (ioctl (ipfd, (int) I_STR, (char *) &str) < 0) { + LogError ("cannot get interface configuration; ioctl failed: %s\n", + _SysErrorMsg (errno)); close (ipfd); - LogError ("Getting interface configuration"); } /* @@ -909,7 +946,7 @@ ifn.lifn_family = AF_UNSPEC; ifn.lifn_flags = 0; if (ioctl (fd, (int) SIOCGLIFNUM, (char *) &ifn) < 0) - LogError ("Failed getting interface count"); + LogError ("failed getting interface count"); if (buflen < (ifn.lifn_count * sizeof(struct lifreq))) { buflen = ifn.lifn_count * sizeof(struct lifreq); bufptr = malloc(buflen); @@ -944,7 +981,7 @@ #endif if (ifioctl (fd, IFC_IOCTL_REQ, (char *) &ifc) < 0) { - LogError ("Trouble getting network interface configuration"); + LogError ("trouble getting network interface configuration"); #ifdef USE_SIOCGLIFCONF if (bufptr != buf) { @@ -977,7 +1014,7 @@ if (len == 0) { - Debug ("Skipping zero length address\n"); + Debug ("skipping zero length address\n"); continue; } /* @@ -991,7 +1028,7 @@ addr[0] == 127 && addr[1] == 0 && addr[2] == 0 && addr[3] == 1) { - Debug ("Skipping localhost address\n"); + Debug ("skipping localhost address\n"); continue; } } @@ -1156,7 +1193,7 @@ snprintf (home_name, sizeof(home_name), "%s/.Xauthority", home); Debug ("XauLockAuth %s\n", home_name); lockStatus = XauLockAuth (home_name, 1, 2, 10); - Debug ("Lock is %d\n", lockStatus); + Debug ("lock is %d\n", lockStatus); if (lockStatus == LOCK_SUCCESS) { if (openFiles (home_name, new_name, &old, &new)) { name = home_name; @@ -1165,28 +1202,47 @@ Debug ("openFiles failed\n"); XauUnlockAuth (home_name); lockStatus = LOCK_ERROR; - } + } } } if (lockStatus != LOCK_SUCCESS) { + /* log the fact that we're having trouble with authorization */ + if (home) { + LogInfo ("unable to lock authority file in %s for display %s\n", + home, d->name); + } else { + LogInfo ("unable to determine home directory for authority " + "file locking on display %s\n", d->name); + } snprintf (backup_name, sizeof(backup_name), "%s/.XauthXXXXXX", d->userAuthDir); + /* + * Security auditors should note that mktemp() is not used + * unsafely here. XauLockAuth() is very careful about opening + * the authority file, using O_CREAT and O_EXCL. + * + * However, note that the file backup_name will likely never be + * unlinked, since the user's home directory was unwritable and we + * will have to use backup_name as the authority file for the entire + * session. + */ (void) mktemp (backup_name); lockStatus = XauLockAuth (backup_name, 1, 2, 10); Debug ("backup lock is %d\n", lockStatus); if (lockStatus == LOCK_SUCCESS) { - if (openFiles (backup_name, new_name, &old, &new)) { + if (openFiles (backup_name, new_name, NULL, &new)) { + old = NULL; name = backup_name; setenv = 1; } else { XauUnlockAuth (backup_name); lockStatus = LOCK_ERROR; - } + } } } if (lockStatus != LOCK_SUCCESS) { Debug ("can't lock auth file %s or backup %s\n", home_name, backup_name); - LogError ("can't lock authorization file %s or backup %s\n", + LogError ("cannot lock authorization file %s or backup %s\n", home_name, backup_name); return; } @@ -1242,7 +1298,7 @@ while ((entry = XauReadAuth (old))) { if (!checkEntry (entry)) { - Debug ("Writing an entry\n"); + Debug ("writing an entry\n"); writeAuth (new, entry); } XauDisposeAuth (entry); @@ -1255,8 +1311,9 @@ Debug ("unlink %s failed\n", name); envname = name; if (link (new_name, name) == -1) { + LogError ("cannot move authorization file into place: %s\n", + _SysErrorMsg (errno)); Debug ("link failed %s %s\n", new_name, name); - LogError ("Can't move authorization into place\n"); setenv = 1; envname = new_name; } else { @@ -1296,7 +1353,7 @@ snprintf(name, sizeof(name), "%s/.Xauthority", home); Debug ("XauLockAuth %s\n", name); lockStatus = XauLockAuth (name, 1, 2, 10); - Debug ("Lock is %d\n", lockStatus); + Debug ("lock is %d\n", lockStatus); if (lockStatus != LOCK_SUCCESS) return; if (openFiles (name, new_name, &old, &new)) @@ -1320,7 +1377,7 @@ while ((entry = XauReadAuth (old))) { if (!checkEntry (entry)) { - Debug ("Writing an entry\n"); + Debug ("writing an entry\n"); writeAuth (new, entry); } XauDisposeAuth (entry); @@ -1332,12 +1389,14 @@ if (unlink (name) == -1) Debug ("unlink %s failed\n", name); if (link (new_name, name) == -1) { + LogError ("cannot move authorization file into place: %s\n", + _SysErrorMsg (errno)); Debug ("link failed %s %s\n", new_name, name); - LogError ("Can't move authorization into place\n"); } else { Debug ("new is in place, go for it!\n"); unlink (new_name); } } XauUnlockAuth (name); + Debug ("done RemoveUserAuthorization\n"); } diff -urN xc/programs/xdm~/choose.c xc/programs/xdm/choose.c --- xc/programs/xdm~/choose.c 2003-09-21 15:39:22.000000000 -0500 +++ xc/programs/xdm/choose.c 2003-09-21 15:40:41.000000000 -0500 @@ -191,8 +191,8 @@ if (GetChooserAddr ((char *)addr_buf, &addr_len) == -1) { - LogError ("Cannot get return address for chooser socket\n"); - Debug ("Cannot get chooser socket address\n"); + LogError ("cannot get return address for chooser socket\n"); + Debug ("cannot get chooser socket address\n"); return 0; } netfamily = NetaddrFamily((XdmcpNetaddr)addr_buf); @@ -219,7 +219,7 @@ break; #endif default: - Debug ("Chooser family %d isn't known\n", netfamily); + Debug ("chooser family %d isn't known\n", netfamily); return 0; } @@ -249,11 +249,11 @@ for (c = choices; c; c = next) { next = c->next; - Debug ("Choice checking timeout: %ld >? %d\n", + Debug ("choice checking timeout: %ld >? %d\n", (long)(now - c->time), choiceTimeout); if (now - c->time > (Time_t)choiceTimeout) { - Debug ("Timeout choice %ld > %d\n", + Debug ("timeout choice %ld > %d\n", (long)(now - c->time), choiceTimeout); if (prev) prev->next = next; @@ -286,7 +286,7 @@ int found = 0; #endif - Debug ("Got indirect choice back\n"); + Debug ("got indirect choice back\n"); for (c = choices; c; c = c->next) { if (XdmcpARRAY8Equal (clientAddress, &c->client) && connectionType == c->connectionType) { @@ -406,14 +406,14 @@ if( call == NULL ) { t_error( "ProcessChooserSocket: t_alloc failed" ); - LogError ("Cannot setup to listen on chooser connection\n"); + LogError ("cannot setup to listen on chooser connection\n"); return; } if( t_listen( fd, call ) < 0 ) { t_error( "ProcessChooserSocket: t_listen failed" ); t_free( (char *)call, T_CALL ); - LogError ("Cannot listen on chooser connection\n"); + LogError ("cannot listen on chooser connection\n"); return; } client_fd = t_open ("/dev/tcp", O_RDWR, NULL); @@ -421,21 +421,21 @@ { t_error( "ProcessChooserSocket: t_open failed" ); t_free( (char *)call, T_CALL ); - LogError ("Cannot open new chooser connection\n"); + LogError ("cannot open new chooser connection\n"); return; } if( t_bind( client_fd, NULL, NULL ) < 0 ) { t_error( "ProcessChooserSocket: t_bind failed" ); t_free( (char *)call, T_CALL ); - LogError ("Cannot bind new chooser connection\n"); + LogError ("cannot bind new chooser connection\n"); t_close (client_fd); return; } if( t_accept (fd, client_fd, call) < 0 ) { t_error( "ProcessChooserSocket: t_accept failed" ); - LogError ("Cannot accept chooser connection\n"); + LogError ("cannot accept chooser connection\n"); t_free( (char *)call, T_CALL ); t_unbind (client_fd); t_close (client_fd); @@ -445,18 +445,18 @@ client_fd = accept (fd, (struct sockaddr *)buf, (void *)&len); if (client_fd == -1) { - LogError ("Cannot accept chooser connection\n"); + LogError ("cannot accept chooser connection\n"); return; } #endif - Debug ("Accepted %d\n", client_fd); + Debug ("accepted %d\n", client_fd); #if defined(STREAMSCONN) len = t_rcv (client_fd, buf, sizeof (buf),&flags); #else len = read (client_fd, buf, sizeof (buf)); #endif - Debug ("Read returns %d\n", len); + Debug ("read returns %d\n", len); if (len > 0) { buffer.data = (BYTE *) buf; @@ -470,23 +470,23 @@ if (XdmcpReadARRAY8 (&buffer, &clientAddress)) { if (XdmcpReadCARD16 (&buffer, &connectionType)) { if (XdmcpReadARRAY8 (&buffer, &choice)) { - Debug ("Read from chooser succesfully\n"); + Debug ("read from chooser succesfully\n"); RegisterIndirectChoice (&clientAddress, connectionType, &choice); XdmcpDisposeARRAY8 (&choice); } else { - LogError ("Invalid choice response length %d\n", len); + LogError ("invalid choice response length %d\n", len); } } else { - LogError ("Invalid choice response length %d\n", len); + LogError ("invalid choice response length %d\n", len); } XdmcpDisposeARRAY8 (&clientAddress); } else { - LogError ("Invalid choice response length %d\n", len); + LogError ("invalid choice response length %d\n", len); } } else { - LogError ("Choice response read error: %s\n", strerror(errno)); + LogError ("choice response read error: %s\n", _SysErrorMsg (errno)); } #if defined(STREAMSCONN) @@ -524,10 +524,10 @@ ForEachChooserHost (&d->clientAddr, d->connectionType, AddChooserHost, (char *) &args); env = systemEnv (d, (char *) 0, (char *) 0); - Debug ("Running %s\n", args[0]); + Debug ("running %s\n", args[0]); execute (args, env); - Debug ("Couldn't run %s\n", args[0]); - LogError ("Cannot execute %s\n", args[0]); + Debug ("couldn't run %s\n", args[0]); + LogError ("cannot execute %s\n", args[0]); exit (REMANAGE_DISPLAY); } diff -urN xc/programs/xdm~/config/Imakefile xc/programs/xdm/config/Imakefile --- xc/programs/xdm~/config/Imakefile 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/config/Imakefile 2003-09-21 15:40:41.000000000 -0500 @@ -39,7 +39,11 @@ #endif CppFileTarget(Xservers.ws,Xserv.ws.cpp,-DBINDIR=$(BINDIR) -DDEFAULTVT=$(DEFAULTVT),NullParameter) +#if defined(LinuxArchitecture) || defined(GNUMachArchitecture) +CppFileTarget(xdm-config,xdm-conf.cpp,-DXDMDIR=$(XDMDIR) -DXDMLOGDIR=$(XDMLOGDIR) -DXDMPIDDIR=$(XDMPIDDIR) -DXDMVARDIR=$(XDMVARDIR) -DSU=$(SU),NullParameter) +#else CppFileTarget(xdm-config,xdm-conf.cpp,-DXDMDIR=$(XDMDIR) -DXDMLOGDIR=$(XDMLOGDIR) -DXDMPIDDIR=$(XDMPIDDIR) -DSU=$(SU),NullParameter) +#endif /* LinuxArchitecture || GNUMachArchitecture */ CppFileTarget(Xresources,Xres.cpp,$(XPM_DEFINES),NullParameter) LinkFile(Xservers,Xservers.$(SERVERSTYPE)) diff -urN xc/programs/xdm~/config/Xres.cpp xc/programs/xdm/config/Xres.cpp --- xc/programs/xdm~/config/Xres.cpp 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/config/Xres.cpp 2003-09-21 15:40:41.000000000 -0500 @@ -28,22 +28,25 @@ #endif /* XPM */ xlogin*fail: Login incorrect #ifdef XPM -/**/#if WIDTH > 800 -xlogin*greetFont: -adobe-helvetica-bold-o-normal--24-240-75-75-p-138-iso8859-1 -xlogin*font: -adobe-helvetica-medium-r-normal--18-180-75-75-p-98-iso8859-1 -xlogin*promptFont: -adobe-helvetica-bold-r-normal--18-180-75-75-p-103-iso8859-1 -xlogin*failFont: -adobe-helvetica-bold-r-normal--18-180-75-75-p-103-iso8859-1 +/**/#if WIDTH >= 1024 +xlogin*greetFont: -adobe-helvetica-bold-o-normal--25-180-100-100-p-138-iso8859-1 +xlogin*font: -adobe-helvetica-medium-r-normal--20-140-100-100-p-100-iso8859-1 +xlogin*promptFont: -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 +xlogin*failFont: -adobe-helvetica-bold-r-normal--20-140-100-100-p-105-iso8859-1 +/**/#if PLANES >= 8 +xlogin*logoFileName: BITMAPDIR/**//XDM_PIXMAP +/**/#else +xlogin*logoFileName: BITMAPDIR/**//XDM_BWPIXMAP +/**/#endif /**/#else -xlogin*greetFont: -adobe-helvetica-bold-o-normal--17-120-100-100-p-92-iso8859-1 +xlogin*greetFont: -adobe-helvetica-bold-o-normal--14-140-75-75-p-82-iso8859-1 xlogin*font: -adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1 xlogin*promptFont: -adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1 -xlogin*failFont: -adobe-helvetica-bold-o-normal--14-140-75-75-p-82-iso8859-1 +xlogin*failFont: -adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1 /**/#endif #endif /* XPM */ /**/#ifdef COLOR -#ifndef XPM -xlogin*greetColor: CadetBlue -#else +#ifdef XPM xlogin*borderWidth: 1 xlogin*frameWidth: 5 xlogin*innerFramesWidth: 2 @@ -52,6 +55,8 @@ xlogin*background: grey !xlogin*foreground: darkgreen xlogin*greetColor: Blue3 +#else +xlogin*greetColor: CadetBlue #endif /* XPM */ xlogin*failColor: red *Foreground: black @@ -70,11 +75,6 @@ #endif /* XPM */ /**/#endif #ifdef XPM -/**/#if PLANES >= 8 -xlogin*logoFileName: BITMAPDIR/**//XDM_PIXMAP -/**/#else -xlogin*logoFileName: BITMAPDIR/**//XDM_BWPIXMAP -/**/#endif xlogin*useShape: true xlogin*logoPadding: 10 #endif /* XPM */ diff -urN xc/programs/xdm~/daemon.c xc/programs/xdm/daemon.c --- xc/programs/xdm~/daemon.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/daemon.c 2003-09-21 15:40:41.000000000 -0500 @@ -87,7 +87,7 @@ break; case -1: /* error */ - LogError ("daemon fork failed, errno = %d\n", errno); + LogError ("daemon fork failed: %s\n", _SysErrorMsg (errno)); break; default: { @@ -107,7 +107,7 @@ #endif if (stat != 0) LogError ("setting process group for daemon failed: %s\n", - strerror(errno)); + _SysErrorMsg (errno)); #endif /* ! (CSRG_BASED || SYSV || SVR4 || __QNXNTO__ || __GLIBC__) */ } exit (0); @@ -118,28 +118,29 @@ BecomeDaemon (void) { /* - * Close standard file descriptors and get rid of controlling tty + * Get rid of controlling tty. We would close standard file + * descriptors as well, but that interferes with our logging. */ /* If our C library has the daemon() function, just use it. */ #if defined(__GLIBC__) || defined(CSRG_BASED) - daemon (0, 0); + if ((daemon (0, 1)) == -1) { + if (errno) { + LogError ("unable to daemonize: %s\n", _SysErrorMsg (errno)); + } else { + LogError ("unable to daemonize\n"); + } + } #else - int i; - # if defined(SYSV) || defined(SVR4) || defined(__QNXNTO__) setpgrp (); # else setpgrp (0, getpid ()); # endif - close (0); - close (1); - close (2); - # if !defined(__UNIXOS2__) && !defined(__CYGWIN__) # if !((defined(SYSV) || defined(SVR4)) && defined(i386)) - if ((i = open ("/dev/tty", O_RDWR)) >= 0) { /* did open succeed? */ + if ((int i = open ("/dev/tty", O_RDWR)) >= 0) { /* did open succeed? */ # if defined(USG) && defined(TCCLRCTTY) int zero = 0; (void) ioctl (i, TCCLRCTTY, &zero); @@ -148,19 +149,12 @@ int zero = 0; (void) ioctl (i, TIOCTTY, &zero); # else - (void) ioctl (i, TIOCNOTTY, (char *) 0); /* detach, BSD style */ + (void) ioctl (i, TIOCNOTTY, (char *) 0); /* detach, BSD style */ # endif # endif (void) close (i); } # endif /* !((SYSV || SVR4) && i386) */ # endif /* !__UNIXOS2__ && !__CYGWIN__*/ - - /* - * Set up the standard file descriptors. - */ - (void) open ("/", O_RDONLY); /* root inode already in core */ - (void) dup2 (0, 1); - (void) dup2 (0, 2); #endif } diff -urN xc/programs/xdm~/dm.c xc/programs/xdm/dm.c --- xc/programs/xdm~/dm.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/dm.c 2003-09-21 15:40:41.000000000 -0500 @@ -35,41 +35,42 @@ * display manager */ -# include "dm.h" -# include "dm_auth.h" -# include "dm_error.h" +#include "dm.h" +#include "dm_auth.h" +#include "dm_error.h" -# include <stdio.h> +#include <stdio.h> +#include <string.h> #ifdef X_POSIX_C_SOURCE -#define _POSIX_C_SOURCE X_POSIX_C_SOURCE -#include <signal.h> -#undef _POSIX_C_SOURCE -#else -#if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE) -#include <signal.h> -#else -#define _POSIX_SOURCE -#include <signal.h> -#undef _POSIX_SOURCE -#endif +# define _POSIX_C_SOURCE X_POSIX_C_SOURCE +# include <signal.h> +# undef _POSIX_C_SOURCE +#else +# if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE) +# include <signal.h> +# else +# define _POSIX_SOURCE +# include <signal.h> +# undef _POSIX_SOURCE +# endif #endif #ifdef __NetBSD__ -#include <sys/param.h> +# include <sys/param.h> #endif #ifndef sigmask -#define sigmask(m) (1 << ((m - 1))) +# define sigmask(m) (1 << ((m - 1))) #endif -# include <sys/stat.h> -# include <errno.h> -# include <X11/Xfuncproto.h> -# include <stdarg.h> +#include <sys/stat.h> +#include <errno.h> +#include <X11/Xfuncproto.h> +#include <stdarg.h> #ifndef F_TLOCK -#ifndef X_NOT_POSIX +# ifndef X_NOT_POSIX # include <unistd.h> -#endif +# endif #endif @@ -100,7 +101,9 @@ static SIGVAL ChildNotify (int n); #endif -static int StorePid (void); +static int pidFd; +static FILE *pidFilePtr; +static long StorePid (void); static int parent_pid = -1; /* PID of parent xdm process */ @@ -124,34 +127,42 @@ InitResources (argc, argv); SetConfigFileTime (); LoadDMResources (); + if (debugLevel == 0) + { + if (getuid() != 0) + { /* - * Only allow root to run in non-debug mode to avoid problems + * only allow root to run in non-debug mode to avoid problems */ - if (debugLevel == 0 && getuid() != 0) - { - fprintf (stderr, "Only root wants to run %s\n", argv[0]); + LogError ("only root run can run %s in non-debug mode; exiting\n", + argv[0]); exit (1); } + /* + * if not debugging, send messages to the log file + */ + InitErrorLog (); + } if (debugLevel == 0 && daemonMode) BecomeOrphan (); if (debugLevel >= 10) nofork_session = 1; if (debugLevel == 0 && daemonMode) BecomeDaemon (); - /* SUPPRESS 560 */ if ((oldpid = StorePid ())) { if (oldpid == -1) - LogError ("Can't create/lock pid file %s\n", pidFile); + LogError ("error opening process-id file %s; exiting\n", pidFile); else - LogError ("Can't lock pid file %s, another xdm is running (pid %d)\n", - pidFile, oldpid); + LogError ("process-id file %s indicates another xdm is " + "running (pid %d); exiting\n", pidFile, oldpid); exit (1); } - if (debugLevel == 0) - InitErrorLog (); - if (nofork_session == 0) { + LogInfo ("starting\n"); + + if (nofork_session == 0) + { /* Clean up any old Authorization files */ /* AUD: all good? */ snprintf(cmdbuf, sizeof(cmdbuf), "/bin/rm -f %s/authdir/authfiles/A*", authDir); @@ -190,6 +201,7 @@ #ifndef UNRELIABLE_SIGNALS (void) Signal (SIGCHLD, ChildNotify); #endif + Debug ("startup successful; entering main loop\n"); while ( #ifdef XDMCP AnyWellKnownSockets() || @@ -207,8 +219,9 @@ WaitForSomething (); #endif } - Debug ("Nothing left to do, exiting\n"); - exit(0); + Debug ("nothing left to do, exiting\n"); + LogInfo ("exiting\n"); + exit (0); /*NOTREACHED*/ } @@ -218,7 +231,7 @@ { int olderrno = errno; - Debug ("Caught SIGHUP\n"); + Debug ("caught SIGHUP\n"); Rescan = 1; #ifdef SIGNALS_RESET_WHEN_CAUGHT (void) Signal (SIGHUP, RescanNotify); @@ -278,7 +291,7 @@ RescanServers (void) { Debug ("rescanning servers\n"); - LogInfo ("Rescanning both config and servers files\n"); + LogInfo ("rescanning both config and servers files\n"); ForEachDisplay (MarkDisplay); SetConfigFileTime (); ReinitResources (); @@ -319,8 +332,8 @@ { if (statb.st_mtime != ConfigModTime) { - Debug ("Config file %s has changed, rereading\n", config); - LogInfo ("Rereading configuration file %s\n", config); + Debug ("config file %s has changed, rereading\n", config); + LogInfo ("rereading configuration file %s\n", config); ConfigModTime = statb.st_mtime; ReinitResources (); LoadDMResources (); @@ -330,8 +343,8 @@ { if (statb.st_mtime != ServersModTime) { - Debug ("Servers file %s has changed, rescanning\n", servers); - LogInfo ("Rereading servers file %s\n", servers); + Debug ("servers file %s has changed, rescanning\n", servers); + LogInfo ("rereading servers file %s\n", servers); ServersModTime = statb.st_mtime; ForEachDisplay (MarkDisplay); ScanServers (); @@ -342,8 +355,8 @@ { if (statb.st_mtime != AccessFileModTime) { - Debug ("Access file %s has changed, rereading\n", accessFile); - LogInfo ("Rereading access file %s\n", accessFile); + Debug ("access file %s has changed, rereading\n", accessFile); + LogInfo ("rereading access file %s\n", accessFile); AccessFileModTime = statb.st_mtime; ScanAccessDatabase (); UpdateListenSockets(); @@ -371,13 +384,14 @@ * * See defect XWSog08655 for more information. */ - Debug ("Child xdm caught SIGTERM before it remove that signal.\n"); + Debug ("child xdm caught SIGTERM before it removed that signal\n"); (void) Signal (n, SIG_DFL); TerminateProcess (getpid(), SIGTERM); errno = olderrno; return; } - Debug ("Shutting down entire manager\n"); + Debug ("shutting down entire manager\n"); + LogInfo ("shutting down\n"); #ifdef XDMCP DestroyWellKnownSockets (); #endif @@ -428,66 +442,62 @@ /* XXX classic System V signal race condition here with RescanNotify */ if ((pid = wait (&status)) != -1) #else -#ifndef X_NOT_POSIX +# ifndef X_NOT_POSIX sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigaddset(&mask, SIGHUP); sigprocmask(SIG_BLOCK, &mask, &omask); Debug ("signals blocked\n"); -#else +# else omask = sigblock (sigmask (SIGCHLD) | sigmask (SIGHUP)); Debug ("signals blocked, mask was 0x%x\n", omask); -#endif +# endif if (!ChildReady && !Rescan) -#ifndef X_NOT_POSIX +# ifndef X_NOT_POSIX sigsuspend(&omask); -#else +# else sigpause (omask); -#endif +# endif ChildReady = 0; -#ifndef X_NOT_POSIX +# ifndef X_NOT_POSIX sigprocmask(SIG_SETMASK, &omask, (sigset_t *)NULL); -#else +# else sigsetmask (omask); -#endif -#ifndef X_NOT_POSIX +# endif +# ifndef X_NOT_POSIX while ((pid = waitpid (-1, &status, WNOHANG)) > 0) -#else +# else while ((pid = wait3 (&status, WNOHANG, (struct rusage *) 0)) > 0) -#endif -#endif +# endif +#endif /* UNRELIABLE_SIGNALS */ { - Debug ("Manager wait returns pid: %d sig %d core %d code %d\n", + Debug ("manager wait returns pid: %d sig %d core %d code %d\n", pid, waitSig(status), waitCore(status), waitCode(status)); if (autoRescan) RescanIfMod (); /* SUPPRESS 560 */ - if ((d = FindDisplayByPid (pid))) { + if ((d = FindDisplayByPid (pid))) + { d->pid = -1; - switch (waitVal (status)) { + switch (waitVal (status)) + { case UNMANAGE_DISPLAY: - Debug ("Display exited with UNMANAGE_DISPLAY\n"); + Debug ("display exited with UNMANAGE_DISPLAY\n"); StopDisplay (d); break; case OBEYSESS_DISPLAY: d->startTries = 0; - Debug ("Display exited with OBEYSESS_DISPLAY\n"); + Debug ("display exited with OBEYSESS_DISPLAY\n"); if (d->displayType.lifetime != Permanent || d->status == zombie) StopDisplay (d); else RestartDisplay (d, FALSE); break; - default: - Debug ("Display exited with unknown status %d\n", waitVal(status)); - LogError ("Unknown session exit code %d from process %d\n", - waitVal (status), pid); - StopDisplay (d); - break; case OPENFAILED_DISPLAY: - Debug ("Display exited with OPENFAILED_DISPLAY, try %d of %d\n", + Debug ("display exited with OPENFAILED_DISPLAY, try %d of %d\n", d->startTries, d->startAttempts); - LogError ("Display %s cannot be opened\n", d->name); + LogError ("display %s cannot be opened\n", d->name); /* * no display connection was ever made, tell the * terminal that the open attempt failed @@ -500,7 +510,7 @@ d->status == zombie || ++d->startTries >= d->startAttempts) { - LogError ("Display %s is being disabled\n", d->name); + LogError ("display %s is being disabled\n", d->name); StopDisplay (d); } else @@ -510,7 +520,7 @@ break; case RESERVER_DISPLAY: d->startTries = 0; - Debug ("Display exited with RESERVER_DISPLAY\n"); + Debug ("display exited with RESERVER_DISPLAY\n"); if (d->displayType.origin == FromXDMCP || d->status == zombie) StopDisplay(d); else @@ -520,33 +530,45 @@ time(&Time); Debug("time %i %i\n",Time,d->lastCrash); if (d->lastCrash && - ((Time - d->lastCrash) < XDM_BROKEN_INTERVAL)) { - Debug("Server crash frequency too high:" + ((Time - d->lastCrash) < XDM_BROKEN_INTERVAL)) + { + Debug("server crash frequency too high:" " removing display %s\n",d->name); - LogError("Server crash rate too high:" + LogError("server crash rate too high:" " removing display %s\n",d->name); #if !defined(ARC4_RANDOM) && !defined(DEV_RANDOM) AddTimerEntropy(); #endif RemoveDisplay (d); - } else + } + else d->lastCrash = Time; } break; case waitCompose (SIGTERM,0,0): - Debug ("Display exited on SIGTERM, try %d of %d\n", + Debug ("display exited on SIGTERM, try %d of %d\n", d->startTries, d->startAttempts); if (d->displayType.origin == FromXDMCP || d->status == zombie || - ++d->startTries >= d->startAttempts) { - LogError ("Display %s is being disabled\n", d->name); + ++d->startTries >= d->startAttempts) + { + /* + * During normal xdm shutdown, killed local X servers + * can be zombies; this is not an error. + */ + if (d->status == zombie && + (d->startTries < d->startAttempts)) + LogInfo ("display %s is being disabled\n", d->name); + else + LogError ("display %s is being disabled\n", d->name); StopDisplay(d); - } else + } + else RestartDisplay (d, TRUE); break; case REMANAGE_DISPLAY: d->startTries = 0; - Debug ("Display exited with REMANAGE_DISPLAY\n"); + Debug ("display exited with REMANAGE_DISPLAY\n"); /* * XDMCP will restart the session if the display * requests it @@ -556,6 +578,13 @@ else RestartDisplay (d, FALSE); break; + default: + Debug ("display %s exited with unknown status %d\n", + d->name, waitVal(status)); + LogError ("display %s (pid %ld) exited with unexpected status " + "%d\n", d->name, waitVal (status), (long) pid); + StopDisplay (d); + break; } } /* SUPPRESS 560 */ @@ -565,30 +594,34 @@ switch (d->status) { case zombie: - Debug ("Zombie server reaped, removing display %s\n", d->name); + Debug ("zombie server reaped, removing display %s\n", d->name); RemoveDisplay (d); break; case phoenix: - Debug ("Phoenix server arises, restarting display %s\n", d->name); + Debug ("phoenix server arises, restarting display %s\n", + d->name); d->status = notRunning; break; case running: - Debug ("Server for display %s terminated unexpectedly, status %d %d\n", d->name, waitVal (status), status); - LogError ("Server for display %s terminated unexpectedly: %d\n", d->name, waitVal (status)); + Debug ("server for display %s terminated unexpectedly, " + "status %d %d\n", d->name, waitVal (status), status); + LogError ("server for display %s terminated unexpectedly: %d\n", + d->name, waitVal (status)); if (d->pid != -1) { - Debug ("Terminating session pid %d\n", d->pid); + Debug ("terminating session pid %d\n", d->pid); TerminateProcess (d->pid, SIGTERM); } break; case notRunning: - Debug ("Server exited for notRunning session on display %s\n", d->name); + Debug ("server exited for notRunning session on display %s\n", + d->name); break; } } else { - Debug ("Unknown child termination, status %d\n", waitVal (status)); + Debug ("unknown child termination, status %d\n", waitVal (status)); } } StartDisplays (); @@ -599,7 +632,8 @@ { if (d->displayType.origin == FromFile) { - switch (d->state) { + switch (d->state) + { case MissingEntry: StopDisplay (d); break; @@ -625,10 +659,12 @@ int pid; Debug ("StartDisplay %s\n", d->name); + LogInfo ("starting X server on %s\n", d->name); LoadServerResources (d); if (d->displayType.location == Local) { - /* don't bother pinging local displays; we'll + /* + * don't bother pinging local displays; we'll * certainly notice when they exit */ d->pingInterval = 0; @@ -648,7 +684,8 @@ } if (d->serverPid == -1 && !StartServer (d)) { - LogError ("Server for display %s can't be started, session disabled\n", d->name); + LogError ("server for display %s can't be started, session " + "disabled\n", d->name); RemoveDisplay (d); return; } @@ -666,7 +703,8 @@ switch (pid) { case 0: - if (!nofork_session) { + if (!nofork_session) + { CleanUpChild (); (void) Signal (SIGPIPE, SIG_IGN); } @@ -750,7 +788,8 @@ ClearCloseOnFork (int fd) { FD_CLR (fd, &CloseMask); - if (fd == max) { + if (fd == max) + { while (--fd >= 0) if (FD_ISSET (fd, &CloseMask)) break; @@ -772,100 +811,68 @@ max = 0; } -static int pidFd; -static FILE *pidFilePtr; - -static int +static long StorePid (void) { - int oldpid; + long oldpid; + char pidstr[11]; /* enough space for a 32-bit pid plus \0 */ + size_t pidstrlen; - if (pidFile[0] != '\0') { - pidFd = open (pidFile, O_RDWR); - if (pidFd == -1 && errno == ENOENT) - pidFd = open (pidFile, O_RDWR|O_CREAT, 0666); - if (pidFd == -1 || !(pidFilePtr = fdopen (pidFd, "r+"))) + if (pidFile[0] != '\0') + { + pidFd = open (pidFile, O_WRONLY|O_CREAT|O_EXCL, 0666); + if (pidFd == -1) { - LogError ("process-id file %s cannot be opened\n", - pidFile); - return -1; - } - if (fscanf (pidFilePtr, "%d\n", &oldpid) != 1) - oldpid = -1; - fseek (pidFilePtr, 0l, 0); - if (lockPidFile) - { -#ifdef F_SETLK -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - struct flock lock_data; - lock_data.l_type = F_WRLCK; - lock_data.l_whence = SEEK_SET; - lock_data.l_start = lock_data.l_len = 0; - if (fcntl(pidFd, F_SETLK, &lock_data) == -1) + if (errno == EEXIST) { - if (errno == EAGAIN) - return oldpid; - else + /* pidFile already exists; see if we can open it */ + pidFilePtr = fopen (pidFile, "r"); + if (pidFilePtr == NULL) + { + LogError ("cannot open process-id file %s for reading: " + "%s\n", pidFile, _SysErrorMsg (errno)); return -1; + } + if (fscanf (pidFilePtr, "%ld\n", &oldpid) != 1) + { + LogError ("existing process-id file %s empty or contains " + "garbage\n", pidFile); + oldpid = -1; + } + fclose (pidFilePtr); + return oldpid; } -#else -#ifdef LOCK_EX - if (flock (pidFd, LOCK_EX|LOCK_NB) == -1) - { - if (errno == EWOULDBLOCK) - return oldpid; else - return -1; - } -#else - if (lockf (pidFd, F_TLOCK, 0) == -1) { - if (errno == EACCES) - return oldpid; - else - return -1; + LogError ("cannot fdopen process-id file %s for writing: " + "%s\n", pidFile, _SysErrorMsg (errno)); + return -1; } -#endif -#endif } - fprintf (pidFilePtr, "%5ld\n", (long)getpid ()); + if ((pidFilePtr = fdopen (pidFd, "w")) == NULL) + { + LogError ("cannot open process-id file %s for writing: %s\n", + pidFile, _SysErrorMsg (errno)); + return -1; + } + (void) snprintf (pidstr, 11, "%ld", (long) getpid ()); + pidstrlen = strlen (pidstr); + if (fprintf (pidFilePtr, "%s\n", pidstr) != ( pidstrlen + 1)) + { + LogError ("cannot write to process-id file %s: %s\n", pidFile, + _SysErrorMsg (errno)); + return -1; + } (void) fflush (pidFilePtr); - RegisterCloseOnFork (pidFd); + (void) fclose (pidFilePtr); } return 0; } -#if 0 -void -UnlockPidFile (void) -{ - if (lockPidFile) -#ifdef F_SETLK - { - struct flock lock_data; - lock_data.l_type = F_UNLCK; - lock_data.l_whence = SEEK_SET; - lock_data.l_start = lock_data.l_len = 0; - (void) fcntl(pidFd, F_SETLK, &lock_data); - } -#else -#ifdef F_ULOCK - lockf (pidFd, F_ULOCK, 0); -#else - flock (pidFd, LOCK_UN); -#endif -#endif - close (pidFd); - fclose (pidFilePtr); -} -#endif - #ifndef HAS_SETPROCTITLE void SetTitle (char *name, ...) { -#ifndef NOXDMTITLE +# ifndef NOXDMTITLE char *p = Title; int left = TitleLen; char *s; @@ -890,6 +897,6 @@ --left; } va_end(args); -#endif +# endif /* NOXDMTITLE */ } -#endif +#endif /* HAS_SETPROCTITLE */ diff -urN xc/programs/xdm~/dm_auth.h xc/programs/xdm/dm_auth.h --- xc/programs/xdm~/dm_auth.h 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/dm_auth.h 2003-09-21 15:40:41.000000000 -0500 @@ -42,18 +42,40 @@ extern void MitInitAuth (unsigned short name_len, char *name); extern Xauth *MitGetAuth (unsigned short namelen, char *name); +/* xdmauth.c */ #ifdef HASXDMAUTH extern void XdmInitAuth (unsigned short name_len, char *name); extern Xauth *XdmGetAuth (unsigned short namelen, char *name); -#ifdef XDMCP +# ifdef XDMCP extern void XdmGetXdmcpAuth ( struct protoDisplay *pdpy, unsigned short authorizationNameLen, char *authorizationName); -#else -#define XdmGetXdmcpAuth NULL -#endif -#endif + +extern int XdmCheckAuthentication ( + struct protoDisplay *pdpy, + ARRAY8Ptr displayID, + ARRAY8Ptr authenticationName, + ARRAY8Ptr authenticationData); + +typedef unsigned char auth_cblock[8]; /* block size */ + +typedef struct auth_ks_struct { auth_cblock _; } auth_wrapper_schedule[16]; + +extern void _XdmcpAuthSetup (auth_cblock key, + auth_wrapper_schedule schedule); + +extern void _XdmcpAuthDoIt (auth_cblock input, + auth_cblock output, + auth_wrapper_schedule schedule, + int edflag); + +extern void _XdmcpWrapperToOddParity (unsigned char *in, + unsigned char *out); +# else +# define XdmGetXdmcpAuth NULL +# endif +#endif /* HASXDMAUTH */ #ifdef SECURE_RPC extern void SecureRPCInitAuth (unsigned short name_len, char *name); @@ -68,15 +90,12 @@ /* auth.c */ extern int ValidAuthorization (unsigned short name_length, char *name); - #ifdef XDMCP - extern void SetProtoDisplayAuthorization ( struct protoDisplay *pdpy, unsigned short authorizationNameLen, char *authorizationName); - #endif /* XDMCP */ extern int SaveServerAuthorizations (struct display *d, Xauth **auths, int count); diff -urN xc/programs/xdm~/dm_error.h xc/programs/xdm/dm_error.h --- xc/programs/xdm~/dm_error.h 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/dm_error.h 2003-09-21 15:40:41.000000000 -0500 @@ -50,7 +50,6 @@ extern void LogInfo (char * fmt, ...) GCC_PRINTFLIKE(1,2); extern void LogOutOfMem (char * fmt, ...) GCC_PRINTFLIKE(1,2); extern void LogPanic (char * fmt, ...) GCC_PRINTFLIKE(1,2); -extern void Panic (char * mesg); #endif /* _DM_ERROR_H_ */ diff -urN xc/programs/xdm~/error.c xc/programs/xdm/error.c --- xc/programs/xdm~/error.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/error.c 2003-09-21 15:40:41.000000000 -0500 @@ -34,23 +34,41 @@ * * error.c * - * Log display manager errors to a file as - * we generally do not have a terminal to talk to + * Log display manager errors to a file as we generally do not have a + * terminal to talk to. + * + * Because we have child processes, and chatty things like X servers, we do + * not use syslog(). */ -# include <stdio.h> -# include <stdarg.h> +#include <errno.h> +#include <stdio.h> +#include <stdarg.h> +#include <time.h> -# include "dm.h" -# include "dm_error.h" +#include "dm.h" +#include "dm_error.h" #define WRITES(fd, buf) write(fd, buf, strlen(buf)) -void LogInfo(char * fmt, ...) +void +LogInfo(char * fmt, ...) { char buf[1024]; - snprintf(buf, sizeof buf, "xdm info (pid %ld): ", (long)getpid()); + time_t seconds; + struct tm *timestamp = NULL; + char timebuf[256]; + + if (time(&seconds) > (time_t) -1) + timestamp = localtime(&seconds); + + strcpy(timebuf, "(time unavailable)"); + + if (timestamp != NULL) + strftime(timebuf, 255, "%c", timestamp); + + snprintf(buf, sizeof buf, "%s xdm info (pid %ld): ", timebuf, (long)getpid()); WRITES(STDERR_FILENO, buf); { va_list args; @@ -61,11 +79,24 @@ WRITES(STDERR_FILENO, buf); } -void LogError (char * fmt, ...) +void +LogError (char * fmt, ...) { char buf[1024]; - snprintf (buf, sizeof buf, "xdm error (pid %ld): ", (long)getpid()); + time_t seconds; + struct tm *timestamp = NULL; + char timebuf[256]; + + if (time(&seconds) > (time_t) -1) + timestamp = localtime(&seconds); + + strcpy(timebuf, "(time unavailable)"); + + if (timestamp != NULL) + strftime(timebuf, 255, "%c", timestamp); + + snprintf (buf, sizeof buf, "%s xdm error (pid %ld): ", timebuf, (long)getpid()); WRITES(STDERR_FILENO, buf); { va_list args; @@ -76,11 +107,24 @@ WRITES(STDERR_FILENO, buf); } -void LogPanic (char * fmt, ...) +void +LogPanic (char * fmt, ...) { char buf[1024]; - snprintf (buf, sizeof buf, "xdm panic (pid %ld): ", (long)getpid()); + time_t seconds; + struct tm *timestamp = NULL; + char timebuf[256]; + + if (time(&seconds) > (time_t) -1) + timestamp = localtime(&seconds); + + strcpy(timebuf, "(time unavailable)"); + + if (timestamp != NULL) + strftime(timebuf, 255, "%c", timestamp); + + snprintf (buf, sizeof buf, "%s xdm panic (pid %ld): ", timebuf, (long)getpid()); WRITES(STDERR_FILENO, buf); { va_list args; @@ -92,8 +136,14 @@ _exit (1); } -void LogOutOfMem (char * fmt, ...) +void +LogOutOfMem (char * fmt, ...) { + /* + * No point messing with allocation of timeval structs and static + * buffers for the timestamp string if we're already out of memory... + */ + fprintf (stderr, "xdm: out of memory in routine "); { va_list args; @@ -104,23 +154,12 @@ fflush (stderr); } -void Panic (char *mesg) -{ - int i; - - i = creat ("/dev/console", 0666); - write (i, "panic: ", 7); - write (i, mesg, strlen (mesg)); - exit (1); -} - - -void Debug (char * fmt, ...) +void +Debug (char * fmt, ...) { char buf[1024]; - if (debugLevel > 0) - { + if (debugLevel > 0) { va_list args; va_start(args, fmt); vsnprintf (buf, sizeof buf, fmt, args); @@ -129,17 +168,26 @@ } } -void InitErrorLog (void) +void +InitErrorLog (void) { - int i; - if (errorLogFile[0]) { - i = creat (errorLogFile, 0666); - if (i != -1) { - if (i != 2) { - dup2 (i, 2); - close (i); - } - } else - LogError ("Cannot open errorLogFile %s\n", errorLogFile); - } + int fd; + + if (errorLogFile[0]) { + /* create the log file if it doesn't already exist */ + fd = open (errorLogFile, O_WRONLY|O_CREAT|O_EXCL, 0666); + if (fd == -1) + if (errno == EEXIST) + /* log file already exists; append to it */ + fd = open (errorLogFile, O_WRONLY|O_APPEND); + if (fd != -1) { + /* redirect stderr to the log file */ + if (fd != 2) { + dup2 (fd, 2); + close (fd); + } + } else + fprintf (stderr, "cannot open log file %s: %s\n", errorLogFile, + _SysErrorMsg (errno)); + } } diff -urN xc/programs/xdm~/file.c xc/programs/xdm/file.c --- xc/programs/xdm~/file.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/file.c 2003-09-21 15:40:41.000000000 -0500 @@ -152,14 +152,14 @@ return; if (!args[0]) { - LogError ("Missing display name in servers file\n"); + LogError ("missing display name in servers file\n"); freeFileArgs (args); return; } name = args[0]; if (!args[1]) { - LogError ("Missing display type for %s\n", args[0]); + LogError ("missing display type for %s\n", args[0]); freeFileArgs (args); return; } @@ -192,7 +192,7 @@ } if (!numAcceptable) { - LogError ("Unacceptable display type %s for display %s\n", + LogError ("unacceptable display type %s for display %s\n", type, name); } d = FindDisplayByName (name); @@ -211,13 +211,13 @@ d->class = newclass; } } - Debug ("Found existing display: %s %s %s", d->name, d->class , type); + Debug ("found existing display: %s %s %s", d->name, d->class , type); freeFileArgs (d->argv); } else { d = NewDisplay (name, class); - Debug ("Found new display: %s %s %s", + Debug ("found new display: %s %s %s", d->name, d->class ? d->class : "", type); } d->displayType = displayType; diff -urN xc/programs/xdm~/genauth.c xc/programs/xdm/genauth.c --- xc/programs/xdm~/genauth.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/genauth.c 2003-09-21 15:41:15.000000000 -0500 @@ -33,14 +33,16 @@ * Author: Keith Packard, MIT X Consortium */ -# include <X11/Xauth.h> -# include <X11/Xos.h> +#include <X11/Xauth.h> +#include <X11/Xos.h> -# include "dm.h" -# include "dm_auth.h" -# include "dm_error.h" +#include "dm.h" +#include "dm_auth.h" +#include "dm_error.h" #include <errno.h> +#include <fcntl.h> +#include <string.h> #include <time.h> #define Time_t time_t @@ -55,12 +57,6 @@ #ifdef HASXDMAUTH -typedef unsigned char auth_cblock[8]; /* block size */ - -typedef struct auth_ks_struct { auth_cblock _; } auth_wrapper_schedule[16]; - -extern void _XdmcpWrapperToOddParity(); - static void longtochars (long l, unsigned char *c) { @@ -336,7 +332,7 @@ if ((offset = sumFile (randomFile, BSIZ, SEEK_SET, 0)) == BSIZ) return; } - LogError("Cannot read randomFile \"%s\"; X cookies may be easily guessable\n", randomFile); + LogError("cannot read randomFile \"%s\"; X cookies may be easily guessable\n", randomFile); } #endif /* !ARC4_RANDOM && !DEV_RANDOM */ @@ -369,7 +365,7 @@ close(fd); } } else { - LogError("Cannot open randomDevice \"%s\", errno = %d\n", + LogError("cannot open randomDevice \"%s\", errno = %d\n", randomDevice, errno); } #endif @@ -455,10 +451,10 @@ return 1; } close(fd); - LogError("Cannot read randomDevice \"%s\", errno=%d\n", + LogError("cannot read randomDevice \"%s\", errno=%d\n", randomDevice, errno); } else - LogError("Cannot open randomDevice \"%s\", errno = %d\n", + LogError("cannot open randomDevice \"%s\", errno = %d\n", randomDevice, errno); #endif /* DEV_RANDOM */ /* Try some pseudo-random number genrator daemon next */ diff -urN xc/programs/xdm~/greeter/Login.c xc/programs/xdm/greeter/Login.c --- xc/programs/xdm~/greeter/Login.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/greeter/Login.c 2003-09-21 15:40:41.000000000 -0500 @@ -863,7 +863,7 @@ xim = XOpenIM(XtDisplay(ctx), NULL, NULL, NULL); if (!xim) { - LogError("Failed to open input method\n"); + LogError("failed to open input method\n"); return; } @@ -873,7 +873,7 @@ XNFocusWindow, ctx->core.window, NULL); if (!ctx->login.xic) { - LogError("Failed to create input context\n"); + LogError("failed to create input context\n"); XCloseIM(xim); } return; @@ -1108,7 +1108,7 @@ if (0 != stat(w->login.logoFileName, &myBuffer)) { - LogError("Unable to stat() pixmap file %s\n", + LogError("unable to stat() pixmap file %s\n", w->login.logoFileName); w->login.logoValid = False; goto SkipXpmLoad; diff -urN xc/programs/xdm~/greeter/greet.c xc/programs/xdm/greeter/greet.c --- xc/programs/xdm~/greeter/greet.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/greeter/greet.c 2003-09-21 15:40:41.000000000 -0500 @@ -273,13 +273,13 @@ XtGetValues (login, arglist, 1); if (allow) { - Debug ("Disabling access control\n"); + Debug ("disabling access control\n"); XSetAccessControl (dpy, DisableAccess); } XtDestroyWidget (toplevel); ClearCloseOnFork (XConnectionNumber (dpy)); XCloseDisplay (dpy); - Debug ("Greet connection closed\n"); + Debug ("greet connection closed\n"); } #define WHITESPACE 0 @@ -308,7 +308,7 @@ } } XFlush (XtDisplay (toplevel)); - Debug ("Done dispatch %s\n", d->name); + Debug ("done dispatch %s\n", d->name); if (code == 0) { char *ptr; @@ -412,7 +412,7 @@ if (!d->grabServer) SetupDisplay (d); if (!*dpy) { - LogError ("Cannot reopen display %s for greet window\n", d->name); + LogError ("cannot reopen display %s for greet window\n", d->name); exit (RESERVER_DISPLAY); } #ifdef __OpenBSD__ @@ -438,13 +438,13 @@ } DeleteXloginResources (d, *dpy); CloseGreet (d); - Debug ("Greet loop finished\n"); + Debug ("greet loop finished\n"); /* * Run system-wide initialization file */ if (source (verify->systemEnviron, d->startup) != 0) { - Debug ("Startup program %s exited with non-zero status\n", + Debug ("startup program %s exited with non-zero status\n", d->startup); SessionExit (d, OBEYSESS_DISPLAY, FALSE); } diff -urN xc/programs/xdm~/greeter/verify.c xc/programs/xdm/greeter/verify.c --- xc/programs/xdm~/greeter/verify.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/greeter/verify.c 2003-09-21 15:40:41.000000000 -0500 @@ -196,29 +196,29 @@ endpwent(); if (!p || strlen (greet->name) == 0) { - Debug("getpwnam() failed.\n"); + Debug("getpwnam() failed\n"); bzero(greet->password, strlen(greet->password)); return 0; } if ((lc = login_getclass(p->pw_class)) == NULL) { - Debug("login_getclass() failed.\n"); + Debug("login_getclass() failed\n"); bzero(greet->password, strlen(greet->password)); return 0; } if ((style = login_getstyle(lc, style, "xdm")) == NULL) { - Debug("login_getstyle() failed.\n"); + Debug("login_getstyle() failed\n"); bzero(greet->password, strlen(greet->password)); return 0; } if ((as = auth_open()) == NULL) { - Debug("auth_open() failed.\n"); + Debug("auth_open() failed\n"); login_close(lc); bzero(greet->password, strlen(greet->password)); return 0; } if (auth_setoption(as, "login", "yes") == -1) { - Debug("auth_setoption() failed.\n"); + Debug("auth_setoption() failed\n"); login_close(lc); bzero(greet->password, strlen(greet->password)); return 0; @@ -331,7 +331,7 @@ (strncmp(console, "/dev/console", 12) == 0) && (strncmp(d->name,":0",2) != 0) ) { - Debug("Not on system console\n"); + Debug("not on system console\n"); bzero(greet->password, strlen(greet->password)); XFree(console); return 0; @@ -340,7 +340,7 @@ } else { - Debug("Could not open %s\n", SOLARIS_LOGIN_DEFAULTS); + Debug("could not open %s\n", SOLARIS_LOGIN_DEFAULTS); } } #endif @@ -350,13 +350,13 @@ endpwent(); if (!p || strlen (greet->name) == 0) { - Debug ("getpwnam() failed.\n"); + Debug ("getpwnam() failed\n"); bzero(greet->password, strlen(greet->password)); return 0; } else { #ifdef linux if (!strcmp(p->pw_passwd, "!") || !strcmp(p->pw_passwd, "*")) { - Debug ("The account is locked, no login allowed.\n"); + Debug ("the account is locked, no login allowed\n"); bzero(greet->password, strlen(greet->password)); return 0; } @@ -372,7 +372,7 @@ int ret; if(krb_get_lrealm(realm, 1)){ - Debug ("Can't get Kerberos realm.\n"); + Debug ("can't get Kerberos realm\n"); } else { sprintf(krbtkfile, "%s.%s", TKT_ROOT, d->name); @@ -391,7 +391,7 @@ greet->name); if((ret = k_afsklog(NULL, NULL)) != KSUCCESS) - LogError("Warning %s\n", + LogError("warning %s\n", krb_get_err_text(ret)); } goto done; @@ -408,7 +408,7 @@ errno = 0; sp = getspnam(greet->name); if (sp == NULL) { - Debug ("getspnam() failed, errno=%d. Are you root?\n", errno); + Debug ("getspnam() failed: %s", _SysErrorMsg (errno)); } else { user_pass = sp->sp_pwdp; } @@ -466,14 +466,14 @@ (void)gettimeofday(&tp, (struct timezone *)NULL); if (p->pw_change) { if (tp.tv_sec >= p->pw_change) { - Debug("Password has expired.\n"); + Debug("password has expired\n"); bzero(greet->password, strlen(greet->password)); return 0; } } if (p->pw_expire) { if (tp.tv_sec >= p->pw_expire) { - Debug("account has expired.\n"); + Debug("account has expired\n"); bzero(greet->password, strlen(greet->password)); return 0; } @@ -503,7 +503,7 @@ endpwent(); if (!p || strlen (greet->name) == 0) { - Debug ("getpwnam() failed.\n"); + Debug ("getpwnam() failed\n"); bzero(greet->password, strlen(greet->password)); return 0; } diff -urN xc/programs/xdm~/resource.c xc/programs/xdm/resource.c --- xc/programs/xdm~/resource.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/resource.c 2003-09-21 15:41:15.000000000 -0500 @@ -35,11 +35,11 @@ * resource.c */ -# include "dm.h" -# include "dm_error.h" +#include "dm.h" +#include "dm_error.h" -# include <X11/Intrinsic.h> -# include <X11/Xmu/CharSet.h> +#include <X11/Intrinsic.h> +#include <X11/Xmu/CharSet.h> char *config; @@ -72,134 +72,133 @@ char *willing; int choiceTimeout; /* chooser choice timeout */ -# define DM_STRING 0 -# define DM_INT 1 -# define DM_BOOL 2 -# define DM_ARGV 3 +#define DM_STRING 0 +#define DM_INT 1 +#define DM_BOOL 2 +#define DM_ARGV 3 /* * the following constants are supposed to be set in the makefile from * parameters set util/imake.includes/site.def (or *.macros in that directory * if it is server-specific). DO NOT CHANGE THESE DEFINITIONS! */ -#ifndef __EMX__ -#ifndef DEF_SERVER_LINE -#define DEF_SERVER_LINE ":0 local /usr/bin/X11/X :0" -#endif -#ifndef XRDB_PROGRAM -#define XRDB_PROGRAM "/usr/bin/X11/xrdb" -#endif -#ifndef DEF_SESSION -#define DEF_SESSION "/usr/bin/X11/xterm -ls" -#endif -#ifndef DEF_USER_PATH -#define DEF_USER_PATH ":/bin:/usr/bin:/usr/bin/X11:/usr/ucb" -#endif -#ifndef DEF_SYSTEM_PATH -#define DEF_SYSTEM_PATH "/etc:/bin:/usr/bin:/usr/bin/X11:/usr/ucb" -#endif -#ifndef DEF_SYSTEM_SHELL -#define DEF_SYSTEM_SHELL "/bin/sh" -#endif -#ifndef DEF_FAILSAFE_CLIENT -#define DEF_FAILSAFE_CLIENT "/usr/bin/X11/xterm" -#endif -#ifndef DEF_XDM_CONFIG -#define DEF_XDM_CONFIG "/usr/lib/X11/xdm/xdm-config" -#endif -#ifndef DEF_CHOOSER -#define DEF_CHOOSER "/usr/lib/X11/xdm/chooser" -#endif -#ifndef DEF_AUTH_NAME -#ifdef HASXDMAUTH -#define DEF_AUTH_NAME "XDM-AUTHORIZATION-1 MIT-MAGIC-COOKIE-1" -#else -#define DEF_AUTH_NAME "MIT-MAGIC-COOKIE-1" -#endif -#endif -#ifndef DEF_AUTH_DIR -#define DEF_AUTH_DIR "/usr/lib/X11/xdm" -#endif -#ifndef DEF_USER_AUTH_DIR -#define DEF_USER_AUTH_DIR "/tmp" -#endif -#ifndef DEF_KEY_FILE -#define DEF_KEY_FILE "" -#endif -#ifndef DEF_ACCESS_FILE -#define DEF_ACCESS_FILE "" -#endif -#ifndef DEF_RANDOM_FILE -#define DEF_RANDOM_FILE "/dev/mem" -#endif -#ifndef DEF_PRNGD_SOCKET -#define DEF_PRNGD_SOCKET "/tmp/entropy" -#endif -#ifndef DEF_PRNGD_PORT -#define DEF_PRNGD_PORT "0" -#endif -#ifndef DEF_GREETER_LIB -#define DEF_GREETER_LIB "/usr/lib/X11/xdm/libXdmGreet.so" -#endif +#ifndef __UNIXOS2__ +# ifndef DEF_SERVER_LINE +# define DEF_SERVER_LINE ":0 local /usr/bin/X11/X :0" +# endif +# ifndef XRDB_PROGRAM +# define XRDB_PROGRAM "/usr/bin/X11/xrdb" +# endif +# ifndef DEF_SESSION +# define DEF_SESSION "/usr/bin/X11/xterm -ls" +# endif +# ifndef DEF_USER_PATH +# define DEF_USER_PATH ":/bin:/usr/bin:/usr/bin/X11:/usr/ucb" +# endif +# ifndef DEF_SYSTEM_PATH +# define DEF_SYSTEM_PATH "/etc:/bin:/usr/bin:/usr/bin/X11:/usr/ucb" +# endif +# ifndef DEF_SYSTEM_SHELL +# define DEF_SYSTEM_SHELL "/bin/sh" +# endif +# ifndef DEF_FAILSAFE_CLIENT +# define DEF_FAILSAFE_CLIENT "/usr/bin/X11/xterm" +# endif +# ifndef DEF_XDM_CONFIG +# define DEF_XDM_CONFIG "/usr/lib/X11/xdm/xdm-config" +# endif +# ifndef DEF_CHOOSER +# define DEF_CHOOSER "/usr/lib/X11/xdm/chooser" +# endif +# ifndef DEF_AUTH_NAME +# ifdef HASXDMAUTH +# define DEF_AUTH_NAME "XDM-AUTHORIZATION-1 MIT-MAGIC-COOKIE-1" +# else +# define DEF_AUTH_NAME "MIT-MAGIC-COOKIE-1" +# endif +# endif +# ifndef DEF_AUTH_DIR +# define DEF_AUTH_DIR "/usr/lib/X11/xdm" +# endif +# ifndef DEF_USER_AUTH_DIR +# define DEF_USER_AUTH_DIR "/tmp" +# endif +# ifndef DEF_KEY_FILE +# define DEF_KEY_FILE "" +# endif +# ifndef DEF_ACCESS_FILE +# define DEF_ACCESS_FILE "" +# endif +# ifndef DEF_RANDOM_FILE +# define DEF_RANDOM_FILE "/dev/mem" +# endif +# ifndef DEF_PRNGD_SOCKET +# define DEF_PRNGD_SOCKET "/tmp/entropy" +# endif +# ifndef DEF_PRNGD_PORT +# define DEF_PRNGD_PORT "0" +# endif +# ifndef DEF_GREETER_LIB +# define DEF_GREETER_LIB "/usr/lib/X11/xdm/libXdmGreet.so" +# endif #else /* unfortunately I have to declare all of them, because there is a limit * in argument size in OS/2 * but everything needs to be fixed again */ -#define DEF_SERVER_LINE ":0 local /XFree86/bin/X :0" -#ifndef XRDB_PROGRAM -#define XRDB_PROGRAM "/XFree86/bin/xrdb" -#endif -#ifndef DEF_SESSION -#define DEF_SESSION "/XFree86/bin/xterm -ls" -#endif -#ifndef DEF_USER_PATH -#define DEF_USER_PATH "c:\\os2;c:\\os2\apps;\\XFree86\\bin" -#endif -#ifndef DEF_SYSTEM_PATH -#define DEF_SYSTEM_PATH "c:\\os2;c:\\os2\apps;\\XFree86\\bin" -#endif -#ifndef DEF_SYSTEM_SHELL -#define DEF_SYSTEM_SHELL "sh" -#endif -#ifndef DEF_FAILSAFE_CLIENT -#define DEF_FAILSAFE_CLIENT "/XFree86/bin/xterm" -#endif -#ifndef DEF_XDM_CONFIG -#define DEF_XDM_CONFIG "/XFree86/lib/X11/xdm/xdm-config" -#endif -#ifndef DEF_CHOOSER -#define DEF_CHOOSER "/XFree86/lib/X11/xdm/chooser" -#endif -#ifndef DEF_AUTH_NAME -#ifdef HASXDMAUTH -#define DEF_AUTH_NAME "XDM-AUTHORIZATION-1 MIT-MAGIC-COOKIE-1" -#else -#define DEF_AUTH_NAME "MIT-MAGIC-COOKIE-1" -#endif -#endif -#ifndef DEF_AUTH_DIR -#define DEF_AUTH_DIR "/XFree86/lib/X11/xdm" -#endif -#ifndef DEF_USER_AUTH_DIR -#define DEF_USER_AUTH_DIR "/tmp" -#endif -#ifndef DEF_KEY_FILE -#define DEF_KEY_FILE "" -#endif -#ifndef DEF_ACCESS_FILE -#define DEF_ACCESS_FILE "" -#endif -#ifndef DEF_RANDOM_FILE -#define DEF_RANDOM_FILE "" -#endif -#ifndef DEF_GREETER_LIB -#define DEF_GREETER_LIB "/XFree86/lib/X11/xdm/libXdmGreet.so" -#endif - -#endif /* __EMX__ */ +# define DEF_SERVER_LINE ":0 local /XFree86/bin/X :0" +# ifndef XRDB_PROGRAM +# define XRDB_PROGRAM "/XFree86/bin/xrdb" +# endif +# ifndef DEF_SESSION +# define DEF_SESSION "/XFree86/bin/xterm -ls" +# endif +# ifndef DEF_USER_PATH +# define DEF_USER_PATH "c:\\os2;c:\\os2\apps;\\XFree86\\bin" +# endif +# ifndef DEF_SYSTEM_PATH +# define DEF_SYSTEM_PATH "c:\\os2;c:\\os2\apps;\\XFree86\\bin" +# endif +# ifndef DEF_SYSTEM_SHELL +# define DEF_SYSTEM_SHELL "sh" +# endif +# ifndef DEF_FAILSAFE_CLIENT +# define DEF_FAILSAFE_CLIENT "/XFree86/bin/xterm" +# endif +# ifndef DEF_XDM_CONFIG +# define DEF_XDM_CONFIG "/XFree86/lib/X11/xdm/xdm-config" +# endif +# ifndef DEF_CHOOSER +# define DEF_CHOOSER "/XFree86/lib/X11/xdm/chooser" +# endif +# ifndef DEF_AUTH_NAME +# ifdef HASXDMAUTH +# define DEF_AUTH_NAME "XDM-AUTHORIZATION-1 MIT-MAGIC-COOKIE-1" +# else +# define DEF_AUTH_NAME "MIT-MAGIC-COOKIE-1" +# endif +# endif +# ifndef DEF_AUTH_DIR +# define DEF_AUTH_DIR "/XFree86/lib/X11/xdm" +# endif +# ifndef DEF_USER_AUTH_DIR +# define DEF_USER_AUTH_DIR "/tmp" +# endif +# ifndef DEF_KEY_FILE +# define DEF_KEY_FILE "" +# endif +# ifndef DEF_ACCESS_FILE +# define DEF_ACCESS_FILE "" +# endif +# ifndef DEF_RANDOM_FILE +# define DEF_RANDOM_FILE "" +# endif +# ifndef DEF_GREETER_LIB +# define DEF_GREETER_LIB "/XFree86/lib/X11/xdm/libXdmGreet.so" +# endif +#endif /* __UNIXOS2__ */ -#define DEF_UDP_PORT "177" /* registered XDMCP port, dont change */ +#define DEF_UDP_PORT "177" /* registered XDMCP port, do not change */ struct dmResources { char *name, *class; @@ -236,7 +235,7 @@ #if !defined(ARC4_RANDOM) { "randomFile", "RandomFile", DM_STRING, &randomFile, DEF_RANDOM_FILE} , -{ "prgndSocket", "PrngdSocket", DM_STRING, &prngdSocket, +{ "prgndSocket", "PrngdSocket", DM_STRING, &prngdSocket, DEF_PRNGD_SOCKET}, { "prngdPort", "PrngdPort", DM_INT, (char **) &prngdPort, DEF_PRNGD_PORT}, @@ -255,9 +254,9 @@ ""} , }; -# define NUM_DM_RESOURCES (sizeof DmResources / sizeof DmResources[0]) +#define NUM_DM_RESOURCES (sizeof DmResources / sizeof DmResources[0]) -# define boffset(f) XtOffsetOf(struct display, f) +#define boffset(f) XtOffsetOf(struct display, f) struct displayResource { char *name, *class; @@ -305,7 +304,7 @@ "" }, }; -# define NUM_SERVER_RESOURCES (sizeof serverResources/\ +#define NUM_SERVER_RESOURCES (sizeof serverResources /\ sizeof serverResources[0]) /* resources which control the session behaviour */ @@ -337,7 +336,7 @@ DEF_CHOOSER }, }; -# define NUM_SESSION_RESOURCES (sizeof sessionResources/\ +#define NUM_SESSION_RESOURCES (sizeof sessionResources /\ sizeof sessionResources[0]) XrmDatabase DmResourceDB; @@ -481,7 +480,7 @@ DmResourceDB = newDB; } else if (argc != originalArgc) - LogError ("Can't open configuration file %s\n", config ); + LogError ("can't open configuration file %s\n", config ); XrmParseCommand (&DmResourceDB, optionTable, sizeof (optionTable) / sizeof (optionTable[0]), "DisplayManager", &argc, argv); @@ -543,7 +542,7 @@ CleanUpName (d->name, dpyName, sizeof (dpyName)); CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass)); for (i = 0; i < numResources; i++) { - snprintf (name, sizeof(name), "DisplayManager.%s.%s", + snprintf (name, sizeof(name), "DisplayManager.%s.%s", dpyName, resources[i].name); snprintf (class, sizeof(class), "DisplayManager.%s.%s", dpyClass, resources[i].class); diff -urN xc/programs/xdm~/rpcauth.c xc/programs/xdm/rpcauth.c --- xc/programs/xdm~/rpcauth.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/rpcauth.c 2003-09-21 15:40:41.000000000 -0500 @@ -69,7 +69,7 @@ new->number = 0; getnetname (key); - Debug ("System netname %s\n", key); + Debug ("system netname %s\n", key); new->data_length = strlen(key); new->data = (char *) malloc (new->data_length); if (!new->data) diff -urN xc/programs/xdm~/server.c xc/programs/xdm/server.c --- xc/programs/xdm~/server.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/server.c 2003-09-21 15:40:41.000000000 -0500 @@ -80,7 +80,7 @@ char arg[1024]; int pid; - Debug ("StartServer for %s\n", d->name); + Debug ("StartServerOnce for %s\n", d->name); receivedUsr1 = 0; (void) Signal (SIGUSR1, CatchUsr1); argv = d->argv; @@ -120,7 +120,7 @@ default: break; } - Debug ("Server Started %d\n", pid); + Debug ("server started (pid %d)\n", pid); d->serverPid = pid; if (serverPause ((unsigned) d->openDelay, pid)) return FALSE; @@ -186,7 +186,7 @@ if (!receivedUsr1) (void) alarm (t); else - Debug ("Already received USR1\n"); + Debug ("already received USR1\n"); #endif for (;;) { #if defined(SYSV) && defined(X_NOT_POSIX) @@ -217,13 +217,13 @@ if (pid == serverPid || (pid == -1 && errno == ECHILD)) { - Debug ("Server dead\n"); + Debug ("server dead\n"); serverPauseRet = 1; break; } #if !defined(SYSV) || !defined(X_NOT_POSIX) if (pid == 0) { - Debug ("Server alive and kicking\n"); + Debug ("server alive and kicking\n"); break; } #endif @@ -233,7 +233,7 @@ (void) Signal (SIGALRM, SIG_DFL); (void) Signal (SIGUSR1, CatchUsr1); if (serverPauseRet) { - Debug ("Server died\n"); + Debug ("server died\n"); LogError ("server unexpectedly died\n"); } return serverPauseRet; @@ -293,7 +293,7 @@ d->peerlen = len; } } - Debug ("Got remote address %s %d\n", d->name, d->peerlen); + Debug ("got remote address %s %d\n", d->name, d->peerlen); } #endif /* XDMCP */ @@ -316,7 +316,7 @@ (void) Signal (SIGALRM, abortOpen); (void) alarm ((unsigned) d->openTimeout); if (!Setjmp (openAbort)) { - Debug ("Before XOpenDisplay(%s)\n", d->name); + Debug ("before XOpenDisplay(%s)\n", d->name); errno = 0; (void) XSetIOErrorHandler (openErrorHandler); dpy = XOpenDisplay (d->name); @@ -334,7 +334,7 @@ (void) alarm ((unsigned) 0); (void) Signal (SIGALRM, SIG_DFL); (void) XSetIOErrorHandler ((int (*)(Display *)) 0); - Debug ("After XOpenDisplay(%s)\n", d->name); + Debug ("after XOpenDisplay(%s)\n", d->name); if (dpy) { #ifdef XDMCP if (d->displayType.location == Foreign) @@ -351,7 +351,7 @@ sleep ((unsigned) d->openDelay); } else { Debug ("hung in open, aborting\n"); - LogError ("Hung in XOpenDisplay(%s), aborting\n", d->name); + LogError ("hung in XOpenDisplay(%s), aborting\n", d->name); (void) Signal (SIGALRM, SIG_DFL); break; } @@ -406,12 +406,12 @@ (void) alarm (d->pingTimeout * 60); if (!Setjmp (pingTime)) { - Debug ("Ping server\n"); + Debug ("ping server\n"); XSync (aDpy, 0); } else { - Debug ("Server dead\n"); + Debug ("server dead\n"); (void) alarm (0); (void) Signal (SIGALRM, SIG_DFL); XSetIOErrorHandler (oldError); @@ -420,7 +420,7 @@ (void) alarm (0); (void) Signal (SIGALRM, oldSig); (void) alarm (oldAlarm); - Debug ("Server alive\n"); + Debug ("server alive\n"); XSetIOErrorHandler (oldError); return 1; } diff -urN xc/programs/xdm~/session.c xc/programs/xdm/session.c --- xc/programs/xdm~/session.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/session.c 2003-09-21 15:40:41.000000000 -0500 @@ -61,17 +61,17 @@ #endif #ifndef GREET_USER_STATIC -#include <dlfcn.h> -#ifndef RTLD_NOW -#define RTLD_NOW 1 -#endif +# include <dlfcn.h> +# ifndef RTLD_NOW +# define RTLD_NOW 1 +# endif #endif static int runAndWait (char **args, char **environ); -#if defined(CSRG_BASED) || defined(__osf__) || defined(__DARWIN__) || defined(__QNXNTO__) || defined(sun) -#include <sys/types.h> -#include <grp.h> +#if defined(CSRG_BASED) || defined(__osf__) || defined(__DARWIN__) || defined(__QNXNTO__) || defined(sun) || defined(__GLIBC__) +# include <sys/types.h> +# include <grp.h> #else /* should be in <grp.h> */ extern void setgrent(void); @@ -87,28 +87,34 @@ extern void endspent(void); #endif #endif -#if defined(CSRG_BASED) -#include <pwd.h> -#include <unistd.h> + +#if defined(CSRG_BASED) || defined(__GLIBC__) +# include <pwd.h> +# include <unistd.h> #else extern struct passwd *getpwnam(GETPWNAM_ARGS); -#ifdef linux +# ifdef linux extern void endpwent(void); -#endif +# endif +# ifndef __GLIBC__ extern char *crypt(CRYPT_ARGS); +# endif #endif + #ifdef USE_PAM -pam_handle_t **thepamhp() +pam_handle_t ** +thepamhp () { static pam_handle_t *pamh = NULL; return &pamh; } -pam_handle_t *thepamh() +pam_handle_t * +thepamh () { pam_handle_t **pamhp; - pamhp = thepamhp(); + pamhp = thepamhp (); if (pamhp) return *pamhp; else @@ -141,12 +147,12 @@ endgrent, #ifdef USESHADOW getspnam, -#ifndef QNX4 +# ifndef QNX4 endspent, -#endif /* QNX4 doesn't use endspent */ +# endif /* QNX4 doesn't use endspent */ #endif getpwnam, -#ifdef linux +#if defined(linux) || defined(__GLIBC__) endpwent, #endif crypt, @@ -194,7 +200,7 @@ } #if defined(_POSIX_SOURCE) || defined(SYSV) || defined(SVR4) -#define killpg(pgrp, sig) kill(-(pgrp), sig) +# define killpg(pgrp, sig) kill(-(pgrp), sig) #endif static void @@ -321,7 +327,7 @@ * setting up environment and running the session */ if (StartClient (&verify, d, &clientPid, greet.name, greet.password)) { - Debug ("Client Started\n"); + Debug ("client started\n"); #ifndef GREET_USER_STATIC /* Save memory; close library */ @@ -369,7 +375,7 @@ /* * run system-wide reset file */ - Debug ("Source reset program %s\n", d->reset); + Debug ("source reset program %s\n", d->reset); source (verify.systemEnviron, d->reset); SessionExit (d, OBEYSESS_DISPLAY, TRUE); } @@ -384,7 +390,7 @@ env = systemEnv (d, (char *) 0, (char *) 0); args = parseArgs ((char **) 0, d->xrdb); args = parseArgs (args, d->resources); - Debug ("Loading resource file: %s\n", d->resources); + Debug ("loading resource file: %s\n", d->resources); (void) runAndWait (args, env); freeArgs (args); freeEnv (env); @@ -438,7 +444,7 @@ SessionExit (d, RESERVER_DISPLAY, FALSE); } (void) alarm ((unsigned) d->grabTimeout); - Debug ("Before XGrabServer %s\n", d->name); + Debug ("before XGrabServer %s\n", d->name); XGrabServer (dpy); if (XGrabKeyboard (dpy, DefaultRootWindow (dpy), True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess) @@ -511,7 +517,7 @@ code = krb5_cc_destroy(ccache); if (code) { if (code == KRB5_FCC_NOFILE) { - Debug ("No Kerberos ccache file found to destroy\n"); + Debug ("no Kerberos ccache file found to destroy\n"); } else LogError("%s while destroying Krb5 credentials cache\n", error_message(code)); @@ -522,7 +528,7 @@ } #endif /* K5AUTH */ } - Debug ("Display %s exiting with status %d\n", d->name, status); + Debug ("display %s exiting with status %d\n", d->name, status); exit (status); } @@ -582,39 +588,37 @@ #ifndef AIXV3 #ifndef HAS_SETUSERCONTEXT - if (setgid(verify->gid) < 0) - { - LogError("setgid %d (user \"%s\") failed, errno=%d\n", - verify->gid, name, errno); + if (setgid(verify->gid) < 0) { + LogError("setgid %d (user \"%s\") failed: %s\n", + verify->gid, name, _SysErrorMsg (errno)); return (0); } #if defined(BSD) && (BSD >= 199103) - if (setlogin(name) < 0) - { - LogError("setlogin for \"%s\" failed, errno=%d", name, errno); + if (setlogin(name) < 0) { + LogError("setlogin for \"%s\" failed: %s\n", name, + _SysErrorMsg (errno)); return(0); } #endif #ifndef QNX4 - if (initgroups(name, verify->gid) < 0) - { - LogError("initgroups for \"%s\" failed, errno=%d\n", name, errno); + if (initgroups(name, verify->gid) < 0) { + LogError("initgroups for \"%s\" failed: %s\n", name, + _SysErrorMsg (errno)); return (0); } #endif /* QNX4 doesn't support multi-groups, no initgroups() */ #ifdef USE_PAM if (thepamh()) { if (pam_setcred(thepamh(), PAM_ESTABLISH_CRED) != PAM_SUCCESS) { - LogError("pam_setcred for %\"s failed, errno=%d\n", - name, errno); + LogError("pam_setcred for \"%s\" failed: %s\n", name, + _SysErrorMsg (errno)); return(0); } } #endif - if (setuid(verify->uid) < 0) - { - LogError("setuid %d (user \"%s\") failed, errno=%d\n", - verify->uid, name, errno); + if (setuid(verify->uid) < 0) { + LogError("setuid %d (user \"%s\") failed: %s\n", + verify->uid, name, _SysErrorMsg (errno)); return (0); } #else /* HAS_SETUSERCONTEXT */ @@ -622,20 +626,17 @@ * Set the user's credentials: uid, gid, groups, * environment variables, resource limits, and umask. */ - pwd = getpwnam(name); - if (pwd) - { - if (setusercontext(NULL, pwd, pwd->pw_uid, LOGIN_SETALL) < 0) - { - LogError("setusercontext for \"%s\" failed, errno=%d\n", name, - errno); + pwd = getpwnam (name); + if (pwd) { + if (setusercontext (NULL, pwd, pwd->pw_uid, LOGIN_SETALL) < 0) { + LogError ("setusercontext for \"%s\" failed: %s\n", name, + _SysErrorMsg (errno)); return (0); } - endpwent(); - } - else - { - LogError("getpwnam for \"%s\" failed, errno=%d\n", name, errno); + endpwent (); + } else { + LogError ("getpwnam for \"%s\" failed: %s\n", name, + _SysErrorMsg (errno)); return (0); } #endif /* HAS_SETUSERCONTEXT */ @@ -644,9 +645,9 @@ * Set the user's credentials: uid, gid, groups, * audit classes, user limits, and umask. */ - if (setpcred(name, NULL) == -1) - { - LogError("setpcred for \"%s\" failed, errno=%d\n", name, errno); + if (setpcred (name, NULL) == -1) { + LogError ("setpcred for \"%s\" failed: %s\n", name, + _SysErrorMsg (errno)); return (0); } #endif /* AIXV3 */ @@ -665,7 +666,7 @@ int key_set_ok = 0; nameret = getnetname (netname); - Debug ("User netname: %s\n", netname); + Debug ("user netname: %s\n", netname); len = strlen (passwd); if (len > 8) bzero (passwd + 8, len - 8); @@ -676,7 +677,7 @@ netst.st_netname = strdup(netname); memset(netst.st_pub_key, 0, HEXKEYBYTES); if (key_setnet(&netst) < 0) { - Debug("Could not set secret key.\n"); + Debug("could not set secret key\n"); } free(netst.st_netname); /* is there a key, and do we have the right password? */ @@ -759,22 +760,22 @@ if (verify->argv) { Debug ("executing session %s\n", verify->argv[0]); execute (verify->argv, verify->userEnviron); - LogError ("Session \"%s\" execution failed (err %d)\n", verify->argv[0], errno); + LogError ("session \"%s\" execution failed (err %d)\n", verify->argv[0], errno); } else { - LogError ("Session has no command/arguments\n"); + LogError ("session has no command/arguments\n"); } failsafeArgv[0] = d->failsafeClient; failsafeArgv[1] = 0; execute (failsafeArgv, verify->userEnviron); exit (1); case -1: - bzero(passwd, strlen(passwd)); + bzero (passwd, strlen (passwd)); Debug ("StartSession, fork failed\n"); - LogError ("can't start session on \"%s\", fork failed, errno=%d\n", - d->name, errno); + LogError ("can't start session on \"%s\", fork failed: %s\n", + d->name, _SysErrorMsg (errno)); return 0; default: - bzero(passwd, strlen(passwd)); + bzero (passwd, strlen (passwd)); Debug ("StartSession, fork succeeded %d\n", pid); *pidp = pid; return 1; @@ -885,7 +886,7 @@ p = "/bin/sh"; optarg = 0; } - Debug ("Shell script execution: %s (optarg %s)\n", + Debug ("shell script execution: %s (optarg %s)\n", p, optarg ? optarg : "(null)"); for (av = argv, argc = 0; *av; av++, argc++) /* SUPPRESS 530 */ @@ -941,9 +942,10 @@ return env; } -#if (defined(Lynx) && !defined(HAS_CRYPT)) || defined(SCO) && !defined(SCO_USA) && !defined(_SCO_DS) -char *crypt(char *s1, char *s2) +#if (defined(Lynx) && !defined(HAS_CRYPT)) || (defined(SCO) && !defined(SCO_USA) && !defined(_SCO_DS)) +char * +crypt (char *s1, char *s2) { - return(s2); + return (s2); } #endif diff -urN xc/programs/xdm~/socket.c xc/programs/xdm/socket.c --- xc/programs/xdm~/socket.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/socket.c 2003-09-21 15:40:41.000000000 -0500 @@ -67,10 +67,10 @@ registerHostname (name, strlen (name)); chooserFd = socket (AF_INET, SOCK_STREAM, 0); - Debug ("Created chooser socket %d\n", chooserFd); + Debug ("created chooser socket %d\n", chooserFd); if (chooserFd == -1) { - LogError ("chooser socket creation failed, errno %d\n", errno); + LogError ("chooser socket creation failed: %s\n", _SysErrorMsg (errno)); return; } listen (chooserFd, 5); @@ -93,7 +93,7 @@ return -1; /* TODO check other listening sockets */ if (getsockname (chooserFd, (struct sockaddr *)&in_addr, (void *)&len) < 0) return -1; - Debug ("Chooser socket port: %d\n", + Debug ("chooser socket port: %d\n", ntohs(((struct sockaddr_in *) &in_addr)->sin_port)); if (*lenp < len) retval = -2; @@ -123,14 +123,15 @@ fd = socket (sock_addr->sa_family, SOCK_DGRAM, 0); if (fd == -1) { - LogError ("XDMCP socket creation failed, errno %d\n", errno); + LogError ("XDMCP socket creation failed: %s\n", _SysErrorMsg (errno)); return fd; } RegisterCloseOnFork (fd); if (bind (fd, sock_addr, salen) == -1) { - LogError ("error %d binding socket address %d\n", errno, request_port); + LogError ("error binding socket address %d: %s\n", request_port, + _SysErrorMsg (errno)); close (fd); fd = -1; return fd; diff -urN xc/programs/xdm~/streams.c xc/programs/xdm/streams.c --- xc/programs/xdm~/streams.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/streams.c 2003-09-21 15:40:41.000000000 -0500 @@ -107,7 +107,7 @@ FD_SET (xdmcpFd, &WellKnownSocketsMask); chooserFd = t_open ("/dev/tcp", O_RDWR, NULL); - Debug ("Created chooser fd %d\n", chooserFd); + Debug ("created chooser fd %d\n", chooserFd); if (chooserFd == -1) { LogError ("chooser stream creation failed\n"); diff -urN xc/programs/xdm~/util.c xc/programs/xdm/util.c --- xc/programs/xdm~/util.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/util.c 2003-09-21 15:40:41.000000000 -0500 @@ -55,7 +55,7 @@ #undef _POSIX_SOURCE #endif #endif -#if defined(__osf__) || defined(linux) || defined(__QNXNTO__) || defined(__GNU__) +#if defined(__osf__) || defined(linux) || defined(__QNXNTO__) || defined(__GNU__) || defined(__GLIBC__) #define setpgrp setpgid #endif diff -urN xc/programs/xdm~/xdm.man xc/programs/xdm/xdm.man --- xc/programs/xdm~/xdm.man 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/xdm.man 2003-09-21 15:41:15.000000000 -0500 @@ -151,8 +151,9 @@ At the end of the session, the \fIXreset\fP script is run to clean up, the X server is reset, and the cycle starts over. .PP -The file \fI __projectroot__/lib/X11/xdm/xdm-errors\fP will contain error -messages from +The file +.I __projectroot__/lib/X11/xdm/xdm-errors +will contain error messages from .I xdm and anything output to stderr by \fIXsetup, Xstartup, Xsession\fP or \fIXreset\fP. @@ -312,7 +313,8 @@ This names a directory under which .I xdm stores authorization files while initializing the session. The -default value is \fI __projectroot__/lib/X11/xdm.\fP +default value is +.IR __projectroot__/lib/X11/xdm . Can be overridden for specific displays by DisplayManager.\fIDISPLAY\fP.authFile. .IP \fBDisplayManager.autoRescan\fP @@ -359,9 +361,11 @@ #ifdef DEV_RANDOM .IP \fBDisplayManager.randomDevice\fP A file to read 8 bytes from to generate the seed of authorization keys. -The default is \fI DEV_RANDOM \fP. If this file cannot be read, or if a -read blocks for more than 5 seconds, xdm falls back to using a checksum -of \fBDisplayManager.randomFile\fP to generate the seed. +The default is +.IR DEV_RANDOM . +If this file cannot be read, or if a read blocks for more than 5 seconds, +xdm falls back to using a checksum of \fBDisplayManager.randomFile\fP to +generate the seed. #endif #if !defined(ARC4_RANDOM) .IP \fBDisplayManager.prngdSocket\fP @@ -380,7 +384,7 @@ .IP \fBDisplayManager.greeterLib\fP On systems that support a dynamically-loadable greeter library, the name of the library. The default is -\fI __projectroot__/lib/X11/xdm/libXdmGreet.so\fP. +.IR __projectroot__/lib/X11/xdm/libXdmGreet.so . .IP \fBDisplayManager.choiceTimeout\fP Number of seconds to wait for display to respond after user has selected a host from the chooser. If the display sends an XDMCP @@ -412,17 +416,19 @@ which describes the various resources that are appropriate to place in this file. There is no default value for this resource, but -\fI __projectroot__/lib/X11/xdm/Xresources\fP +.I __projectroot__/lib/X11/xdm/Xresources is the conventional name. .IP "\fBDisplayManager.\fP\fIDISPLAY\fP\fB.chooser\fP" Specifies the program run to offer a host menu for Indirect queries redirected to the special host name CHOOSER. -\fI __projectroot__/lib/X11/xdm/chooser\fP is the default. -See the sections \fBXDMCP Access Control\fP and \fBChooser\fP. +.I __projectroot__/lib/X11/xdm/chooser +is the default. See the sections \fBXDMCP Access Control\fP and +\fBChooser\fP. .IP "\fBDisplayManager.\fP\fIDISPLAY\fP\fB.xrdb\fP" Specifies the program used to load the resources. By default, .I xdm -uses \fI __projectroot__/bin/xrdb\fP. +uses +.IR __projectroot__/bin/xrdb . .IP "\fBDisplayManager.\fP\fIDISPLAY\fP\fB.cpp\fP" This specifies the name of the C preprocessor which is used by \fIxrdb\fP. .IP "\fBDisplayManager.\fP\fIDISPLAY\fP\fB.setup\fP" @@ -440,8 +446,9 @@ See the section \fBStartup Program.\fP .IP "\fBDisplayManager.\fP\fIDISPLAY\fP\fB.session\fP" This specifies the session to be executed (not running as root). -By default, \fI __projectroot__/bin/xterm\fP is -run. The conventional name is \fIXsession\fP. +By default, +.I __projectroot__/bin/xterm\fP +is run. The conventional name is \fIXsession\fP. See the section .B "Session Program." .IP "\fBDisplayManager.\fP\fIDISPLAY\fP\fB.reset\fP" @@ -526,7 +533,9 @@ will fall back to this program. This program is executed with no arguments, but executes using the same environment variables as the session would have had (see the section \fBSession Program\fP). -By default, \fI __projectroot__/bin/xterm\fP is used. +By default, +.I __projectroot__/bin/xterm +is used. .IP "\fBDisplayManager.\fP\fIDISPLAY\fP\fB.grabServer\fP" .IP "\fBDisplayManager.\fP\fIDISPLAY\fP\fB.grabTimeout\fP" To improve security, @@ -605,8 +614,9 @@ First, the .I xdm configuration file should be set up. -Make a directory (usually \fI __projectroot__/lib/X11/xdm\fP) to contain all -of the relevant files. +Make a directory (usually +.IR __projectroot__/lib/X11/xdm ) +to contain all of the relevant files. .LP Here is a reasonable configuration file, which could be named \fIxdm-config\fP: diff -urN xc/programs/xdm~/xdmauth.c xc/programs/xdm/xdmauth.c --- xc/programs/xdm~/xdmauth.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/xdmauth.c 2003-09-21 15:40:41.000000000 -0500 @@ -45,11 +45,20 @@ static char auth_name[256]; static int auth_name_len; -void -XdmPrintDataHex (s, a, l) - char *s; - char *a; - int l; +static void XdmPrintDataHex (char *s, char *a, int l); +# ifdef XDMCP +static void XdmPrintArray8Hex (char *s, ARRAY8Ptr a); +# endif +static Xauth *XdmGetAuthHelper (unsigned short namelen, + char *name, + int includeRho); +# ifdef XDMCP +static int HexToBinary (char *key); +static int XdmGetKey (struct protoDisplay *pdpy, ARRAY8Ptr displayID); +# endif + +static void +XdmPrintDataHex (char *s, char *a, int l) { int i; @@ -59,7 +68,7 @@ Debug ("\n"); } -#ifdef notdef /* not used */ +#if 0 /* not used */ void XdmPrintKey (s, k) char *s; @@ -69,20 +78,16 @@ } #endif -#ifdef XDMCP -void -XdmPrintArray8Hex (s, a) - char *s; - ARRAY8Ptr a; +# ifdef XDMCP +static void +XdmPrintArray8Hex (char *s, ARRAY8Ptr a) { XdmPrintDataHex (s, (char *) a->data, a->length); } -#endif +# endif void -XdmInitAuth (name_len, name) - unsigned short name_len; - char *name; +XdmInitAuth (unsigned short name_len, char *name) { if (name_len > 256) name_len = 256; @@ -91,7 +96,7 @@ } /* - * Generate authorization for XDM-AUTHORIZATION-1 + * Generate authorization for XDM-AUTHORIZATION-1 * * When being used with XDMCP, 8 bytes are generated for the session key * (sigma), as the random number (rho) is already shared between xdm and @@ -99,11 +104,8 @@ * between xdm and the server (16 bytes total) */ -Xauth * -XdmGetAuthHelper (namelen, name, includeRho) - unsigned short namelen; - char *name; - int includeRho; +static Xauth * +XdmGetAuthHelper (unsigned short namelen, char *name, int includeRho) { Xauth *new; new = (Xauth *) malloc (sizeof (Xauth)); @@ -152,20 +154,17 @@ } Xauth * -XdmGetAuth (namelen, name) - unsigned short namelen; - char *name; +XdmGetAuth (unsigned short namelen, char *name) { return XdmGetAuthHelper (namelen, name, TRUE); } -#ifdef XDMCP +# ifdef XDMCP void -XdmGetXdmcpAuth (pdpy,authorizationNameLen, authorizationName) - struct protoDisplay *pdpy; - unsigned short authorizationNameLen; - char *authorizationName; +XdmGetXdmcpAuth (struct protoDisplay *pdpy, + unsigned short authorizationNameLen, + char *authorizationName) { Xauth *fileauth, *xdmcpauth; @@ -206,7 +205,9 @@ XdmPrintDataHex ("Accept packet auth", xdmcpauth->data, xdmcpauth->data_length); XdmPrintDataHex ("Auth file auth", fileauth->data, fileauth->data_length); /* encrypt the session key for its trip back to the server */ - XdmcpWrap (xdmcpauth->data, (unsigned char *)&pdpy->key, xdmcpauth->data, 8); + XdmcpWrap ((unsigned char *)&xdmcpauth->data, + (unsigned char *)&pdpy->key, + (unsigned char *)&xdmcpauth->data, 8); pdpy->fileAuthorization = fileauth; pdpy->xdmcpAuthorization = xdmcpauth; } @@ -216,8 +217,7 @@ 'A' <= c && c <= 'F' ? c - 'A' + 10 : -1) static int -HexToBinary (key) - char *key; +HexToBinary (char *key) { char *out, *in; int top, bottom; @@ -246,16 +246,14 @@ * routine accepts either plain ascii strings for keys, or hex-encoded numbers */ -int -XdmGetKey (pdpy, displayID) - struct protoDisplay *pdpy; - ARRAY8Ptr displayID; +static int +XdmGetKey (struct protoDisplay *pdpy, ARRAY8Ptr displayID) { FILE *keys; char line[1024], id[1024], key[1024]; int keylen; - Debug ("Lookup key for %*.*s\n", displayID->length, displayID->length, displayID->data); + Debug ("lookup key for %*.*s\n", displayID->length, displayID->length, displayID->data); keys = fopen (keyFile, "r"); if (!keys) return FALSE; @@ -264,7 +262,7 @@ if (line[0] == '#' || sscanf (line, "%s %s", id, key) != 2) continue; bzero(line, sizeof(line)); - Debug ("Key entry for \"%s\" %d bytes\n", id, strlen(key)); + Debug ("key entry for \"%s\" %d bytes\n", id, strlen(key)); if (strlen (id) == displayID->length && !strncmp (id, (char *)displayID->data, displayID->length)) { @@ -311,5 +309,5 @@ return TRUE; } -#endif /* XDMCP */ +# endif /* XDMCP */ #endif /* HASXDMAUTH (covering the entire file) */ diff -urN xc/programs/xdm~/xdmshell.c xc/programs/xdm/xdmshell.c --- xc/programs/xdm~/xdmshell.c 2003-09-21 15:39:23.000000000 -0500 +++ xc/programs/xdm/xdmshell.c 2003-09-21 15:40:41.000000000 -0500 @@ -41,6 +41,7 @@ #include <stdio.h> #include "dm.h" #include <errno.h> +#include <string.h> #ifdef macII #define ON_CONSOLE_ONLY @@ -193,7 +194,7 @@ args[4] = NULL; if (exec_args (cmdbuf, args) == -1) { fprintf (stderr, "%s: unable to execute %s (error %d, %s)\r\n", - ProgramName, cmdbuf, errno, strerror(errno)); + ProgramName, cmdbuf, errno, strerror (errno)); exit (1); }
signature.asc
Description: Digital signature