1 /* (c) Copyright 1997 The Open Group */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
4 * (c) Copyright 1993, 1994 International Business Machines Corp. *
5 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
6 * (c) Copyright 1993, 1994 Novell, Inc. *
9 * xdm - display manager daemon
11 * $TOG: dm.h /main/12 1998/04/06 13:21:59 mgreess $
13 * Copyright 1988 Massachusetts Institute of Technology
15 * Permission to use, copy, modify, and distribute this software and its
16 * documentation for any purpose and without fee is hereby granted, provided
17 * that the above copyright notice appear in all copies and that both that
18 * copyright notice and this permission notice appear in supporting
19 * documentation, and that the name of M.I.T. not be used in advertising or
20 * publicity pertaining to distribution of the software without specific,
21 * written prior permission. M.I.T. makes no representations about the
22 * suitability of this software for any purpose. It is provided "as is"
23 * without express or implied warranty.
25 * Author: Keith Packard, MIT X Consortium
31 * public interfaces for greet/verify functionality
39 /***************************************************************************
43 ***************************************************************************/
45 # include <errno.h> /* for errno */
46 # include <pwd.h> /* for passwd structure */
48 # include <stdlib.h> /* for exit(), malloc(), abort() */
49 # include <string.h> /* for string functions, bcopy(),
51 # include <sys/param.h> /* for NGROUPS */
52 # include <sys/types.h> /* for fd_set */
53 # include <netinet/in.h> /* for Internet socket stuff */
56 # include <strings.h> /* for BSD string functions */
59 # include <X11/Xlib.h>
62 # include <X11/Xauth.h>
63 # include <X11/Xdmcp.h>
64 #ifdef SVR4 /*** needed for bcopy bcmp ***/
65 #include <X11/Xlibint.h>
68 # include <X11/Xresource.h>
70 #ifndef LAST_SESSION_FILE
71 #define LAST_SESSION_FILE "/.dt/sessions/lastsession"
74 #ifndef CDE_INSTALLATION_TOP
75 #define CDE_INSTALLATION_TOP "/opt/dt"
78 #define DEF_PATH "/usr/bin:" /* same as PATH */
79 #define DEF_SUPATH "/usr/sbin:/usr/bin" /* same as ROOTPATH */
81 #define LANGLISTSIZE 2048
82 #define DELIM " \t" /* delimiters in language list */
85 /***************************************************************************
89 ***************************************************************************/
92 * Default directories containing locale information.
94 #if defined(_AIX) || defined (__osf__)
95 #define DEF_NLS_DIR "/usr/lib/nls/loc"
97 #define DEF_NLS_DIR "/usr/lib/nls/msg"
98 #elif defined(sun) || defined(__uxp__) || defined(USL)
99 #define DEF_NLS_DIR "/usr/lib/locale"
101 #define DEF_NLS_DIR CDE_INSTALLATION_TOP "/lib/nls/msg"
105 #define DEF_X11_NLS_SHARE_DIR "/usr/openwin/share/locale"
106 #define DEF_X11_NLS_LIB_DIR "/usr/openwin/lib/locale"
109 /**************************************************************************
113 **************************************************************************/
115 /* Default dummy device name (/etc/utmp "tty line" for foreign displays ) */
116 #define DEF_NETWORK_DEV "/dev/dtremote"
119 * Pseudo-tty file creation routine
121 * For remote connections, the value for 'line' in /etc/utmp must also
122 * exist as a device in the /dev directory for commands such as 'finger'
123 * to operate properly.
125 * For most platforms, /dev/dtremote will simply be a symbolic link
126 * to the /dev/null device.
128 * For AIX, /dev/dtremote will be a character special file whose major
129 * and minor numbers are the same as /dev/null. This is the case since
130 * the AIX init command will chown and chmod the 'line' device if dtlogin
131 * dies while owned by init. If /dev/dtremote were a symlink to /dev/null,
132 * /dev/null whould be chown/chmod such that regular users could no longer
136 #define MK_NETWORK_DEV_PERMS (S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
137 #define MK_NETWORK_DEV(DEV) (mknod(DEV, MK_NETWORK_DEV_PERMS, makedev(2, 2)))
139 #define MK_NETWORK_DEV(DEV) (symlink("/dev/null",DEV))
142 /* Utmp rec prefix */
143 #define UTMPREC_PREFIX "dt"
145 #ifdef SIGNALRETURNSINT
152 #ifndef UID_NO_CHANGE
153 # define UID_NO_CHANGE ((uid_t) -1) /* for chown(2) and setresuid(2) */
156 #ifndef GID_NO_CHANGE
157 # define GID_NO_CHANGE ((gid_t) -1) /* for chown(2) and setresgid(2) */
166 #define bzero(x,y) memset((void *)(x),0,(y))/* use ANSI C version */
168 #define bzero(x,y) memset((x),0,(y)) /* use ANSI C version */
172 #define IsVerifyName(n) ((d->verifyName && (strcmp(d->verifyName,(n)) == 0 )) \
176 /***************************************************************************
180 ***************************************************************************/
182 /*#if defined(SYSV) && !defined(hpux)*/
183 #if defined(SYSV) || defined(SVR4) || defined(linux)
184 # include <sys/wait.h>
185 # define waitCode(w) WEXITSTATUS(w)
186 # define waitSig(w) WTERMSIG(w)
189 * hpux has a "WCOREDUMP" macro which is undefined in AIX.
190 * For AIX, the macro from hpux's <sys/wait.h> is used.
192 # define waitCore(w) ( ((int)(w)&0200) == 0 ? 0 : 1 )
194 # define waitCore(w) ( WCOREDUMP(w) == 0 ? 0 : 1 )
196 typedef int waitType;
199 # include <sys/wait.h>
202 # include <sys/wait.h>
205 # define waitCode(w) ((w).w_T.w_Retcode)
206 # define waitSig(w) ((w).w_T.w_Termsig)
207 # define waitCore(w) ((w).w_T.w_Coredump)
208 typedef union wait waitType;
211 # define waitCompose(sig,core,code) ((sig) * 256 + (core) * 128 + (code))
213 # define waitVal(w) waitCompose(waitSig(w), waitCore(w), waitCode(w))
215 # define waitVal(w) waitCode(w)
220 /***************************************************************************
224 ***************************************************************************/
227 typedef struct my_fd_set { int fds_bits[1]; } my_fd_set;
228 # define FD_ZERO(fdp) bzero ((fdp), sizeof (*(fdp)))
229 # define FD_SET(f,fdp) ((fdp)->fds_bits[(f) / (sizeof (int) * 8)] |= (1 << ((f) % (sizeof (int) * 8))))
230 # define FD_CLR(f,fdp) ((fdp)->fds_bits[(f) / (sizeof (int) * 8)] &= ~(1 << ((f) % (sizeof (int) * 8))))
231 # define FD_ISSET(f,fdp) ((fdp)->fds_bits[(f) / (sizeof (int) * 8)] & (1 << ((f) % (sizeof (int) * 8))))
232 # define FD_TYPE my_fd_set
234 # define FD_TYPE fd_set
240 /***************************************************************************
242 * Defines and structures for display management
244 ***************************************************************************/
246 typedef enum displayStatus { running, notRunning, zombie, phoenix, suspended }
249 typedef enum fileState { NewEntry, OldEntry, MissingEntry } FileState;
252 * local - server runs on local host
253 * foreign - server runs on remote host
254 * permanent - session restarted when it exits
255 * transient - session not restarted when it exits
256 * fromFile - started via entry in servers file
257 * fromXDMCP - started with XDMCP
260 typedef struct displayType {
261 unsigned int location:1;
262 unsigned int lifetime:1;
263 unsigned int origin:1;
278 * NONE - no getty running or don't care
279 * LOGIN - getty running
280 * USER - user logged in on getty
282 #define DM_GETTY_NONE 0
283 #define DM_GETTY_LOGIN 1
284 #define DM_GETTY_USER 2
287 struct display *next;
288 /* Xservers file / XDMCP information */
289 char *name; /* DISPLAY name */
290 char *class; /* display class (may be NULL) */
291 DisplayType displayType; /* method to handle with */
292 char **argv; /* program name and arguments */
295 DisplayStatus status; /* current status */
296 int pid; /* process id of child */
297 int serverPid; /* process id of server (-1 if none) */
298 FileState state; /* state during HUP processing */
299 int startTries; /* current start try */
300 int gettyState; /* current getty state */
303 CARD32 sessionID; /* ID of active session */
304 struct sockaddr *peer; /* sockaddr of display peer */
305 int peerlen; /* length of peer name */
306 struct sockaddr *from; /* XDMCP port of display */
308 CARD16 displayNumber;
309 int useChooser; /* Run the chooser for this display */
310 ARRAY8 clientAddr; /* for chooser picking */
311 CARD16 connectionType; /* ... */
314 int bypassLogin; /* bypass login for this display */
315 #endif /* BYPASSLOGIN */
317 /* server management resources */
318 int serverAttempts; /* number of attempts at running X */
319 int openDelay; /* open delay time */
320 int openRepeat; /* open attempts to make */
321 int openTimeout; /* abort open attempt timeout */
322 int startAttempts; /* number of attempts at starting */
323 int pingInterval; /* interval between XSync */
324 int pingTimeout; /* timeout for XSync */
325 int terminateServer;/* restart for each session */
326 int grabServer; /* keep server grabbed for Login */
327 int grabTimeout; /* time to wait for grab */
328 int resetSignal; /* signal to reset server */
329 int termSignal; /* signal to terminate server */
330 int resetForAuth; /* server reads auth file at reset */
332 /* session resources */
333 char *resources; /* resource file */
334 char *xrdb; /* xrdb program */
335 char *cpp; /* cpp program */
336 char *setup; /* Xsetup program */
337 char *startup; /* Xstartup program */
338 char *reset; /* Xreset program */
339 char *session; /* Xsession program */
340 char *userPath; /* path set for session */
341 char *systemPath; /* path set for startup/reset */
342 char *systemShell; /* interpreter for startup/reset */
343 char *failsafeClient;/* a client to start when the session fails */
344 char *chooser; /* chooser program */
346 /* authorization resources */
347 int authorize; /* enable authorization */
348 char **authNames; /* authorization protocol name */
349 unsigned short *authNameLens; /* authorization protocol name len */
350 char *clientAuthFile;/* client specified auth file */
351 char *userAuthDir; /* backup directory for tickets */
353 /* information potentially derived from resources */
354 int authNameNum; /* number of protocol names */
355 Xauth **authorizations; /* authorization data */
356 int authNum; /* number of authorizations */
357 char *authFile; /* file to store authorization in */
358 char *language; /* value for LANG env variable */
359 char *langList; /* list of languages on login screen */
360 char *utmpId; /* id for entry in utmp file */
361 char *gettyLine; /* line to run getty on */
362 char *gettySpeed; /* speed for getty (from gettydefs) */
363 char *environStr; /* environment variable resource */
364 int dtlite; /* boolean for HP DT Lite session */
365 int xdmMode; /* boolean for XDM style session */
366 int sessionType; /* default, XDM, DT, or DTLITE session */
367 char *verifyName; /* default, Kerberos, AFS, B1 */
368 char *pmSearchPath; /* motif pixmap search path */
369 char *bmSearchPath; /* motif bitmap search path */
372 #define PROTO_TIMEOUT (30 * 60) /* 30 minutes should be long enough */
374 struct protoDisplay {
375 struct protoDisplay *next;
376 struct sockaddr *address; /* UDP address */
377 int addrlen; /* UDP address length */
378 unsigned long date; /* creation date */
379 CARD16 displayNumber;
380 CARD16 connectionType;
381 ARRAY8 connectionAddress;
383 Xauth *fileAuthorization;
384 Xauth *xdmcpAuthorization;
385 ARRAY8 authenticationName;
386 ARRAY8 authenticationData;
392 char *name; /* user name */
393 char *password; /* user password */
395 char *b1security; /* user's b1 security */
397 char *string; /* random string */
399 char *name_full; /* full SID */
404 int uid; /* user id */
406 gid_t groups[NGROUPS];/* group list */
407 int ngroups; /* number of elements in groups */
409 int gid; /* group id */
411 char **argv; /* arguments to session */
412 char **userEnviron; /* environment for session */
413 char **systemEnviron;/* environment for startup/reset */
415 long audid; /* audit id */
416 int audflg; /* audit flag */
420 struct mand_ir_t *sec_label_ir;
421 struct mand_ir_t *clearance_ir;
422 /* save these for logout time */
423 struct pr_passwd *prpwd;
430 /* display manager exit status definitions */
432 # define OBEYSESS_DISPLAY 0 /* obey multipleSessions resource */
433 # define REMANAGE_DISPLAY 1 /* force remanage */
434 # define UNMANAGE_DISPLAY 2 /* force deletion */
435 # define RESERVER_DISPLAY 3 /* force server termination */
436 # define OPENFAILED_DISPLAY 4 /* XOpenDisplay failed, retry */
437 # define SUSPEND_DISPLAY 5 /* suspend server while getty is run */
439 # define GREETLESS_FAILED 6
440 #endif /* BYPASSLOGIN */
446 # define CLOSE_ALWAYS 0
447 # define LEAVE_FOR_DISPLAY 1
452 /***************************************************************************
454 * External variable declarations
456 ***************************************************************************/
459 extern char *sys_errlist[]; /* system error msgs */
460 extern int sys_nerr; /* system error msgs */
462 extern XrmDatabase XresourceDB;
468 extern char *sysParmsFile;
469 extern char *accessFile;
470 extern char *servers;
471 extern int request_port;
472 extern int debugLevel;
473 extern char *errorLogFile;
474 extern int errorLogSize;
475 extern int daemonMode;
476 extern char *pidFile;
477 extern int lockPidFile;
478 extern char *authDir;
479 extern int autoRescan;
480 extern int removeDomainname;
481 extern char *keyFile;
482 extern char *timeZone;
483 extern int wakeupInterval;
486 extern int langListTimeout;
487 #ifdef DEF_NETWORK_DEV
488 extern char *networkDev;
491 extern char *ignoreLocales;
494 #if !defined (ENABLE_DYNAMIC_LANGLIST)
495 extern char languageList[]; /* util.c */
496 #endif /* ENABLE_DYNAMIC_LANGLIST */
498 extern char **exportList; /* list of export env vars RK 08.17.93 */
503 /****************************************************************************
505 * Public procedure declarations
507 ****************************************************************************/
509 /******************************* access.c **************************/
511 extern int AcceptableDisplayAddress(
512 ARRAY8Ptr clientAddress,
513 #if NeedWidePrototypes
516 CARD16 connectionType,
517 #endif /* NeedWidePrototypes */
520 extern void ForEachChooserHost(
521 ARRAY8Ptr clientAddress,
522 #if NeedWidePrototypes
525 CARD16 connectionType,
526 #endif /* NeedWidePrototypes */
529 extern int ForEachMatchingIndirectHost(
530 ARRAY8Ptr clientAddress,
531 #if NeedWidePrototypes
534 CARD16 connectionType,
535 #endif /* NeedWidePrototypes */
538 extern int ScanAccessDatabase( void ) ;
539 extern int UseChooser(
540 ARRAY8Ptr clientAddress,
541 #if NeedWidePrototypes
542 int connectionType) ;
544 CARD16 connectionType) ;
545 #endif /* NeedWidePrototypes */
546 extern ARRAY8Ptr getLocalAddress( void ) ;
549 /******************************* account.c **************************/
556 #if NeedWidePrototypes
560 #endif /* NeedWidePrototypes */
563 extern int UtmpIdOpen(
567 /******************************* apollo.c **************************/
575 /******************************* auth.c **************************/
577 extern int ConvertAddr(
579 int *len, /* return */
580 char **addr); /* return */
582 extern int ConvertFamily(
585 extern int SaveServerAuthorizations(
589 extern void SetAuthorization(
591 extern void SetLocalAuthorization(
593 extern void SetProtoDisplayAuthorization(
594 struct protoDisplay *pdpy,
595 #if NeedWidePrototypes
596 unsigned int authorizationNameLen,
598 unsigned short authorizationNameLen,
599 #endif /* NeedWidePrototypes */
600 char *authorizationName) ;
601 extern void SetUserAuthorization(
603 struct verify_info *verify) ;
604 extern int ValidAuthorization(
605 #if NeedWidePrototypes
606 unsigned int name_length,
608 unsigned short name_length,
609 #endif /* NeedWidePrototypes */
613 /******************************* cryptokey.c **************************/
615 extern void GenerateCryptoKey(
618 extern int InitCryptoKey( void ) ;
621 /******************************* daemon.c **************************/
623 extern void BecomeDaemon( void ) ;
626 /******************************* dm.c **************************/
628 extern int CloseOnFork( void ) ;
629 extern void GettyMessage(
632 extern void RegisterCloseOnFork(
637 extern int StartDisplay(
639 extern void StartDisplays( void ) ;
640 extern void StopDisplay(
642 extern void WaitForChild( void ) ;
646 extern int GettyRunning( struct display *d) ;
649 /******************************* dpylist.c **************************/
651 extern int AnyDisplaysLeft( void ) ;
653 extern struct display * FindDisplayByAddress(
654 struct sockaddr *addr,
656 #if NeedWidePrototypes
659 CARD16 displayNumber) ;
660 #endif /* NeedWidePrototypes */
662 extern struct display * FindDisplayByName(
664 extern struct display * FindDisplayByPid(
666 extern struct display * FindDisplayByServerPid(
668 extern struct display * FindDisplayBySessionID(
671 extern void ForEachDisplay(
673 extern struct display * NewDisplay(
676 extern void RemoveDisplay(
677 struct display *old) ;
680 /******************************* error.c **************************/
684 extern void InitErrorLog( void ) ;
685 extern void CheckErrorFile( void ) ;
686 extern void LogError(
687 unsigned char *fmt, ...) ;
689 unsigned char *fmt, ...) ;
690 extern void LogOutOfMem(
691 unsigned char *fmt, ...) ;
692 extern void LogPanic(
693 unsigned char *fmt, ...) ;
696 extern int SyncErrorFile(
698 extern void TrimErrorFile( void ) ;
701 /******************************* file.c **************************/
703 extern int ParseDisplay( char *source,
704 DisplayType *acceptableTypes,
706 struct passwd *puser );
709 /******************************* mitauth.c **************************/
711 extern Xauth * MitGetAuth(
712 #if NeedWidePrototypes
713 unsigned int namelen,
715 unsigned short namelen,
716 #endif /* NeedWidePrototypes */
719 extern int MitInitAuth(
720 #if NeedWidePrototypes
721 unsigned int name_len,
723 unsigned short name_len,
724 #endif /* NeedWidePrototypes */
728 /******************************* policy.c **************************/
730 extern ARRAY8Ptr Accept(
731 struct sockaddr *from,
733 #if NeedWidePrototypes
736 CARD16 displayNumber) ;
737 #endif /* NeedWidePrototypes */
739 extern int CheckAuthentication(
740 struct protoDisplay *pdpy,
744 extern ARRAY8Ptr ChooseAuthentication(
745 ARRAYofARRAY8Ptr authenticationNames) ;
746 extern int SelectAuthorizationTypeIndex(
747 ARRAY8Ptr authenticationName,
748 ARRAYofARRAY8Ptr authorizationNames) ;
749 extern int SelectConnectionTypeIndex(
750 ARRAY16Ptr connectionTypes,
751 ARRAYofARRAY8Ptr connectionAddresses) ;
755 #if NeedWidePrototypes
758 CARD16 connectionType,
759 #endif /* NeedWidePrototypes */
760 ARRAY8Ptr authenticationName,
763 extern ARRAY8Ptr Accept(
764 struct sockaddr *from,
766 #if NeedWidePrototypes
769 CARD16 displayNumber) ;
770 #endif /* NeedWidePrototypes */
772 /******************************* protodpy.c **************************/
774 extern int DisposeProtoDisplay(
775 struct protoDisplay *pdpy) ;
776 extern void TimeoutProtoDisplays(
778 extern int addressEqual(
783 extern struct protoDisplay * FindProtoDisplay(
784 struct sockaddr *address,
786 #if NeedWidePrototypes
789 CARD16 displayNumber) ;
790 #endif /* NeedWidePrototypes */
792 extern struct protoDisplay * NewProtoDisplay(
793 struct sockaddr *address,
795 #if NeedWidePrototypes
799 CARD16 displayNumber,
800 CARD16 connectionType,
801 #endif /* NeedWidePrototypes */
802 ARRAY8Ptr connectionAddress,
807 /******************************* reset.c **************************/
809 extern void pseudoReset(
813 /******************************* resource.c **************************/
815 extern int GetResource(
820 char *default_value) ;
821 extern void InitResources(
824 extern void ReinitResources( void ) ;
825 extern void LoadDMResources( void ) ;
826 extern void LoadDisplayResources(
828 extern void SetAppName( void ) ;
831 /******************************* server.c **************************/
833 extern int LogOpenError(
835 extern int PingServer(
837 Display *alternateDpy) ;
838 extern void ResetServer(
840 extern int StartServer(
842 extern int StartServerOnce(
844 extern int WaitForServer(
848 /******************************* session.c **************************/
850 extern void ManageSession(
856 struct verify_info *verify,
861 /******************************* socket.c **************************/
863 extern int AnyWellKnownSockets( void ) ;
864 extern int CreateWellKnownSockets( void ) ;
865 extern void DestroyWellKnownSockets( void ) ;
866 extern char * NetworkAddressToHostname(
867 #if NeedWidePrototypes
870 CARD16 connectionType,
871 #endif /* NeedWidePrototypes */
872 ARRAY8Ptr connectionAddress) ;
873 extern char * localHostname( void ) ;
874 extern char * NetworkAddressToName(
875 #if NeedWidePrototypes
878 CARD16 connectionType,
879 #endif /* NeedWidePrototypes */
880 ARRAY8Ptr connectionAddress,
881 #if NeedWidePrototypes
884 CARD16 displayNumber) ;
885 #endif /* NeedWidePrototypes */
886 extern void SendFailed(
889 extern void WaitForSomething( void ) ;
891 extern char * localHostname( void ) ;
895 /******************************* util.c **************************/
897 extern void CleanUpChild( void ) ;
898 extern Cursor GetHourGlass(
900 #if !defined (ENABLE_DYNAMIC_LANGLIST)
901 extern void MakeLangList( void ) ;
903 extern void SetHourGlassCursor(
906 extern char * getEnv(
909 extern char ** parseArgs(
912 extern char ** parseEnv(
915 extern void printEnv(
917 extern char ** setEnv(
921 extern unsigned char * ReadCatalog(
925 extern char ** setLang(
930 /******************************* verify.c **************************/
932 extern void getGroups(
934 struct verify_info *verify,
936 extern int groupMember(
939 extern char ** setDt(
943 extern char ** systemEnv(
947 extern char ** userEnv(
955 struct greet_info *greet,
956 struct verify_info *verify) ;
959 extern char * login_defaults(struct passwd *p,
968 /******************************* version.c **************************/
969 /******************************* xdmauth.c **************************/
971 extern int XdmInitAuth(
972 #if NeedWidePrototypes
973 unsigned int name_len,
975 unsigned short name_len,
976 #endif /* NeedWidePrototypes */
979 extern Xauth * XdmGetAuth(
980 #if NeedWidePrototypes
981 unsigned int namelen,
983 unsigned short namelen,
984 #endif /* NeedWidePrototypes */
987 extern int XdmGetXdmcpAuth(
988 struct protoDisplay *pdpy,
989 #if NeedWidePrototypes
990 unsigned int authorizationNameLen,
992 unsigned short authorizationNameLen,
993 #endif /* NeedWidePrototypes */
994 char *authorizationName) ;
996 extern int XdmGetKey(
997 struct protoDisplay *pdpy,
998 ARRAY8Ptr displayID) ;
1000 extern int XdmCheckAuthentication(
1001 struct protoDisplay *pdpy,
1002 ARRAY8Ptr displayID,
1003 ARRAY8Ptr authenticationName,
1004 ARRAY8Ptr authenticationData) ;
1007 #endif /* HASXDMAUTH */