1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
/*
Copyright 1988, 1998 The Open Group
Copyright 2000-2005 Oswald Buddenhagen <ossi@kde.org>
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of a copyright holder shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from the copyright holder.
*/
/*
* xdm - display manager daemon
* Author: Keith Packard, MIT X Consortium
*
* global xdm core declarations
*/
#ifndef _DM_H_
#define _DM_H_ 1
#define WITH_CONSOLE_KIT
#include "greet.h"
#include <config.ci>
#include <X11/X.h> /* FamilyInternet6 */
#include <X11/Xos.h>
#include <X11/Xfuncs.h>
#include <X11/Xmd.h>
#include <X11/Xauth.h>
#include <X11/Intrinsic.h>
#include <sys/param.h>
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
#include <time.h>
#define Time_t time_t
#include <stdlib.h>
#include <errno.h>
#ifdef XDMCP
# if defined(__osf__)
/* someone somewhere defines QUERY under Tru64 which confuses Xdmcp.h */
# undef QUERY
# endif
# include <X11/Xdmcp.h>
#endif
#ifndef PATH_MAX
# ifdef MAXPATHLEN
# define PATH_MAX MAXPATHLEN
# else
# define PATH_MAX 1024
# endif
#endif
#include <sys/wait.h>
#define waitCode(w) (WIFEXITED(w) ? WEXITSTATUS(w) : 0)
#define waitSig(w) (WIFSIGNALED(w) ? WTERMSIG(w) : 0)
#ifdef WCOREDUMP
# define waitCore(w) (WCOREDUMP(w))
#else
# define waitCore(w) 0 /* not in POSIX. so what? */
#endif
typedef int waitType;
#define waitCompose(sig,core,code) ((sig) * 256 + (core) * 128 + (code))
#define waitVal(w) waitCompose(waitSig(w), waitCore(w), waitCode(w))
#define WaitCode(w) ((w) & 0x7f)
#define WaitCore(w) (((w) >> 7) & 1)
#define WaitSig(w) (((w) >> 8) & 0xff)
#include <sys/time.h>
#define FD_TYPE fd_set
#include <setjmp.h>
#if defined(__EMX__) || (defined(__NetBSD__) && defined(__sparc__)) /* XXX netbsd? */
# define Setjmp(e) setjmp(e)
# define Longjmp(e,v) longjmp(e,v)
# define Jmp_buf jmp_buf
#else
# define Setjmp(e) sigsetjmp(e,1)
# define Longjmp(e,v) siglongjmp(e,v)
# define Jmp_buf sigjmp_buf
#endif
#include <utmp.h>
#ifdef HAVE_UTMPX
# include <utmpx.h>
# define STRUCTUTMP struct utmpx
# define UTMPNAME utmpxname
# define SETUTENT setutxent
# define GETUTENT getutxent
# define PUTUTLINE pututxline
# define ENDUTENT endutxent
# define LASTLOG lastlogx
# define ut_time ut_tv.tv_sec
# define ll_time ll_tv.tv_sec
#else
# define STRUCTUTMP struct utmp
# define UTMPNAME utmpname
# define SETUTENT setutent
# define GETUTENT getutent
# define PUTUTLINE pututline
# define ENDUTENT endutent
# define LASTLOG lastlog
#endif
#ifndef HAVE_STRUCT_UTMP_UT_USER
# define ut_user ut_name
#endif
#ifndef WTMP_FILE
# ifdef _PATH_WTMPX
# define WTMP_FILE _PATH_WTMPX
# elif defined(_PATH_WTMP)
# define WTMP_FILE _PATH_WTMP
# else
# define WTMP_FILE "/usr/adm/wtmp"
# endif
#endif
#ifndef UTMP_FILE
# ifdef _PATH_UTMPX
# define UTMP_FILE _PATH_UTMPX
# elif defined(_PATH_UTMP)
# define UTMP_FILE _PATH_UTMP
# else
# define UTMP_FILE "/etc/utmp"
# endif
#endif
#ifdef HAVE_NETCONFIG_H
# define STREAMSCONN
#else
# define UNIXCONN
# define TCPCONN
# ifdef FamilyInternet6
# define IPv6
# endif
# ifdef HAVE_NETDNET_DN_H
# define DNETCONN
# endif
#endif
#if !defined(HAVE_ARC4RANDOM) && !defined(DEV_RANDOM)
# define NEED_ENTROPY
#endif
typedef struct GPipe {
int wfd, rfd;
char *who;
} GPipe;
typedef struct GTalk {
GPipe *pipe;
Jmp_buf errjmp;
} GTalk;
typedef struct GProc {
GPipe pipe;
int pid;
} GProc;
typedef enum displaytqStatus { notRunning = 0, running, zombie, phoenix, raiser,
textMode, reserve, remoteLogin } DisplaytqStatus;
typedef enum servertqStatus { ignore = 0, awaiting, starting,
terminated, killed, pausing } ServertqStatus;
typedef struct RcStr {
struct RcStr *next;
char *str;
int cnt;
} RcStr;
typedef struct CfgDep {
RcStr *name;
long time;
} CfgDep;
typedef struct CfgArr {
char *data; /* config value array; allocated */
long *idx; /* config index array; alias */
CfgDep dep; /* filestamp */
int numCfgEnt; /* number of config entries */
} CfgArr;
struct bsock {
int fd;
int buflen;
char *buffer;
};
struct cmdsock {
struct cmdsock *next;
struct bsock sock; /* buffered fd of the socket */
};
typedef struct {
struct cmdsock *css; /* open connections */
char *path; /* filename of the socket */
#ifndef HONORS_SOCKET_PERMS
char *realdir; /* real dirname of the socket */
#endif
int fd; /* fd of the socket */
int gid; /* owner group of the socket */
char *fpath; /* filename of the fifo */
struct bsock fifo; /* buffered fd of the fifo */
} CtrlRec;
struct display {
struct display *next;
struct disphist *hstent; /* display history entry */
/* basic display information */
char *name; /* DISPLAY name -- also referenced in hstent */
char *class2; /* display class (may be NULL) */
int displayType; /* location/origin/lifetime */
CfgArr cfg; /* config data array */
/* display state */
DisplaytqStatus status; /* current status */
int zstatus; /* substatus while zombie */
int pid; /* process id of child */
int serverPid; /* process id of server (-1 if none) */
#ifdef HAVE_VTS
int serverVT; /* server VT (0 = none, -1 = pending) */
struct display *follower; /* on exit, hand VT to this display */
#endif
ServertqStatus servertqStatus; /* X server startup state */
Time_t lastStart; /* time of last display start */
int startTries; /* current start try */
int stillThere; /* state during HUP processing */
int userSess; /* -1=nobody, otherwise uid */
char *userName;
char *sessName;
CtrlRec ctrl; /* command socket & fifo */
GPipe pipe; /* comm master <-> slave */
GPipe gpipe; /* comm master <-> greeter */
#ifdef XDMCP
char *remoteHost; /* for X -query type remote login */
/* XDMCP state */
unsigned sessionID; /* ID of active session */
ARRAY8 peer; /* display peer address */
ARRAY8 from; /* XDMCP port of display */
unsigned displayNumber; /* numerical part of name */
int useChooser; /* Run the chooser for this display */
ARRAY8 clientAddr; /* for chooser picking */
unsigned connectionType; /* ... */
int xdmcpFd;
#endif
CONF_CORE_LOCAL_DEFS
int idleTimeout; /* abort login after that time */
unsigned short *authNameLens; /* authorization protocol name lens */
/* information potentially derived from resources */
int authNameNum; /* number of protocol names */
Xauth **authorizations; /* authorization data */
int authNum; /* number of authorizations */
char *authFile; /* file to store authorization in */
};
typedef struct {
unsigned how:2, /* 0=none 1=reboot 2=halt (SHUT_*) */
force:2;
int uid;
int start;
int timeout;
char *osname;
time_t bmstamp;
int osindex;
} SdRec;
struct disphist {
struct disphist *next;
char *name;
Time_t lastExit; /* time of last display exit */
unsigned rLogin:2, /* 0=nothing 1=relogin 2=login */
lock:1, /* screen locker running */
goodExit:1; /* was the last exit "peaceful"? */
SdRec sdRec;
char *nuser, *npass, *nargs;
};
#ifdef XDMCP
#define PROTO_TIMEOUT (30 * 60) /* 30 minutes should be long enough */
struct protoDisplay {
struct protoDisplay *next;
XdmcpNetaddr address; /* UDP address */
int addrlen; /* UDP address length */
unsigned long date; /* creation date */
CARD16 displayNumber;
CARD16 connectionType;
ARRAY8 connectionAddress;
CARD32 sessionID;
Xauth *fileAuthorization;
Xauth *xdmcpAuthorization;
ARRAY8 authenticationName;
ARRAY8 authenticationData;
XdmAuthKeyRec key;
};
#endif /* XDMCP */
/* status code for RStopDisplay */
#define DS_RESTART 0
#define DS_TEXTMODE 1
#define DS_RESERVE 2
#define DS_REMOTE 3
#define DS_REMOVE 4
/* command codes dpy process -> master process */
#define D_User 1
#define D_ReLogin 2
#define D_ChooseHost 4
#define D_RemoteHost 5
#define D_XConnOk 6
extern int debugLevel;
CONF_CORE_GLOBAL_DECLS
/* in daemon.c */
void BecomeDaemon( void );
/* in dm.c */
extern char *prog, *progpath;
extern time_t now;
extern SdRec sdRec;
void StartDisplay( struct display *d );
void StartDisplayP2( struct display *d );
void StopDisplay( struct display *d );
void SetTitle( const char *name );
void SwitchToX( struct display *d );
void setNLogin( struct display *d,
const char *nuser, const char *npass, char *nargs,
int rl );
void cancelShutdown( void );
int TTYtoVT( const char *tty );
int activateVT( int vt );
/* in ctrl.c */
void openCtrl( struct display *d );
void closeCtrl( struct display *d );
int handleCtrl( FD_TYPE *reads, struct display *d );
void chownCtrl( CtrlRec *cr, int uid );
void updateCtrl( void );
/* in dpylist.c */
extern struct display *displays; /* that's ugly ... */
int AnyDisplaysLeft( void );
void ForEachDisplay( void (*f)( struct display * ) );
#ifdef HAVE_VTS
void ForEachDisplayRev( void (*f)( struct display * ) );
#endif
void RemoveDisplay( struct display *old );
struct display
*FindDisplayByName( const char *name ),
#ifdef XDMCP
*FindDisplayBySessionID( CARD32 sessionID ),
*FindDisplayByAddress( XdmcpNetaddr addr, int addrlen, CARD16 displayNumber ),
#endif /* XDMCP */
*FindDisplayByPid( int pid ),
*FindDisplayByServerPid( int serverPid ),
*NewDisplay( const char *name );
int AnyActiveDisplays( void );
int AnyRunningDisplays( void );
int AnyReserveDisplays( void );
int idleReserveDisplays( void );
int AllLocalDisplaysLocked( struct display *dp );
int StartReserveDisplay( int lt );
void ReapReserveDisplays( void );
/* in reset.c */
void pseudoReset( void );
/* in resource.c */
char **FindCfgEnt( struct display *d, int id );
int InitResources( char **argv );
int LoadDMResources( int force );
int LoadDisplayResources( struct display *d );
void ScanServers( void );
void CloseGetter( void );
int startConfig( int what, CfgDep *dep, int force );
RcStr *newStr( char *str );
void delStr( RcStr *str );
extern GTalk cnftalk;
/* in session.c */
extern struct display *td;
extern const char *td_setup;
char **baseEnv( const char *user );
char **inheritEnv( char **env, const char **what );
char **systemEnv( const char *user );
int source( char **env, const char *file, const char *arg );
void ManageSession( struct display *d );
extern GTalk mstrtalk, grttalk;
extern GProc grtproc;
void OpenGreeter( void );
int CloseGreeter( int force );
int CtrlGreeterWait( int wreply );
void PrepErrorGreet( void );
char *conv_interact( int what, const char *prompt );
/* process.c */
typedef void (*SIGFUNC)( int );
SIGFUNC Signal( int, SIGFUNC Handler );
void RegisterInput( int fd );
void UnregisterInput( int fd );
void RegisterCloseOnFork( int fd );
void ClearCloseOnFork( int fd );
void CloseNClearCloseOnFork( int fd );
int Fork( void );
int Wait4( int pid );
void execute( char **argv, char **env );
int runAndWait( char **args, char **env );
FILE *pOpen( char **what, char m, int *pid );
int pClose( FILE *f, int pid );
char *locate( const char *exe );
void TerminateProcess( int pid, int sig );
void GSet( GTalk *talk); /* call before GOpen! */
int GFork( GPipe *pajp, const char *pname, char *cname,
GPipe *ogp, char *cgname );
void GClosen( GPipe *pajp );
int GOpen( GProc *proc,
char **argv, const char *what, char **env, char *cname,
GPipe *gp );
int GClose( GProc *proc, GPipe *gp, int force );
void GSendInt( int val );
int GRecvInt( void );
int GRecvCmd( int *cmd );
void GSendArr( int len, const char *data );
char *GRecvArr( int *len );
int GRecvStrBuf( char *buf );
int GRecvArrBuf( char *buf );
void GSendStr( const char *buf );
void GSendNStr( const char *buf, int len ); /* exact len, buf != 0 */
void GSendStrN( const char *buf, int len ); /* maximal len */
char *GRecvStr( void );
void GSendArgv( char **argv );
void GSendStrArr( int len, char **data );
char **GRecvStrArr( int *len );
char **GRecvArgv( void );
/* client.c */
#define GCONV_NORMAL 0
#define GCONV_HIDDEN 1
#define GCONV_USER 2
#define GCONV_PASS 3
#define GCONV_PASS_ND 4
#define GCONV_BINARY 5
typedef char *(*GConvFunc)( int what, const char *prompt );
int Verify( GConvFunc gconv, int rootok );
#ifdef WITH_CONSOLE_KIT
int StartClient( const char *ck_session_cookie );
#else
int StartClient( void );
#endif
void SessionExit( int status ) ATTR_NORETURN;
int ReadDmrc( void );
extern char **userEnviron, **systemEnviron;
extern char *curuser, *curpass, *curtype, *newpass,
*dmrcuser, *curdmrc, *newdmrc;
extern int cursource;
#define PWSRC_MANUAL 0
#define PWSRC_AUTOLOGIN 1
#define PWSRC_RELOGIN 2
/* server.c */
char **PrepServerArgv( struct display *d, const char *args );
void StartServer( struct display *d );
void AbortStartServer( struct display *d );
void StartServerSuccess( void );
void StartServerFailed( void );
void StartServerTimeout( void );
extern struct display *startingServer;
extern time_t serverTimeout;
void WaitForServer( struct display *d );
void ResetServer( struct display *d );
int PingServer(struct display *d );
extern Display *dpy;
/* in util.c */
void *Calloc( size_t nmemb, size_t size );
void *Malloc( size_t size );
void *Realloc( void *ptr, size_t size );
void WipeStr( char *str );
int StrCmp( const char *s1, const char *s2 );
#ifdef HAVE_STRNLEN
# define StrNLen(s, m) strnlen(s, m)
#else
int StrNLen( const char *s, int max );
#endif
int StrNDup( char **dst, const char *src, int len );
int StrDup( char **dst, const char *src );
int arrLen( char **arr );
void freeStrArr( char **arr );
char **initStrArr( char **arr );
char **xCopyStrArr( int rn, char **arr );
/* Note: the following functions free the old data even in case of failure */
int ReStrN( char **dst, const char *src, int len );
int ReStr( char **dst, const char *src );
int StrApp( char **dst, ... );
char **addStrArr( char **arr, const char *str, int len );
char **parseArgs( char **argv, const char *string );
/* End note */
char **setEnv( char **e, const char *name, const char *value );
char **putEnv( const char *string, char **env );
const char *getEnv( char **e, const char *name );
const char *localHostname( void );
int Reader( int fd, void *buf, int len );
int Writer( int fd, const void *buf, int len );
int fGets( char *buf, int max, FILE *f );
void randomStr( char *s );
time_t mTime( const char *fn );
void ListSessions( int flags, struct display *d, void *ctx,
void (*emitXSess)( struct display *, struct display *, void * ),
void (*emitTTYSess)( STRUCTUTMP *, struct display *, void * ) );
/* in inifile.c */
char *iniLoad( const char *fname );
int iniSave( const char *data, const char *fname );
char *iniEntry( char *data, const char *section, const char *key, const char *value );
char *iniMerge( char *data, const char *newdata );
/* in bootman.c */
int getBootOptions( char ***opts, int *def, int *cur );
int setBootOption( const char *opt, SdRec *sdr );
void commitBootOption( void );
/* in netaddr.c */
char *NetaddrAddress( char *netaddrp, int *lenp );
char *NetaddrPort( char *netaddrp, int *lenp );
int ConvertAddr( char *saddr, int *len, char **addr );
int NetaddrFamily( char *netaddrp );
int addressEqual( char *a1, int len1, char *a2, int len2 );
#ifdef XDMCP
/* in xdmcp.c */
char *NetworkAddressToHostname( CARD16 connectionType, ARRAY8Ptr connectionAddress );
void SendFailed( struct display *d, const char *reason );
void init_session_id( void );
/* in policy.c */
struct sockaddr;
ARRAY8Ptr Accept( struct sockaddr *from, int fromlen, CARD16 displayNumber );
ARRAY8Ptr ChooseAuthentication( ARRAYofARRAY8Ptr authenticationNames );
int CheckAuthentication( struct protoDisplay *pdpy, ARRAY8Ptr displayID, ARRAY8Ptr name, ARRAY8Ptr data );
int SelectAuthorizationTypeIndex( ARRAY8Ptr authenticationName, ARRAYofARRAY8Ptr authorizationNames );
int SelectConnectionTypeIndex( ARRAY16Ptr connectionTypes, ARRAYofARRAY8Ptr connectionAddresses );
int Willing( ARRAY8Ptr addr, CARD16 connectionType, ARRAY8Ptr authenticationName, ARRAY8Ptr status, xdmOpCode type );
/* in protodpy.c */
void DisposeProtoDisplay( struct protoDisplay *pdpy );
struct protoDisplay *FindProtoDisplay( XdmcpNetaddr address, int addrlen,
CARD16 displayNumber );
struct protoDisplay *NewProtoDisplay( XdmcpNetaddr address, int addrlen,
CARD16 displayNumber,
CARD16 connectionType,
ARRAY8Ptr connectionAddress,
CARD32 sessionID );
#define FamilyBroadcast 0xffff
typedef void (*ChooserFunc)( CARD16 connectionType, ARRAY8Ptr addr, char *closure );
typedef void (*ListenFunc)( ARRAY8Ptr addr, void **closure );
/* in access.c */
ARRAY8Ptr getLocalAddress( void );
int AcceptableDisplayAddress( ARRAY8Ptr clientAddress, CARD16 connectionType, xdmOpCode type );
int ForEachMatchingIndirectHost( ARRAY8Ptr clientAddress, CARD16 connectionType, ChooserFunc function, char *closure );
void ScanAccessDatabase( int force );
int UseChooser( ARRAY8Ptr clientAddress, CARD16 connectionType );
void ForEachChooserHost( ARRAY8Ptr clientAddress, CARD16 connectionType, ChooserFunc function, char *closure );
void ForEachListenAddr( ListenFunc listenfunction, ListenFunc mcastfcuntion, void **closure );
/* in choose.c */
ARRAY8Ptr IndirectChoice( ARRAY8Ptr clientAddress, CARD16 connectionType );
int IsIndirectClient( ARRAY8Ptr clientAddress, CARD16 connectionType );
int RememberIndirectClient( ARRAY8Ptr clientAddress, CARD16 connectionType );
void ForgetIndirectClient( ARRAY8Ptr clientAddress, CARD16 connectionType );
int RegisterIndirectChoice( ARRAY8Ptr clientAddress, CARD16 connectionType, ARRAY8Ptr choice );
int DoChoose( void );
/* socket.c or streams.c */
void UpdateListenSockets( void );
int AnyListenSockets( void );
int ProcessListenSockets( FD_TYPE *reads );
/* in xdmcp.c */
void ProcessRequestSocket( int fd );
#endif /* XDMCP */
/* in sessreg.c */
void sessreg( struct display *d, int pid, const char *user, int uid );
#endif /* _DM_H_ */
|