├── xdm ├── .gitignore ├── Makefile.am ├── daemon.c ├── rpcauth.c ├── mitauth.c ├── reset.c ├── error.c ├── protodpy.c ├── prngc.c ├── file.c ├── netaddr.c ├── krb5auth.c ├── util.c ├── dpylist.c ├── xdmauth.c ├── policy.c ├── server.c ├── choose.c └── resource.c ├── chooser ├── .gitignore └── Makefile.am ├── xdmshell ├── .gitignore ├── Makefile.am └── xdmshell.c ├── app-defaults ├── Makefile.am └── Chooser ├── config ├── Xsetup_0 ├── .gitignore ├── Xreset.in ├── Xstartup.in ├── TakeConsole ├── greeter ├── xdm ├── Xwilling ├── Xservers.fs ├── README ├── GiveConsole ├── Xservers.ws.in ├── xdm-config.in ├── Xsession.in ├── Makefile.am ├── Xresources.in └── Xaccess ├── include ├── Makefile.am ├── dm_socket.h ├── dm_error.h ├── dm_auth.h └── greet.h ├── dist.sh ├── xdm.service.in ├── rebuild.sh ├── autogen.sh ├── AUTHORS ├── greeter ├── Makefile.am ├── LoginP.h ├── Login.h └── verify.c ├── .gitignore ├── m4 └── ax_define_dir.m4 ├── man ├── Makefile.am └── xdmshell.man ├── README.md ├── Makefile.am └── COPYING /xdm/.gitignore: -------------------------------------------------------------------------------- 1 | xdm 2 | -------------------------------------------------------------------------------- /chooser/.gitignore: -------------------------------------------------------------------------------- 1 | chooser 2 | -------------------------------------------------------------------------------- /xdmshell/.gitignore: -------------------------------------------------------------------------------- 1 | xdmshell 2 | -------------------------------------------------------------------------------- /app-defaults/Makefile.am: -------------------------------------------------------------------------------- 1 | dist_appdefault_DATA = Chooser 2 | -------------------------------------------------------------------------------- /config/Xsetup_0: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail 3 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_HEADERS = \ 2 | dm.h \ 3 | dm_auth.h \ 4 | dm_error.h \ 5 | dm_socket.h \ 6 | greet.h 7 | -------------------------------------------------------------------------------- /config/.gitignore: -------------------------------------------------------------------------------- 1 | # Add & Override for this directory and it's subdirectories 2 | Xreset 3 | Xservers 4 | Xstartup 5 | Xresources 6 | Xservers.ws 7 | Xsession 8 | xdm-config 9 | -------------------------------------------------------------------------------- /config/Xreset.in: -------------------------------------------------------------------------------- 1 | XCOMM!/bin/sh 2 | XCOMM Deregister a login. (Derived from TakeConsole as follows:) 3 | XCOMM 4 | BINDIR/sessreg -d WTMP_FLAG UTMP_FLAG \ 5 | -x XDMCONFIGDIR/Xservers -l $DISPLAY -h "" $USER 6 | -------------------------------------------------------------------------------- /config/Xstartup.in: -------------------------------------------------------------------------------- 1 | XCOMM!/bin/sh 2 | XCOMM Register a login (derived from GiveConsole as follows:) 3 | XCOMM 4 | exec BINDIR/sessreg -a WTMP_FLAG UTMP_FLAG \ 5 | -x XDMCONFIGDIR/Xservers -l $DISPLAY -h "" $USER 6 | -------------------------------------------------------------------------------- /config/TakeConsole: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Reassign ownership of the console to root, this should disallow 3 | # assignment of console output to any random users's xterm 4 | # 5 | chown root /dev/console 6 | chmod 622 /dev/console 7 | -------------------------------------------------------------------------------- /dist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # a little script to create a distribution of the package 4 | 5 | [ -f Makefile ] && make distclean 6 | ./autogen.sh 7 | ./configure.sh 8 | make -j$(($(nproc 2>/dev/null||echo 4)<<1)) distcheck 9 | 10 | -------------------------------------------------------------------------------- /config/greeter: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | auth required pam_env.so 3 | auth required pam_permit.so 4 | account required pam_permit.so 5 | password required pam_deny.so 6 | session required pam_unix.so 7 | -session optional pam_systemd.so 8 | -------------------------------------------------------------------------------- /xdm.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=X-Window Display Manager 3 | After=systemd-user-sessions.service 4 | 5 | [Service] 6 | ExecStart=BINDIR/xdm -nodaemon 7 | Type=notify 8 | NotifyAccess=all 9 | 10 | [Install] 11 | Alias=graphical.target.wants/xdm.service 12 | -------------------------------------------------------------------------------- /rebuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # a little script to rebuild the package in your working directory 4 | 5 | rm -f cscope.* 6 | NOCONFIGURE=1 ./autogen.sh 7 | ./configure.sh 8 | make clean 9 | make cscope 10 | cscope -b 11 | make -j$(($(nproc 2>/dev/null||echo 4)<<1)) clean all README 12 | -------------------------------------------------------------------------------- /config/xdm: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | auth required pam_unix.so 3 | auth required pam_nologin.so 4 | auth required pam_env.so 5 | account required pam_unix.so 6 | password required pam_unix.so 7 | session required pam_unix.so 8 | session required pam_limits.so 9 | session required pam_loginuid.so 10 | -session optional pam_systemd.so 11 | -------------------------------------------------------------------------------- /config/Xwilling: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | 4 | # The output of this script is displayed in the chooser window. 5 | # (instead of "Willing to manage") 6 | 7 | load="`uptime|sed -e 's/^.*load[^0-9]*//'`" 8 | nrusers="`who|cut -c 1-8|sort -u|wc -l|sed 's/^[ ]*//'`" 9 | s=""; [ "$nrusers" != 1 ] && s=s 10 | 11 | echo "${nrusers} user${s}, load: ${load}" 12 | -------------------------------------------------------------------------------- /config/Xservers.fs: -------------------------------------------------------------------------------- 1 | # 2 | # Xservers file, fileserver prototype (any machine without a display) 3 | # 4 | # Put X terminals which don't support XDMCP in this file; you will 5 | # want to leave those terminals on and connected to the network, else 6 | # xdm will have a tougher time managing them. 7 | # 8 | # Each line should look like: 9 | # 10 | # XterminalName:0 foreign 11 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | srcdir=`dirname "$0"` 4 | test -z "$srcdir" && srcdir=. 5 | 6 | ORIGDIR=`pwd` 7 | cd "$srcdir" 8 | 9 | autoreconf -v --install || exit 1 10 | cd "$ORIGDIR" || exit $? 11 | 12 | git config --local --get format.subjectPrefix >/dev/null 2>&1 || 13 | git config --local format.subjectPrefix "PATCH app/xdm" 14 | 15 | if test -z "$NOCONFIGURE"; then 16 | exec "$srcdir"/configure "$@" 17 | fi 18 | -------------------------------------------------------------------------------- /config/README: -------------------------------------------------------------------------------- 1 | 2 | Xdm Sample Configuration 3 | 4 | This directory contains a collection of files which describe a sample 5 | configuration of xdm. Choose between the sample Xservers.* files; copy the 6 | appropriate one to "$(XDMDIR)/Xservers" along with the other 7 | files in this directory. 8 | 9 | Only a few of the many configuration parameters which xdm can be tuned with 10 | are set in this sample, read the xdm manual page for a complete description. 11 | -------------------------------------------------------------------------------- /chooser/Makefile.am: -------------------------------------------------------------------------------- 1 | xdmlibdir = $(XDMLIBDIR) 2 | xdmlib_PROGRAMS = chooser 3 | 4 | AM_CPPFLAGS = -I$(top_srcdir)/include 5 | AM_CFLAGS = $(CWARNFLAGS) $(CHOOSER_CFLAGS) 6 | AM_LDFLAGS = $(CHOOSER_LIBS) 7 | 8 | chooser_SOURCES = chooser.c 9 | 10 | if LINT 11 | ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) \ 12 | $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 13 | 14 | lint: 15 | $(LINT) $(ALL_LINT_FLAGS) $(chooser_SOURCES) $(AM_LDFLAGS) 16 | endif LINT 17 | -------------------------------------------------------------------------------- /config/GiveConsole: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Assign ownership of the console to the invoking user 3 | # 4 | # By convention, both xconsole and xterm -C check that the 5 | # console is owned by the invoking user and is readable before attaching 6 | # the console output. This way a random user can invoke xterm -C without 7 | # causing serious grief. 8 | # 9 | chown $USER /dev/console 10 | exec /usr/bin/sessreg -a -w "/var/log/wtmp" -u "/run/utmp" \ 11 | -x "/etc/X11/xdm/Xservers" -l $DISPLAY -h "" $USER 12 | -------------------------------------------------------------------------------- /xdmshell/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if INSTALL_XDMSHELL 3 | bin_PROGRAMS = xdmshell 4 | else 5 | noinst_PROGRAMS = xdmshell 6 | endif 7 | 8 | AM_CPPFLAGS = -I$(top_srcdir)/include 9 | AM_CFLAGS = \ 10 | $(CWARNFLAGS) \ 11 | $(XDMSHELL_CFLAGS) \ 12 | -DBINDIR="\"$(bindir)\"" 13 | 14 | xdmshell_SOURCES = xdmshell.c 15 | 16 | if LINT 17 | ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) \ 18 | $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 19 | 20 | lint: 21 | $(LINT) $(ALL_LINT_FLAGS) $(xdmshell_SOURCES) 22 | endif LINT 23 | 24 | -------------------------------------------------------------------------------- /config/Xservers.ws.in: -------------------------------------------------------------------------------- 1 | XCOMM 2 | XCOMM Xservers file, workstation prototype 3 | XCOMM 4 | XCOMM This file should contain an entry to start the server on the 5 | XCOMM local display; if you have more than one display (not screen), 6 | XCOMM you can add entries to the list (one per line). If you also 7 | XCOMM have some X terminals connected which do not support XDMCP, 8 | XCOMM you can add them here as well. Each X terminal line should 9 | XCOMM look like: 10 | XCOMM XTerminalName:0 foreign 11 | XCOMM 12 | :0 local BINDIR/X :0 DEFAULTVT 13 | :20 dynamic BINDIR/X :20 14 | :21 dynamic BINDIR/X :21 15 | :22 dynamic BINDIR/X :22 16 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Original authors credited in source files: 2 | 3 | Keith Packard, MIT X Consortium 4 | Jim Fulton, MIT X Consortium 5 | Stephen Gildea, The Open Group 6 | 7 | Later enhancements: 8 | 9 | Alan Coopersmith, Sun Microsystems: 10 | IPv6 support, Solaris authentication enhancements, 11 | PAM conversation rewrite 12 | 13 | Amit Margalit, Caolan McNamara, Ivan Griffin, Matthieu Herrb: 14 | 3D decoration & XPM pixmap display in login widget 15 | 16 | Dmitry Yu. Bolkhovityanov: 17 | Xinerama support 18 | 19 | Matthieu Herrb & OpenBSD Team: 20 | "allowRootLogin", OpenBSD authentication enhancements 21 | 22 | Werner Fink, SuSE: 23 | PAM support 24 | -------------------------------------------------------------------------------- /greeter/Makefile.am: -------------------------------------------------------------------------------- 1 | xdmlibdir = $(XDMLIBDIR) 2 | 3 | xdmlib_LTLIBRARIES = libXdmGreet.la 4 | 5 | libXdmGreet_la_SOURCES = \ 6 | Login.c \ 7 | Login.h \ 8 | LoginP.h \ 9 | greet.c \ 10 | verify.c 11 | 12 | libXdmGreet_la_LIBADD = $(XDMGREET_LIBS) 13 | 14 | AM_CPPFLAGS = -I$(top_srcdir)/include 15 | AM_CFLAGS = $(CWARNFLAGS) $(XDMGREET_CFLAGS) -DGREET_LIB 16 | 17 | libXdmGreet_la_LDFLAGS = -module -avoid-version -no-undefined 18 | 19 | if LINT 20 | ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 21 | $(AM_CPPFLAGS) $(CPPFLAGS) 22 | 23 | lint: 24 | $(LINT) $(ALL_LINT_FLAGS) $(libXdmGreet_la_SOURCES) 25 | 26 | endif LINT 27 | -------------------------------------------------------------------------------- /config/xdm-config.in: -------------------------------------------------------------------------------- 1 | ! 2 | ! 3 | ! 4 | ! 5 | ! 6 | DisplayManager.authDir: XDMXAUTHDIR 7 | DisplayManager.errorLogFile: XDMLOGDIR/xdm.log 8 | DisplayManager.pidFile: XDMPIDDIR/xdm.pid 9 | DisplayManager.keyFile: XDMCONFIGDIR/xdm-keys 10 | DisplayManager.servers: XDMCONFIGDIR/Xservers 11 | DisplayManager.accessFile: XDMCONFIGDIR/Xaccess 12 | DisplayManager*resources: XDMCONFIGDIR/Xresources 13 | DisplayManager.willing: SU nobody -s /bin/sh -c XDMSCRIPTDIR/Xwilling 14 | ! All displays should use authorization, but we cannot be sure 15 | ! X terminals may not be configured that way, so they will require 16 | ! individual resource settings. 17 | DisplayManager*authorize: true 18 | ! 19 | DisplayManager*chooser: CHOOSERPATH 20 | DisplayManager*startup: XDMSCRIPTDIR/Xstartup 21 | DisplayManager*session: XDMSCRIPTDIR/Xsession 22 | DisplayManager*reset: XDMSCRIPTDIR/Xreset 23 | DisplayManager*authComplain: true 24 | ! The following three resources set up display :0 as the console. 25 | DisplayManager._0.setup: XDMSCRIPTDIR/Xsetup_0 26 | DisplayManager._0.startup: XDMSCRIPTDIR/GiveConsole 27 | DisplayManager._0.reset: XDMSCRIPTDIR/TakeConsole 28 | #ifdef XPM 29 | DisplayManager*loginmoveInterval: 10 30 | #endif /* XPM */ 31 | ! SECURITY: do not listen for XDMCP or Chooser requests 32 | ! Comment out this line if you want to manage X terminals with xdm 33 | DisplayManager.requestPort: 0 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # X.Org module default exclusion patterns 3 | # The next section if for module specific patterns 4 | # 5 | # Do not edit the following section 6 | # GNU Build System (Autotools) 7 | aclocal.m4 8 | autom4te.cache/ 9 | autoscan.log 10 | ChangeLog 11 | compile 12 | config.guess 13 | config.h 14 | config.h.in 15 | config.log 16 | config-ml.in 17 | config.py 18 | config.status 19 | config.status.lineno 20 | config.sub 21 | configure 22 | configure.scan 23 | depcomp 24 | .deps/ 25 | INSTALL 26 | install-sh 27 | .libs/ 28 | libtool 29 | libtool.m4 30 | ltmain.sh 31 | lt~obsolete.m4 32 | ltoptions.m4 33 | ltsugar.m4 34 | ltversion.m4 35 | Makefile 36 | Makefile.in 37 | mdate-sh 38 | missing 39 | mkinstalldirs 40 | *.pc 41 | py-compile 42 | stamp-h? 43 | symlink-tree 44 | texinfo.tex 45 | ylwrap 46 | 47 | # Do not edit the following section 48 | # Edit Compile Debug Document Distribute 49 | *~ 50 | *.[0-9] 51 | *.[0-9]x 52 | *.bak 53 | *.bin 54 | core 55 | *.dll 56 | *.exe 57 | *-ISO*.bdf 58 | *-JIS*.bdf 59 | *-KOI8*.bdf 60 | *.kld 61 | *.ko 62 | *.ko.cmd 63 | *.lai 64 | *.l[oa] 65 | *.[oa] 66 | *.obj 67 | *.patch 68 | *.so 69 | *.pcf.gz 70 | *.pdb 71 | *.tar.bz2 72 | *.tar.gz 73 | # 74 | # Add & Override patterns for xdm 75 | # 76 | # Edit the following section as needed 77 | # For example, !report.pc overrides *.pc. See 'man gitignore' 78 | # 79 | xdm.service 80 | .*.sw[nop] 81 | cscope.* 82 | configure.sh 83 | core 84 | core.* 85 | *.log 86 | tags 87 | -------------------------------------------------------------------------------- /app-defaults/Chooser: -------------------------------------------------------------------------------- 1 | ! XDM chooser application defaults 2 | ! 3 | *ShapeStyle: Oval 4 | *cursor: left_ptr 5 | *allowShellResize: true 6 | *label.label: XDMCP Host Menu 7 | *label.borderWidth: 0 8 | *label.skipAdjust: true 9 | *paned*showGrip: false 10 | !*viewport.horizDistance: 20 11 | !*viewport.height: 200 12 | *viewport.width: 400 13 | *viewport.height: 50 14 | *viewport.allowVert: true 15 | *viewport.fromVert: label 16 | *viewport.resizeable: true 17 | *viewport.allowResize: true 18 | 19 | *list.translations: #override \ 20 | Return: Accept() \n\ 21 | : KeySwitch() \n\ 22 | : Store() Set() CheckWilling() Setold() \n\ 23 | (2): Accept() \n\ 24 | : BtnSwitch() \n\ 25 | : BtnSwitch() 26 | 27 | *list.defaultColumns: 1 28 | *list.forceColumns: true 29 | 30 | *box.skipAdjust: true 31 | *cancel.fromHoriz: viewport 32 | *cancel.fromVert: label 33 | *cancel.vertDistance: 100 34 | *cancel.bottom: ChainBottom 35 | *cancel.top: ChainBottom 36 | *cancel.left: ChainRight 37 | *cancel.right: ChainRight 38 | 39 | *accept.fromHoriz: viewport 40 | *accept.fromVert: cancel 41 | *accept.bottom: ChainBottom 42 | *accept.top: ChainBottom 43 | *accept.left: ChainRight 44 | *accept.right: ChainRight 45 | 46 | *cancel.translations: #override \ 47 | : Cancel() unset() 48 | *accept.translations: #override \ 49 | : Accept() unset() 50 | *ping.translations: #override \ 51 | : Ping() unset() 52 | -------------------------------------------------------------------------------- /config/Xsession.in: -------------------------------------------------------------------------------- 1 | XCOMM!SHELL_CMD 2 | XCOMM 3 | 4 | XCOMM redirect errors to a file in user's home directory if we can 5 | 6 | errfile="$HOME/.xsession-errors" 7 | if ( umask 077 && cp /dev/null "$errfile" 2> /dev/null ) 8 | then 9 | exec > "$errfile" 2>&1 10 | else 11 | mktemp="MKTEMP_COMMAND" 12 | if [ "x$mktemp" != "x" -a -x "$mktemp" ] 13 | then 14 | for errfile in "${TMPDIR-/tmp}/xses-$USER" "/tmp/xses-$USER" 15 | do 16 | if ef="$( umask 077 && $mktemp "$errfile.XXXXXX" 2> /dev/null)" 17 | then 18 | exec > "$ef" 2>&1 19 | mv "$ef" "$errfile" 2> /dev/null 20 | break 21 | fi 22 | done 23 | else 24 | XCOMM Since this system doesn't have a mktemp command to allow secure 25 | XCOMM creation of files in shared directories, no fallback error log 26 | XCOMM is being used. See https://bugs.freedesktop.org/show_bug.cgi?id=5898 27 | XCOMM 28 | XCOMM for errfile in "${TMPDIR-/tmp}/xses-$USER" "/tmp/xses-$USER" 29 | XCOMM do 30 | XCOMM if ( umask 077 && cp /dev/null "$errfile" 2> /dev/null ) 31 | XCOMM then 32 | XCOMM exec > "$errfile" 2>&1 33 | XCOMM break 34 | XCOMM fi 35 | XCOMM done 36 | 37 | exec > /dev/null 2>&1 38 | fi 39 | fi 40 | 41 | case $# in 42 | 1) 43 | case $1 in 44 | failsafe) 45 | exec BINDIR/xterm -geometry 80x24-0-0 46 | ;; 47 | esac 48 | esac 49 | 50 | XCOMM The startup script is not intended to have arguments. 51 | 52 | startup=$HOME/.xsession 53 | resources=$HOME/.Xresources 54 | xinitrc=$HOME/.xinitrc 55 | 56 | if [ -s "$startup" ]; then 57 | exec /bin/sh -ls -c "$startup" 58 | else 59 | if [ -r "$resources" ]; then 60 | BINDIR/xrdb -load "$resources" 61 | fi 62 | if [ -r "$xinitrc" ]; then 63 | exec /bin/sh -ls -c "$xinitrc" 64 | else 65 | exec /bin/sh -l /etc/X11/xinit/xinitrc 66 | fi 67 | fi 68 | -------------------------------------------------------------------------------- /m4/ax_define_dir.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_define_dir.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_DEFINE_DIR(VARNAME, DIR [, DESCRIPTION]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # This macro sets VARNAME to the expansion of the DIR variable, taking 12 | # care of fixing up ${prefix} and such. 13 | # 14 | # VARNAME is then offered as both an output variable and a C preprocessor 15 | # symbol. 16 | # 17 | # Example: 18 | # 19 | # AX_DEFINE_DIR([DATADIR], [datadir], [Where data are placed to.]) 20 | # 21 | # LICENSE 22 | # 23 | # Copyright (c) 2008 Stepan Kasal 24 | # Copyright (c) 2008 Andreas Schwab 25 | # Copyright (c) 2008 Guido U. Draheim 26 | # Copyright (c) 2008 Alexandre Oliva 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 6 34 | 35 | AU_ALIAS([AC_DEFINE_DIR], [AX_DEFINE_DIR]) 36 | AC_DEFUN([AX_DEFINE_DIR], [ 37 | prefix_NONE= 38 | exec_prefix_NONE= 39 | test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix 40 | test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix 41 | dnl In Autoconf 2.60, ${datadir} refers to ${datarootdir}, which in turn 42 | dnl refers to ${prefix}. Thus we have to use `eval' twice. 43 | eval ax_define_dir="\"[$]$2\"" 44 | eval ax_define_dir="\"$ax_define_dir\"" 45 | AC_SUBST($1, "$ax_define_dir") 46 | AC_DEFINE_UNQUOTED($1, "$ax_define_dir", [$3]) 47 | test "$prefix_NONE" && prefix=NONE 48 | test "$exec_prefix_NONE" && exec_prefix=NONE 49 | ]) 50 | -------------------------------------------------------------------------------- /include/dm_socket.h: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | 3 | Copyright 1998 by Thomas E. Dickey 4 | 5 | All Rights Reserved 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a 8 | copy of this software and associated documentation files (the 9 | "Software"), to deal in the Software without restriction, including 10 | without limitation the rights to use, copy, modify, merge, publish, 11 | distribute, sublicense, and/or sell copies of the Software, and to 12 | permit persons to whom the Software is furnished to do so, subject to 13 | the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included 16 | in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | Except as contained in this notice, the name(s) of the above copyright 27 | holders shall not be used in advertising or otherwise to promote the 28 | sale, use or other dealings in this Software without prior written 29 | authorization. 30 | 31 | ********************************************************/ 32 | 33 | #ifndef _DM_SOCKET_H_ 34 | # define _DM_SOCKET_H_ 1 35 | 36 | # include 37 | # include 38 | 39 | # include 40 | # include 41 | 42 | #if 0 43 | /* ugly, but we need this after socket.h */ 44 | extern ARRAY8Ptr Accept (struct sockaddr *from, int fromlen, CARD16 displayNumber); 45 | #endif 46 | 47 | # ifdef DEBUG 48 | extern void PrintSockAddr (struct sockaddr *a, int len); 49 | #endif 50 | 51 | #endif /* _DM_SOCKET_H_ */ 52 | -------------------------------------------------------------------------------- /include/dm_error.h: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | 3 | Copyright 1998 by Thomas E. Dickey 4 | 5 | All Rights Reserved 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a 8 | copy of this software and associated documentation files (the 9 | "Software"), to deal in the Software without restriction, including 10 | without limitation the rights to use, copy, modify, merge, publish, 11 | distribute, sublicense, and/or sell copies of the Software, and to 12 | permit persons to whom the Software is furnished to do so, subject to 13 | the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included 16 | in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | Except as contained in this notice, the name(s) of the above copyright 27 | holders shall not be used in advertising or otherwise to promote the 28 | sale, use or other dealings in this Software without prior written 29 | authorization. 30 | 31 | ********************************************************/ 32 | 33 | 34 | #ifndef _DM_ERROR_H_ 35 | # define _DM_ERROR_H_ 1 36 | 37 | extern void Debug (const char * fmt, ...) _X_ATTRIBUTE_PRINTF(1,2); 38 | extern void InitErrorLog (void); 39 | extern void LogAppend (const char * fmt, ...) _X_ATTRIBUTE_PRINTF(1,2); 40 | extern void LogError (const char * fmt, ...) _X_ATTRIBUTE_PRINTF(1,2); 41 | extern void LogInfo (const char * fmt, ...) _X_ATTRIBUTE_PRINTF(1,2); 42 | extern void LogOutOfMem (const char * fmt, ...) _X_ATTRIBUTE_PRINTF(1,2); 43 | extern void LogPanic (const char * fmt, ...) _X_ATTRIBUTE_PRINTF(1,2) _X_NORETURN; 44 | 45 | 46 | #endif /* _DM_ERROR_H_ */ 47 | -------------------------------------------------------------------------------- /man/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a 5 | # copy of this software and associated documentation files (the "Software"), 6 | # to deal in the Software without restriction, including without limitation 7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | # and/or sell copies of the Software, and to permit persons to whom the 9 | # Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice (including the next 12 | # paragraph) shall be included in all copies or substantial portions of the 13 | # Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | # DEALINGS IN THE SOFTWARE. 22 | # 23 | 24 | adminmandir = $(ADMIN_MAN_DIR) 25 | adminman_PRE = xdm.man 26 | adminman_DATA = $(adminman_PRE:man=$(ADMIN_MAN_SUFFIX)) 27 | 28 | xdmlmandir = $(ADMIN_MAN_DIR) 29 | xdmlman_PRE = xdmshell.man 30 | 31 | if INSTALL_XDMSHELL 32 | xdmlman_DATA = $(xdmlman_PRE:man=$(ADMIN_MAN_SUFFIX)) 33 | else 34 | noinst_DATA = $(xdmlman_PRE:man=$(ADMIN_MAN_SUFFIX)) 35 | endif 36 | 37 | EXTRA_DIST = $(adminman_PRE) $(xdmlman_PRE) 38 | CLEANFILES = $(adminman_DATA) $(xdmlman_DATA) $(noinst_DATA) 39 | SUFFIXES = .$(ADMIN_MAN_SUFFIX) .man 40 | 41 | # String replacements in MAN_SUBSTS now come from xorg-macros.m4 via configure 42 | MAN_SUBSTS += -e 's|CHOOSERPATH|$(XDMLIBDIR)/chooser|g' \ 43 | -e 's|XDMLOGDIR|$(XDMLOGDIR)|g' \ 44 | -e 's|XDMDIR|$(XDMCONFIGDIR)|g' \ 45 | -e 's|BINDIR|$(bindir)|g' \ 46 | -e 's|XDMPIDDIR|$(XDMPIDDIR)|g' \ 47 | -e 's|XDMXAUTHDIR|$(XDMXAUTHDIR)|g' \ 48 | -e 's|DEF_USER_PATH|$(DEF_USER_PATH)|g' \ 49 | -e 's|DEF_SYSTEM_PATH|$(DEF_SYSTEM_PATH)|g' \ 50 | -e 's|DEF_GREETER_LIB|$(DEF_GREETER_LIB)|g' \ 51 | -e 's|DEV_RANDOM|$(DEV_RANDOM)|g' \ 52 | -e 's|ARC4_RANDOM|$(HAVE_ARC4RANDOM)|g' 53 | 54 | .man.$(ADMIN_MAN_SUFFIX): 55 | $(AM_V_GEN)$(SED) $(MAN_SUBSTS) < $< > $@ 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The default installation settings of xdm match those used for most platforms 2 | in the previous X.Org releases: 3 | 4 | Scripts & modules: $(libdir)/X11/xdm (aka $(prefix)/lib/X11/xdm) 5 | Configuration files: $(libdir)/X11/xdm 6 | Pixmap files: $(libdir)/X11/xdm/pixmaps 7 | Log files: /var/log 8 | Process id/lock files: /var/run 9 | xauth cookie files: /var/lib/xdm 10 | 11 | These may be overridden with the following options to configure: 12 | 13 | Loadable modules: --with-xdmlibdir 14 | Scripts: --with-xdmscriptdir (or --with-xdmlibdir) 15 | Configuration files: --with-xdmconfigdir (or --with-xdmlibdir) 16 | Pixmap files: --with-xdmpixmapdir (or --with-xdmlibdir) 17 | Log files: --with-logdir 18 | Process id/lock files: --with-piddir 19 | xauth cookie files: --with-authdir 20 | 21 | For instance, some packagers/sites may prefer: 22 | 23 | --with-xdmconfigdir=/etc/X11/xdm 24 | --with-xdmlibdir=$(prefix)/lib/xdm 25 | --with-xdmscriptdir=/etc/X11/xdm 26 | 27 | The handling of --with-utmp-file & --with-wtmp-file have also changed 28 | slightly since previous versions of xdm: 29 | 30 | --with-{u,w}tmp-file 31 | [default] write records to utmp/wtmp files, but allow sessreg to 32 | use its builtin default paths. Omits -u/-w flag entirely from 33 | sessreg command in Xstartup & Xreset files. 34 | --with-{u,w}tmp-file= 35 | write records to utmp/wtmp files at specified filename. 36 | Passes filename as argument to sessreg -u/-w flag in Xstartup/Xreset. 37 | --without-{u,w}tmp-file or --with-{u,w}tmp-file=none 38 | Do not write records to utmp/wtmp files at all. 39 | Passes "none" as argument to sessreg -u/-w flag in Xstartup/Xreset. 40 | 41 | ------------------------------------------------------------------------ 42 | 43 | All questions regarding this software should be directed at the 44 | Xorg mailing list: 45 | 46 | https://lists.x.org/mailman/listinfo/xorg 47 | 48 | The master development code repository can be found at: 49 | 50 | https://gitlab.freedesktop.org/xorg/app/xdm 51 | 52 | Please submit bug reports and requests to merge patches there. 53 | 54 | For patch submission instructions, see: 55 | 56 | https://www.x.org/wiki/Development/Documentation/SubmittingPatches 57 | 58 | -------------------------------------------------------------------------------- /xdm/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Red Hat, Inc. 3 | # 4 | # Permission to use, copy, modify, distribute, and sell this software and its 5 | # documentation for any purpose is hereby granted without fee, provided that 6 | # the above copyright notice appear in all copies and that both that 7 | # copyright notice and this permission notice appear in supporting 8 | # documentation, and that the name of Red Hat not be used in 9 | # advertising or publicity pertaining to distribution of the software without 10 | # specific, written prior permission. Red Hat makes no 11 | # representations about the suitability of this software for any purpose. It 12 | # is provided "as is" without express or implied warranty. 13 | # 14 | # RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15 | # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16 | # EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17 | # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18 | # DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19 | # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 20 | # PERFORMANCE OF THIS SOFTWARE. 21 | 22 | bin_PROGRAMS = xdm 23 | 24 | AM_CPPFLAGS = -I$(top_srcdir)/include 25 | AM_CFLAGS = $(CWARNFLAGS) $(XDM_CFLAGS) $(SYSTEMD_DAEMON_CFLAGS) $(SYSTEMD_LOGIN_CFLAGS) 26 | 27 | # The xdm binary needs to export symbols so that they can be used from 28 | # libXdmGreet.so loaded through a dlopen call from session.c 29 | AM_LDFLAGS = $(XDM_LIBS) $(SYSTEMD_DAEMON_LIBS) $(SYSTEMD_LOGIN_LIBS) -export-dynamic 30 | 31 | xdm_SOURCES = \ 32 | access.c \ 33 | auth.c \ 34 | choose.c \ 35 | daemon.c \ 36 | dm.c \ 37 | dpylist.c \ 38 | error.c \ 39 | file.c \ 40 | genauth.c \ 41 | mitauth.c \ 42 | netaddr.c \ 43 | policy.c \ 44 | protodpy.c \ 45 | reset.c \ 46 | resource.c \ 47 | server.c \ 48 | session.c \ 49 | socket.c \ 50 | util.c \ 51 | xdmcp.c 52 | 53 | if HAS_XDM_AUTH 54 | AM_CFLAGS += -DHASXDMAUTH 55 | xdm_SOURCES += xdmauth.c 56 | endif 57 | 58 | if !HAVE_ARC4RANDOM 59 | xdm_SOURCES += prngc.c 60 | endif 61 | 62 | if HAS_SECURE_RPC 63 | AM_CFLAGS += -DSECURE_RPC 64 | xdm_SOURCES += rpcauth.c 65 | endif 66 | 67 | if HAS_KERBEROS_FIVE 68 | xdm_SOURCES += krb5auth.c 69 | endif 70 | 71 | if LINT 72 | ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) \ 73 | $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 74 | 75 | lint: 76 | $(LINT) $(ALL_LINT_FLAGS) $(xdm_SOURCES) $(XDM_LIBS) 77 | 78 | endif LINT 79 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2005 Red Hat, Inc. 3 | # 4 | # Permission to use, copy, modify, distribute, and sell this software and its 5 | # documentation for any purpose is hereby granted without fee, provided that 6 | # the above copyright notice appear in all copies and that both that 7 | # copyright notice and this permission notice appear in supporting 8 | # documentation, and that the name of Red Hat not be used in 9 | # advertising or publicity pertaining to distribution of the software without 10 | # specific, written prior permission. Red Hat makes no 11 | # representations about the suitability of this software for any purpose. It 12 | # is provided "as is" without express or implied warranty. 13 | # 14 | # RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15 | # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16 | # EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17 | # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18 | # DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19 | # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 20 | # PERFORMANCE OF THIS SOFTWARE. 21 | 22 | SUBDIRS = app-defaults chooser config greeter include man xdm xdmshell 23 | 24 | ACLOCAL_AMFLAGS = -I m4 25 | 26 | # This ensures distcheck is performed in a location where user has write access 27 | DISTCHECK_CONFIGURE_FLAGS = \ 28 | --with-appdefaultdir=\$${datadir}/X11/app-defaults \ 29 | --with-systemdsystemunitdir=\$${libdir}/systemd/system 30 | 31 | if LINT 32 | ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ 33 | $(AM_CPPFLAGS) $(CPPFLAGS) 34 | 35 | lint: 36 | $(LINT) $(ALL_LINT_FLAGS) $(xdm_CFLAGS) $(xdm_SOURCES) $(xdm_LIBS) 37 | (cd xdm && $(MAKE) $(AM_MAKEFLAGS) lint) 38 | (cd xdmshell && $(MAKE) $(AM_MAKEFLAGS) lint) 39 | (cd greeter && $(MAKE) $(AM_MAKEFLAGS) lint) 40 | (cd chooser && $(MAKE) $(AM_MAKEFLAGS) lint) 41 | endif LINT 42 | 43 | if HAVE_SYSTEMD 44 | systemdsystemunit_DATA = xdm.service 45 | 46 | xdm.service: xdm.service.in Makefile 47 | if USE_SYSTEMD_DAEMON 48 | $(AM_V_GEN)$(SED) -e 's|BINDIR|$(bindir)|g' < ${srcdir}/xdm.service.in > $@ 49 | else !USE_SYSTEMD_DAEMON 50 | $(AM_V_GEN)$(SED) -e 's|BINDIR|$(bindir)|g' -e '/[Nn]otify/d' < ${srcdir}/xdm.service.in > $@ 51 | endif !USE_SYSTEMD_DAEMON 52 | 53 | endif HAVE_SYSTEMD 54 | CLEANFILES = xdm.service 55 | EXTRA_DIST = xdm.service.in README.md 56 | 57 | MAINTAINERCLEANFILES = ChangeLog INSTALL 58 | 59 | .PHONY: ChangeLog INSTALL 60 | 61 | INSTALL: 62 | $(INSTALL_CMD) 63 | 64 | ChangeLog: 65 | $(CHANGELOG_CMD) 66 | 67 | dist-hook: ChangeLog INSTALL 68 | -------------------------------------------------------------------------------- /xdm/daemon.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | */ 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "dm.h" 41 | #include "dm_error.h" 42 | 43 | /* detach */ 44 | void 45 | BecomeDaemon (void) 46 | { 47 | 48 | /* If our C library has the daemon() function, just use it. */ 49 | #ifdef HAVE_DAEMON 50 | if (daemon (0, 0) < 0) { 51 | /* error */ 52 | LogError("daemon() failed, %s\n", _SysErrorMsg (errno)); 53 | exit(1); 54 | } 55 | #else 56 | switch (fork()) { 57 | case -1: 58 | /* error */ 59 | LogError("daemon fork failed, %s\n", _SysErrorMsg (errno)); 60 | exit(1); 61 | break; 62 | case 0: 63 | /* child */ 64 | break; 65 | default: 66 | /* parent */ 67 | exit(0); 68 | } 69 | 70 | if (setsid() == -1) { 71 | LogError("setting session id for daemon failed: %s\n", 72 | _SysErrorMsg (errno)); 73 | exit(1); 74 | } 75 | 76 | chdir("/"); 77 | 78 | close (0); 79 | close (1); 80 | close (2); 81 | 82 | 83 | /* 84 | * Set up the standard file descriptors. 85 | */ 86 | (void) open ("/dev/null", O_RDWR); 87 | (void) dup2 (0, 1); 88 | (void) dup2 (0, 2); 89 | #endif /* HAVE_DAEMON */ 90 | } 91 | -------------------------------------------------------------------------------- /xdm/rpcauth.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * rpcauth 34 | * 35 | * generate SecureRPC authorization records 36 | */ 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #include "dm.h" 43 | #include "dm_auth.h" 44 | #include "dm_error.h" 45 | 46 | /*ARGSUSED*/ 47 | void 48 | SecureRPCInitAuth (unsigned short name_len, char *name) 49 | { 50 | } 51 | 52 | Xauth * 53 | SecureRPCGetAuth ( 54 | unsigned short namelen, 55 | char *name) 56 | { 57 | char key[MAXNETNAMELEN+1]; 58 | Xauth *new; 59 | 60 | new = calloc (1, sizeof *new); 61 | if (!new) 62 | return (Xauth *) 0; 63 | new->family = FamilyWild; 64 | new->address_length = 0; 65 | new->address = 0; 66 | new->number_length = 0; 67 | new->number = 0; 68 | 69 | getnetname (key); 70 | Debug ("System netname %s\n", key); 71 | new->data_length = strlen(key); 72 | new->data = calloc (new->data_length, sizeof (*new->data)); 73 | if (!new->data) 74 | { 75 | free (new); 76 | return (Xauth *) 0; 77 | } 78 | new->name = calloc (namelen, sizeof (*new->name)); 79 | if (!new->name) 80 | { 81 | free (new->data); 82 | free (new); 83 | return (Xauth *) 0; 84 | } 85 | memmove( new->name, name, namelen); 86 | new->name_length = namelen; 87 | memmove( new->data, key, new->data_length); 88 | return new; 89 | } 90 | -------------------------------------------------------------------------------- /xdm/mitauth.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * mitauth 34 | * 35 | * generate authorization keys 36 | * for MIT-MAGIC-COOKIE-1 type authorization 37 | */ 38 | 39 | #include 40 | 41 | #include "dm.h" 42 | #include "dm_auth.h" 43 | 44 | #define AUTH_DATA_LEN 16 /* bytes of authorization data */ 45 | static char auth_name[256]; 46 | 47 | void 48 | MitInitAuth (unsigned short name_len, char *name) 49 | { 50 | if (name_len > 256) 51 | name_len = 256; 52 | memmove( auth_name, name, name_len); 53 | } 54 | 55 | Xauth * 56 | MitGetAuth (unsigned short namelen, char *name) 57 | { 58 | Xauth *new; 59 | new = calloc (1, sizeof (Xauth)); 60 | 61 | if (!new) 62 | return (Xauth *) 0; 63 | new->family = FamilyWild; 64 | new->address_length = 0; 65 | new->address = NULL; 66 | new->number_length = 0; 67 | new->number = NULL; 68 | 69 | new->data = calloc (AUTH_DATA_LEN, sizeof (*new->data)); 70 | if (!new->data) 71 | { 72 | free (new); 73 | return (Xauth *) 0; 74 | } 75 | new->name = calloc (namelen, sizeof (*new->name)); 76 | if (!new->name) 77 | { 78 | free (new->data); 79 | free (new); 80 | return (Xauth *) 0; 81 | } 82 | memmove( (char *)new->name, name, namelen); 83 | new->name_length = namelen; 84 | if (!GenerateAuthData (new->data, AUTH_DATA_LEN)) 85 | { 86 | free (new->name); 87 | free (new->data); 88 | free (new); 89 | return (Xauth *) 0; 90 | } 91 | new->data_length = AUTH_DATA_LEN; 92 | return new; 93 | } 94 | -------------------------------------------------------------------------------- /config/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | 3 | xdmscriptdir = $(XDMSCRIPTDIR) 4 | xdmconfigdir = $(XDMCONFIGDIR) 5 | 6 | dist_xdmconfig_DATA = \ 7 | Xaccess 8 | 9 | xdmconfig_DATA = \ 10 | xdm-config \ 11 | Xresources \ 12 | Xservers 13 | 14 | xdmscript_SCRIPTS = \ 15 | Xreset \ 16 | Xsession \ 17 | Xstartup 18 | 19 | dist_xdmscript_SCRIPTS = \ 20 | GiveConsole \ 21 | TakeConsole \ 22 | Xsetup_0 \ 23 | Xwilling 24 | 25 | #if USE_PAM 26 | 27 | pamdir = $(sysconfdir)/pam.d 28 | 29 | pam_DATA = xdm greeter 30 | 31 | #endif USE_PAM 32 | 33 | pixmapdir = $(XDM_PIXMAPDIR) 34 | 35 | dist_pixmap_DATA = xorg-bw.xpm xorg.xpm 36 | 37 | BUILT_SOURCES = Xservers.ws xdm-config Xreset Xresources Xsession Xstartup 38 | 39 | CLEANFILES = $(BUILT_SOURCES) Xservers 40 | 41 | EXTRA_DIST = Xservers.ws.in Xservers.fs \ 42 | xdm-config.in Xreset.in Xresources.in Xsession.in Xstartup.in 43 | 44 | Xservers: Xservers.$(SERVERSTYPE) 45 | ln -s Xservers.$(SERVERSTYPE) Xservers 46 | 47 | # Defines used when sed'ing config files to replace settings in the files 48 | 49 | if USE_XPM 50 | XPM_SED_FLAGS = -e '/ifdef XPM/d' -e '/endif \/\* XPM \*\//d' 51 | XPM_SED_FLAGS += -e 's|BITMAPDIR|$(XDM_PIXMAPDIR)|' 52 | XPM_SED_FLAGS += -e 's|XDM_PIXMAP|$(XDM_PIXMAP)|' 53 | XPM_SED_FLAGS += -e 's|XDM_BWPIXMAP|$(XDM_BWPIXMAP)|' 54 | else 55 | XPM_SED_FLAGS = -e '/ifdef XPM/,/endif \/\* XPM \*\//d' 56 | endif 57 | 58 | #if HAVE_MKTEMP_COMMAND 59 | MKTEMP_SED_FLAGS = -e 's|MKTEMP_COMMAND|$(MKTEMP_COMMAND)|' 60 | #endif 61 | 62 | if SET_UTMP_FILE 63 | UTMP_SED_FLAGS = -e 's|UTMP_FILE|$(UTMP_FILE)|' 64 | UTMP_SED_FLAGS += -e 's|UTMP_FLAG|-u $(UTMP_FILE)|' 65 | else 66 | UTMP_SED_FLAGS = -e 's|UTMP_FILE||' -e 's|UTMP_FLAG||' 67 | endif 68 | 69 | if SET_WTMP_FILE 70 | WTMP_SED_FLAGS = -e 's|WTMP_FILE|$(WTMP_FILE)|' 71 | WTMP_SED_FLAGS += -e 's|WTMP_FLAG|-w $(WTMP_FILE)|' 72 | else 73 | WTMP_SED_FLAGS = -e 's|WTMP_FILE||' -e 's|WTMP_FLAG||' 74 | endif 75 | 76 | SED_FILES_FLAGS = -e 's|BINDIR|$(bindir)|' 77 | SED_FILES_FLAGS += -e 's|DEFAULTVT|$(DEFAULTVT)|' 78 | SED_FILES_FLAGS += $(UTMP_SED_FLAGS) $(WTMP_SED_FLAGS) 79 | SED_FILES_FLAGS += -e 's|XDMDIR|$(XDMLIBDIR)|' 80 | SED_FILES_FLAGS += -e 's|XDMLOGDIR|$(XDMLOGDIR)|' 81 | SED_FILES_FLAGS += -e 's|XDMXAUTHDIR|$(XDMXAUTHDIR)|' 82 | SED_FILES_FLAGS += -e 's|XDMPIDDIR|$(XDMPIDDIR)|' 83 | SED_FILES_FLAGS += -e 's|XDMCONFIGDIR|$(XDMCONFIGDIR)|' 84 | SED_FILES_FLAGS += -e 's|XDMSCRIPTDIR|$(XDMSCRIPTDIR)|' 85 | SED_FILES_FLAGS += -e 's|SU|$(SU)|' 86 | SED_FILES_FLAGS += -e 's|CHOOSERPATH|$(XDMLIBDIR)/chooser|' 87 | SED_FILES_FLAGS += $(XPM_SED_FLAGS) 88 | SED_FILES_FLAGS += -e 's|SHELL_CMD|$(SHELL_CMD)|' 89 | SED_FILES_FLAGS += $(MKTEMP_SED_FLAGS) 90 | 91 | # Substitutions previously needed to work around the C pre-processor 92 | SED_CPP_FLAGS = -e 's|XCOMM|\#|' -e 's|XHASH|\#|' \ 93 | -e 's|NLBS|\\n\\|' -e 's|BS|\\|' -e 's|/\*\*/||g' 94 | 95 | SUFFIXES = .in 96 | 97 | .in: 98 | $(AM_V_GEN)$(SED) $(SED_FILES_FLAGS) $(SED_CPP_FLAGS) $< > $@ 99 | -------------------------------------------------------------------------------- /config/Xresources.in: -------------------------------------------------------------------------------- 1 | Xcursor.theme: whiteglass 2 | 3 | xlogin*login.translations: #override BS 4 | CtrlR: abort-display()NLBS 5 | F1: set-session-argument(failsafe) finish-field()NLBS 6 | Delete: delete-character()NLBS 7 | Left: move-backward-character()NLBS 8 | Right: move-forward-character()NLBS 9 | Home: move-to-begining()NLBS 10 | End: move-to-end()NLBS 11 | CtrlKP_Enter: set-session-argument(failsafe) finish-field()NLBS 12 | KP_Enter: set-session-argument() finish-field()NLBS 13 | CtrlReturn: set-session-argument(failsafe) finish-field()NLBS 14 | Return: set-session-argument() finish-field() 15 | 16 | xlogin*greeting: Welcome to CLIENTHOST 17 | xlogin*namePrompt: \040\040\040\040\040\040\040Login: 18 | xlogin*fail: Login incorrect or forbidden by policy 19 | 20 | XHASHif WIDTH > 800 21 | xlogin*greetFont: -adobe-helvetica-bold-o-normal--24-240-75-75-p-138-iso8859-1 22 | xlogin*font: -adobe-helvetica-medium-r-normal--18-180-75-75-p-98-iso8859-1 23 | xlogin*promptFont: -adobe-helvetica-bold-r-normal--18-180-75-75-p-103-iso8859-1 24 | xlogin*failFont: -adobe-helvetica-bold-r-normal--18-180-75-75-p-103-iso8859-1 25 | xlogin*greetFace: Serif-24:bold:italic 26 | xlogin*face: Helvetica-18 27 | xlogin*promptFace: Helvetica-18:bold 28 | xlogin*failFace: Helvetica-18:bold 29 | XHASHelse 30 | xlogin*greetFont: -adobe-helvetica-bold-o-normal--17-120-100-100-p-92-iso8859-1 31 | xlogin*font: -adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1 32 | xlogin*promptFont: -adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1 33 | xlogin*failFont: -adobe-helvetica-bold-o-normal--14-140-75-75-p-82-iso8859-1 34 | xlogin*greetFace: Serif-18:bold:italic 35 | xlogin*face: Helvetica-12 36 | xlogin*promptFace: Helvetica-12:bold 37 | xlogin*failFace: Helvetica-14:bold 38 | XHASHendif 39 | 40 | XHASHifdef COLOR 41 | xlogin*borderWidth: 1 42 | xlogin*frameWidth: 5 43 | xlogin*innerFramesWidth: 2 44 | xlogin*shdColor: grey30 45 | xlogin*hiColor: grey90 46 | xlogin*background: grey 47 | xlogin*inpColor: grey80 48 | !xlogin*foreground: darkgreen 49 | xlogin*greetColor: Blue3 50 | xlogin*failColor: red 51 | *Foreground: black 52 | *Background: #fffff0 53 | XHASHelse 54 | xlogin*borderWidth: 3 55 | xlogin*frameWidth: 0 56 | xlogin*innerFramesWidth: 1 57 | xlogin*shdColor: black 58 | xlogin*hiColor: black 59 | XHASHendif 60 | #ifdef XPM 61 | XHASHif PLANES >= 8 62 | xlogin*logoFileName: BITMAPDIR/**//XDM_PIXMAP 63 | XHASHelse 64 | xlogin*logoFileName: BITMAPDIR/**//XDM_BWPIXMAP 65 | XHASHendif 66 | xlogin*useShape: true 67 | xlogin*logoPadding: 10 68 | #endif /* XPM */ 69 | 70 | XConsole.text.geometry: 480x130 71 | XConsole.verbose: true 72 | XConsole*iconic: true 73 | XConsole*font: fixed 74 | 75 | Chooser*geometry: 700x500+300+200 76 | Chooser*allowShellResize: false 77 | Chooser*viewport.forceBars: true 78 | Chooser*label.font: *-new century schoolbook-bold-i-normal-*-240-* 79 | Chooser*label.label: XDMCP Host Menu from CLIENTHOST 80 | Chooser*list.font: -*-*-medium-r-normal-*-*-230-*-*-c-*-iso8859-1 81 | Chooser*Command.font: *-new century schoolbook-bold-r-normal-*-180-* 82 | -------------------------------------------------------------------------------- /xdm/reset.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * pseudoReset -- pretend to reset the server by killing all clients 34 | * with windows. It will reset the server most of the time, unless 35 | * a client remains connected with no windows. 36 | */ 37 | 38 | #include "dm.h" 39 | #include "dm_error.h" 40 | 41 | #include 42 | #include 43 | 44 | /*ARGSUSED*/ 45 | static int 46 | ignoreErrors (Display *dpy, XErrorEvent *event) 47 | { 48 | Debug ("ignoring error\n"); 49 | return 0; 50 | } 51 | 52 | /* 53 | * this is mostly bogus -- but quite useful. I wish the protocol 54 | * had some way of enumerating and identifying clients, that way 55 | * this code wouldn't have to be this kludgy. 56 | */ 57 | 58 | static void 59 | killWindows (Display *dpy, Window window) 60 | { 61 | Window root, parent, *children; 62 | int child; 63 | unsigned int nchildren = 0; 64 | 65 | while (XQueryTree (dpy, window, &root, &parent, &children, &nchildren) 66 | && nchildren > 0) 67 | { 68 | for (child = 0; child < nchildren; child++) { 69 | Debug ("XKillClient 0x%lx\n", (unsigned long)children[child]); 70 | XKillClient (dpy, children[child]); 71 | } 72 | XFree ((char *)children); 73 | } 74 | } 75 | 76 | static Jmp_buf resetJmp; 77 | 78 | /* ARGSUSED */ 79 | _X_NORETURN 80 | static void 81 | abortReset (int n) 82 | { 83 | Longjmp (resetJmp, 1); 84 | } 85 | 86 | /* 87 | * this display connection better not have any windows... 88 | */ 89 | 90 | void 91 | pseudoReset (Display *dpy) 92 | { 93 | Window root; 94 | int screen; 95 | 96 | if (Setjmp (resetJmp)) { 97 | LogError ("pseudoReset timeout\n"); 98 | } else { 99 | (void) Signal (SIGALRM, abortReset); 100 | (void) alarm (30); 101 | XSetErrorHandler (ignoreErrors); 102 | for (screen = 0; screen < ScreenCount (dpy); screen++) { 103 | Debug ("pseudoReset screen %d\n", screen); 104 | root = RootWindow (dpy, screen); 105 | killWindows (dpy, root); 106 | } 107 | Debug ("before XSync\n"); 108 | XSync (dpy, False); 109 | (void) alarm (0); 110 | } 111 | Signal (SIGALRM, SIG_DFL); 112 | XSetErrorHandler ((XErrorHandler)0 ); 113 | Debug ("pseudoReset done\n"); 114 | } 115 | -------------------------------------------------------------------------------- /xdm/error.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * error.c 34 | * 35 | * Log display manager errors to a file as 36 | * we generally do not have a terminal to talk to 37 | */ 38 | 39 | #include 40 | #include 41 | 42 | #include "dm.h" 43 | #include "dm_error.h" 44 | 45 | /* This function does the actual log message writes. */ 46 | static inline void _X_ATTRIBUTE_PRINTF(1,0) 47 | LogVWrite(const char *fmt, va_list args) 48 | { 49 | char buf[1024]; 50 | int len; 51 | 52 | len = vsnprintf (buf, sizeof(buf), fmt, args); 53 | if (len >= sizeof(buf)) { 54 | len = sizeof(buf) - 1; 55 | } 56 | if (write(STDERR_FILENO, buf, len)) ; 57 | } 58 | 59 | #define LogVarArgsWrite(fmt) \ 60 | do { \ 61 | va_list args; \ 62 | va_start(args, fmt); \ 63 | LogVWrite(fmt, args); \ 64 | va_end(args); \ 65 | } while(0) 66 | 67 | #define LogHeader(type) \ 68 | LogAppend("xdm %s (pid %ld): ", type, (long)getpid()) 69 | 70 | /* Append more text to the log without a new header, right after 71 | having called LogInfo or LogError */ 72 | void 73 | LogAppend(const char * fmt, ...) 74 | { 75 | LogVarArgsWrite(fmt); 76 | } 77 | 78 | void 79 | LogInfo(const char * fmt, ...) 80 | { 81 | LogHeader("info"); 82 | LogVarArgsWrite(fmt); 83 | } 84 | 85 | void 86 | LogError (const char * fmt, ...) 87 | { 88 | LogHeader("error"); 89 | LogVarArgsWrite(fmt); 90 | } 91 | 92 | void 93 | LogPanic (const char * fmt, ...) 94 | { 95 | LogHeader("panic"); 96 | LogVarArgsWrite(fmt); 97 | _exit (1); 98 | } 99 | 100 | void 101 | LogOutOfMem (const char * fmt, ...) 102 | { 103 | fprintf (stderr, "xdm: out of memory in routine "); 104 | { 105 | va_list args; 106 | va_start(args, fmt); 107 | vfprintf (stderr, fmt, args); 108 | va_end(args); 109 | } 110 | fflush (stderr); 111 | } 112 | 113 | void 114 | Debug (const char * fmt, ...) 115 | { 116 | if (debugLevel > 0) 117 | { 118 | LogVarArgsWrite(fmt); 119 | } 120 | } 121 | 122 | void 123 | InitErrorLog (void) 124 | { 125 | int i; 126 | if (errorLogFile[0]) { 127 | i = creat (errorLogFile, 0666); 128 | if (i != -1) { 129 | if (i != STDERR_FILENO) { 130 | dup2 (i, STDERR_FILENO); 131 | close (i); 132 | } 133 | } else 134 | LogError ("Cannot open errorLogFile %s\n", errorLogFile); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /config/Xaccess: -------------------------------------------------------------------------------- 1 | # 2 | # Access control file for XDMCP connections 3 | # 4 | # To control Direct and Broadcast access: 5 | # 6 | # pattern 7 | # 8 | # To control Indirect queries: 9 | # 10 | # pattern list of hostnames and/or macros ... 11 | # 12 | # To use the chooser: 13 | # 14 | # pattern CHOOSER BROADCAST 15 | # 16 | # or 17 | # 18 | # pattern CHOOSER list of hostnames and/or macros ... 19 | # 20 | # To define macros: 21 | # 22 | # %name list of hosts ... 23 | # 24 | # To control which addresses xdm listens for requests on: 25 | # 26 | # LISTEN address [list of multicast groups ... ] 27 | # 28 | # The first form tells xdm which displays to respond to itself. 29 | # The second form tells xdm to forward indirect queries from hosts matching 30 | # the specified pattern to the indicated list of hosts. 31 | # The third form tells xdm to handle indirect queries using the chooser; 32 | # the chooser is directed to send its own queries out via the broadcast 33 | # address and display the results on the terminal. 34 | # The fourth form is similar to the third, except instead of using the 35 | # broadcast address, it sends DirectQuerys to each of the hosts in the list 36 | # The fifth form tells xdm which addresses to listen for incoming connections 37 | # on. If present, xdm will only listen for connections on the specified 38 | # interfaces and/or multicast groups. 39 | # 40 | # In all cases, xdm uses the first entry which matches the terminal; 41 | # for IndirectQuery messages only entries with right hand sides can 42 | # match, for Direct and Broadcast Query messages, only entries without 43 | # right hand sides can match. 44 | # 45 | 46 | #* #any host can get a login window 47 | 48 | # 49 | # To hardwire a specific terminal to a specific host, you can 50 | # leave the terminal sending indirect queries to this host, and 51 | # use an entry of the form: 52 | # 53 | 54 | #terminal-a host-a 55 | 56 | 57 | # 58 | # The nicest way to run the chooser is to just ask it to broadcast 59 | # requests to the network - that way new hosts show up automatically. 60 | # Sometimes, however, the chooser can't figure out how to broadcast, 61 | # so this may not work in all environments. 62 | # 63 | 64 | #* CHOOSER BROADCAST #any indirect host can get a chooser 65 | 66 | # 67 | # If you'd prefer to configure the set of hosts each terminal sees, 68 | # then just uncomment these lines (and comment the CHOOSER line above) 69 | # and edit the %hostlist line as appropriate 70 | # 71 | 72 | #%hostlist host-a host-b 73 | 74 | #* CHOOSER %hostlist # 75 | 76 | # 77 | # If you have a machine with multiple network interfaces or IP addresses 78 | # you can control which interfaces accept XDMCP packets by listing a LISTEN 79 | # line for each interface you want to listen on. You can additionally list 80 | # one or more multicast groups after each address to listen on those groups 81 | # on that address. 82 | # 83 | # If no LISTEN is specified, the default is the same as "LISTEN *" - listen on 84 | # all unicast interfaces, but not for multicast packets. If any LISTEN lines 85 | # are specified, then only the listed interfaces will be listened on. 86 | # 87 | # IANA has assigned FF0X:0:0:0:0:0:0:12B as the permanently assigned 88 | # multicast addresses for XDMCP, where X in the prefix may be replaced 89 | # by any valid scope identifier, such as 1 for Node-Local, 2 for Link-Local, 90 | # 5 for Site-Local, and so on. The default is equivalent to the example shown 91 | # here using the Link-Local version to most closely match the old IPv4 subnet 92 | # broadcast behavior. 93 | # 94 | # LISTEN * ff02:0:0:0:0:0:0:12b 95 | 96 | # This example shows listening for multicast on all scopes up to site-local 97 | # 98 | # LISTEN * ff01:0:0:0:0:0:0:12b ff02:0:0:0:0:0:0:12b ff03:0:0:0:0:0:0:12b ff04:0:0:0:0:0:0:12b ff05:0:0:0:0:0:0:12b 99 | -------------------------------------------------------------------------------- /include/dm_auth.h: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | 3 | Copyright 1998 by Thomas E. Dickey 4 | 5 | All Rights Reserved 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a 8 | copy of this software and associated documentation files (the 9 | "Software"), to deal in the Software without restriction, including 10 | without limitation the rights to use, copy, modify, merge, publish, 11 | distribute, sublicense, and/or sell copies of the Software, and to 12 | permit persons to whom the Software is furnished to do so, subject to 13 | the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included 16 | in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | Except as contained in this notice, the name(s) of the above copyright 27 | holders shall not be used in advertising or otherwise to promote the 28 | sale, use or other dealings in this Software without prior written 29 | authorization. 30 | 31 | ********************************************************/ 32 | 33 | #ifndef _DM_AUTH_H_ 34 | # define _DM_AUTH_H_ 1 35 | 36 | # include "dm.h" /* for struct display */ 37 | 38 | extern void MitInitAuth (unsigned short name_len, char *name); 39 | extern Xauth *MitGetAuth (unsigned short namelen, char *name); 40 | 41 | # ifdef HASXDMAUTH 42 | extern void XdmInitAuth (unsigned short name_len, char *name); 43 | extern Xauth *XdmGetAuth (unsigned short namelen, char *name); 44 | # ifdef XDMCP 45 | extern void XdmGetXdmcpAuth ( 46 | struct protoDisplay *pdpy, 47 | unsigned short authorizationNameLen, 48 | char *authorizationName); 49 | extern int XdmCheckAuthentication (struct protoDisplay *pdpy, 50 | ARRAY8Ptr displayID, ARRAY8Ptr authenticationName, 51 | ARRAY8Ptr authenticationData); 52 | # else 53 | # define XdmGetXdmcpAuth NULL 54 | # endif 55 | # endif 56 | 57 | # ifdef SECURE_RPC 58 | extern void SecureRPCInitAuth (unsigned short name_len, char *name); 59 | extern Xauth *SecureRPCGetAuth (unsigned short namelen, char *name); 60 | # endif 61 | 62 | # ifdef K5AUTH 63 | extern void Krb5InitAuth (unsigned short name_len, char *name); 64 | extern Xauth *Krb5GetAuth (unsigned short namelen, char *name); 65 | # endif 66 | 67 | /* auth.c */ 68 | extern int ValidAuthorization (unsigned short name_length, char *name); 69 | 70 | 71 | # ifdef XDMCP 72 | 73 | extern void 74 | SetProtoDisplayAuthorization ( 75 | struct protoDisplay *pdpy, 76 | unsigned short authorizationNameLen, 77 | char *authorizationName); 78 | 79 | # endif /* XDMCP */ 80 | 81 | extern int SaveServerAuthorizations (struct display *d, Xauth **auths, int count); 82 | extern void CleanUpFileName (char *src, char *dst, int len); 83 | extern void RemoveUserAuthorization (struct display *d, struct verify_info *verify); 84 | extern void SetAuthorization (struct display *d); 85 | extern void SetLocalAuthorization (struct display *d); 86 | extern void SetUserAuthorization (struct display *d, struct verify_info *verify); 87 | 88 | /* genauth.c */ 89 | extern int GenerateAuthData (char *auth, int len); 90 | # if !defined(HAVE_ARC4RANDOM) 91 | extern void AddPreGetEntropy (void); 92 | extern void AddOtherEntropy (void); 93 | extern void AddTimerEntropy (void); 94 | # endif 95 | 96 | /* prngc.c */ 97 | extern int get_prngd_bytes(char *, int, unsigned short, char *); 98 | 99 | #endif /* _DM_AUTH_H_ */ 100 | -------------------------------------------------------------------------------- /xdmshell/xdmshell.c: -------------------------------------------------------------------------------- 1 | /* 2 | * xdmshell - simple program for running xdm from login 3 | * 4 | * 5 | Copyright 1988, 1998 The Open Group 6 | 7 | Permission to use, copy, modify, distribute, and sell this software and its 8 | documentation for any purpose is hereby granted without fee, provided that 9 | the above copyright notice appear in all copies and that both that 10 | copyright notice and this permission notice appear in supporting 11 | documentation. 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | Except as contained in this notice, the name of The Open Group shall not be 24 | used in advertising or otherwise to promote the sale, use or other dealings 25 | in this Software without prior written authorization from The Open Group. 26 | * * 27 | * Author: Jim Fulton, MIT X Consortium 28 | * 29 | * This program should probably be setuid to root. 30 | * 31 | * WARNING: Make sure that you tailor your Xresources file to have a 32 | * way of invoking the abort-display() action. Otherwise, you won't be able 33 | * bring down X when you are finished. 34 | */ 35 | 36 | 37 | #include 38 | #include "dm.h" 39 | #include 40 | #include 41 | 42 | #ifndef BINDIR 43 | # define BINDIR "/usr/bin/X11" 44 | #endif 45 | 46 | /* 47 | * HP-UX does have vfork, but A/UX doesn't 48 | */ 49 | #ifdef HAVE_WORKING_VFORK /* autoconf's preferred name */ 50 | # define HAS_VFORK 51 | #endif 52 | 53 | #ifndef HAS_VFORK 54 | # define vfork() fork() 55 | #endif 56 | 57 | static char *ProgramName; 58 | 59 | static int exec_args ( 60 | char *filename, 61 | char **args) 62 | { 63 | pid_t pid; 64 | waitType status; 65 | 66 | if (!filename) return -1; 67 | 68 | if (filename[0] != '/') { 69 | fprintf (stderr, 70 | "%s: attempt to execute program with relative pathname: %s\n", 71 | ProgramName, filename); 72 | return -1; 73 | } 74 | 75 | if (access (filename, X_OK) != 0) return -1; 76 | 77 | switch (pid = vfork ()) { 78 | case -1: /* error */ 79 | return -1; 80 | case 0: /* child */ 81 | execv (filename, args); 82 | _exit (1); 83 | /* NOTREACHED */ 84 | default: /* parent */ 85 | while (wait (&status) != pid) ; 86 | } 87 | return waitCode (status); 88 | } 89 | 90 | #if defined(sun) 91 | static int exec_one_arg ( 92 | char *filename, 93 | char *arg) 94 | { 95 | char *argv[3]; 96 | 97 | argv[0] = filename; 98 | argv[1] = arg; 99 | argv[2] = NULL; 100 | return exec_args (filename, argv); 101 | } 102 | #endif 103 | 104 | int 105 | main ( 106 | int argc, 107 | char *argv[]) 108 | { 109 | int ttyfd; 110 | char cmdbuf[256]; 111 | char *args[10]; 112 | 113 | ProgramName = argv[0]; 114 | 115 | if (argc > 1) { 116 | fprintf (stderr, "usage: %s\r\n", ProgramName); 117 | exit (1); 118 | } 119 | 120 | ttyfd = open ("/dev/tty", O_RDWR, 0); 121 | if (ttyfd < 3) { /* stdin = 0, stdout = 1, stderr = 2 */ 122 | fprintf (stderr, 123 | "%s: must be run directly from the console.\r\n", 124 | ProgramName); 125 | exit (1); 126 | } 127 | (void) close (ttyfd); 128 | 129 | /* make xdm run in a non-setuid environment */ 130 | if (setuid (geteuid()) == -1) { 131 | fprintf(stderr, "%s: cannot setuid (error %d, %s)\r\n", 132 | ProgramName, errno, strerror(errno)); 133 | exit(1); 134 | } 135 | 136 | /* 137 | * exec /usr/bin/X11/xdm -nodaemon -udpPort 0 138 | */ 139 | strcpy (cmdbuf, BINDIR); 140 | strcat (cmdbuf, "/xdm"); 141 | args[0] = cmdbuf; 142 | args[1] = "-nodaemon"; 143 | args[2] = "-udpPort"; 144 | args[3] = "0"; 145 | args[4] = NULL; 146 | if (exec_args (cmdbuf, args) == -1) { 147 | fprintf (stderr, "%s: unable to execute %s (error %d, %s)\r\n", 148 | ProgramName, cmdbuf, errno, strerror(errno)); 149 | exit (1); 150 | } 151 | 152 | #ifdef sun 153 | strcpy (cmdbuf, BINDIR); 154 | strcat (cmdbuf, "/kbd_mode"); 155 | (void) exec_one_arg (cmdbuf, "-a"); 156 | #endif 157 | 158 | exit (0); 159 | /*NOTREACHED*/ 160 | } 161 | -------------------------------------------------------------------------------- /xdm/protodpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | Copyright 1989, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | 21 | Except as contained in this notice, the name of The Open Group shall not be 22 | used in advertising or otherwise to promote the sale, use or other dealings 23 | in this Software without prior written authorization from The Open Group. 24 | * 25 | * Author: Keith Packard, MIT X Consortium 26 | */ 27 | 28 | /* 29 | * protodpy.c 30 | * 31 | * manage a collection of proto-displays. These are displays for 32 | * which sessionID's have been generated, but no session has been 33 | * started. 34 | */ 35 | 36 | #include "dm.h" 37 | #include "dm_error.h" 38 | #include "dm_socket.h" 39 | 40 | #ifdef XDMCP 41 | 42 | # include 43 | # include 44 | # define Time_t time_t 45 | 46 | static struct protoDisplay *protoDisplays; 47 | 48 | # ifdef DEBUG 49 | static void 50 | PrintProtoDisplay (struct protoDisplay *pdpy) 51 | { 52 | Debug ("ProtoDisplay %p\n", pdpy); 53 | Debug ("\taddress: %s", pdpy->address); 54 | //PrintSockAddr (pdpy->address, pdpy->addrlen); 55 | Debug ("\tdate %lu (%lu from now)\n", pdpy->date, time(0) - pdpy->date); 56 | Debug ("\tdisplay Number %d\n", pdpy->displayNumber); 57 | Debug ("\tsessionID %lu\n", (unsigned long)pdpy->sessionID); 58 | } 59 | # endif 60 | 61 | struct protoDisplay * 62 | FindProtoDisplay ( 63 | XdmcpNetaddr address, 64 | int addrlen, 65 | CARD16 displayNumber) 66 | { 67 | struct protoDisplay *pdpy; 68 | 69 | Debug ("FindProtoDisplay\n"); 70 | for (pdpy = protoDisplays; pdpy; pdpy=pdpy->next) 71 | { 72 | if (pdpy->displayNumber == displayNumber && 73 | addressEqual (address, addrlen, pdpy->address, pdpy->addrlen)) 74 | { 75 | return pdpy; 76 | } 77 | } 78 | return (struct protoDisplay *) 0; 79 | } 80 | 81 | static void 82 | TimeoutProtoDisplays (Time_t now) 83 | { 84 | struct protoDisplay *pdpy, *next; 85 | 86 | for (pdpy = protoDisplays; pdpy; pdpy = next) 87 | { 88 | next = pdpy->next; 89 | if (pdpy->date < now - PROTO_TIMEOUT) 90 | DisposeProtoDisplay (pdpy); 91 | } 92 | } 93 | 94 | struct protoDisplay * 95 | NewProtoDisplay ( 96 | XdmcpNetaddr address, 97 | int addrlen, 98 | CARD16 displayNumber, 99 | CARD16 connectionType, 100 | ARRAY8Ptr connectionAddress, 101 | CARD32 sessionID) 102 | { 103 | struct protoDisplay *pdpy; 104 | Time_t date; 105 | 106 | Debug ("NewProtoDisplay\n"); 107 | time (&date); 108 | TimeoutProtoDisplays (date); 109 | pdpy = calloc (1, sizeof (*pdpy)); 110 | if (!pdpy) 111 | return NULL; 112 | pdpy->address = calloc (addrlen, sizeof (*pdpy->address)); 113 | if (!pdpy->address) 114 | { 115 | free (pdpy); 116 | return NULL; 117 | } 118 | pdpy->addrlen = addrlen; 119 | memmove( pdpy->address, address, addrlen); 120 | pdpy->displayNumber = displayNumber; 121 | pdpy->connectionType = connectionType; 122 | pdpy->date = date; 123 | if (!XdmcpCopyARRAY8 (connectionAddress, &pdpy->connectionAddress)) 124 | { 125 | free (pdpy->address); 126 | free (pdpy); 127 | return NULL; 128 | } 129 | pdpy->sessionID = sessionID; 130 | pdpy->fileAuthorization = (Xauth *) NULL; 131 | pdpy->xdmcpAuthorization = (Xauth *) NULL; 132 | pdpy->next = protoDisplays; 133 | protoDisplays = pdpy; 134 | return pdpy; 135 | } 136 | 137 | void 138 | DisposeProtoDisplay (struct protoDisplay *pdpy) 139 | { 140 | struct protoDisplay *p, *prev; 141 | 142 | prev = NULL; 143 | for (p = protoDisplays; p; p=p->next) 144 | { 145 | if (p == pdpy) 146 | break; 147 | prev = p; 148 | } 149 | if (!p) 150 | return; 151 | if (prev) 152 | prev->next = pdpy->next; 153 | else 154 | protoDisplays = pdpy->next; 155 | bzero(&pdpy->key, sizeof(pdpy->key)); 156 | if (pdpy->fileAuthorization) 157 | XauDisposeAuth (pdpy->fileAuthorization); 158 | if (pdpy->xdmcpAuthorization) 159 | XauDisposeAuth (pdpy->xdmcpAuthorization); 160 | XdmcpDisposeARRAY8 (&pdpy->connectionAddress); 161 | free (pdpy->address); 162 | free (pdpy); 163 | } 164 | 165 | #endif /* XDMCP */ 166 | -------------------------------------------------------------------------------- /man/xdmshell.man: -------------------------------------------------------------------------------- 1 | .\" Copyright 1989 The Open Group 2 | .\" 3 | .\" Permission to use, copy, modify, distribute, and sell this software and its 4 | .\" documentation for any purpose is hereby granted without fee, provided that 5 | .\" the above copyright notice appear in all copies and that both that 6 | .\" copyright notice and this permission notice appear in supporting 7 | .\" documentation. 8 | .\" 9 | .\" The above copyright notice and this permission notice shall be included 10 | .\" in all copies or substantial portions of the Software. 11 | .\" 12 | .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 13 | .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 14 | .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 15 | .\" IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 16 | .\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 17 | .\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 18 | .\" OTHER DEALINGS IN THE SOFTWARE. 19 | .\" 20 | .\" Except as contained in this notice, the name of The Open Group shall 21 | .\" not be used in advertising or otherwise to promote the sale, use or 22 | .\" other dealings in this Software without prior written authorization 23 | .\" from The Open Group. 24 | .\" 25 | .\" Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 26 | .\" 27 | .\" Permission is hereby granted, free of charge, to any person obtaining a 28 | .\" copy of this software and associated documentation files (the "Software"), 29 | .\" to deal in the Software without restriction, including without limitation 30 | .\" the rights to use, copy, modify, merge, publish, distribute, sublicense, 31 | .\" and/or sell copies of the Software, and to permit persons to whom the 32 | .\" Software is furnished to do so, subject to the following conditions: 33 | .\" 34 | .\" The above copyright notice and this permission notice (including the next 35 | .\" paragraph) shall be included in all copies or substantial portions of the 36 | .\" Software. 37 | .\" 38 | .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 39 | .\" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 40 | .\" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 41 | .\" THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 42 | .\" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 43 | .\" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 44 | .\" DEALINGS IN THE SOFTWARE. 45 | .\" 46 | .\" 47 | .TH XDMSHELL __adminmansuffix__ __xorgversion__ 48 | .SH NAME 49 | xdmshell \- shell for starting xdm on login 50 | .SH SYNOPSIS 51 | .B BINDIR/xdmshell 52 | .SH DESCRIPTION 53 | .I Xdmshell 54 | can be used on systems that are configured to start a console in text mode by 55 | default, to allow users to start the X display manager by logging in as a 56 | special user with the shell set to the xdmshell program. 57 | .LP 58 | Many servers set the keyboard to do non-blocking I/O under the assumption that 59 | they are the only programs attempting to read from the keyboard. 60 | Unfortunately, some versions of \fIgetty\fP(__adminmansuffix__) will 61 | immediately see a continuous stream of zero-length reads which they interpret 62 | as end-of-file indicators. Eventually, \fIinit\fP(__adminmansuffix__) will 63 | disable logins on that line until somebody types the following as root: 64 | .RS 65 | \# kill -HUP 1 66 | .RE 67 | .LP 68 | On some platforms, one alternative is to disable logins on the console 69 | and always run \fIxdm\fP(__adminmansuffix__) from \fI/etc/inittab\fP. 70 | .LP 71 | Another approach is to set up an account whose shell is the \fIxdmshell\fP 72 | program found in the xdm distribution. This program is not installed by 73 | default so that site administrators will examine it to see if it meets their 74 | needs. The \fIxdmshell\fP utility makes sure that it is being run from the 75 | appropriate type of terminal, starts \fIxdm\fP, waits for it to finish, and 76 | then resets the console if necessary. If the \fIxdm\fP resources file 77 | (specified by the \fIDisplayManager*resources\fP entry in the 78 | \fIxdm-config\fP file) contains a binding to the \fIabort-display\fP action 79 | similar to the following 80 | .RS 81 | xlogin*login.translations: #override CtrlR: abort-display() 82 | .RE 83 | the console can then by restored by pressing the indicated key 84 | (Control-R in the above example) in the \fIxdm\fP login window. 85 | .LP 86 | .ne 10 87 | The \fIxdmshell\fP program is usually 88 | installed setuid to root but executable only by members of a special group, 89 | of which the only member is the account which has \fIxdmshell\fP as its shell: 90 | .RS 91 | .nf 92 | % grep xdm /etc/passwd 93 | x::101:51:Account for starting up X:/tmp:BINDIR/xdmshell 94 | % grep 51 /etc/group 95 | xdmgrp:*:51: 96 | % ls -lg BINDIR/xdmshell 97 | -rws--x--- 1 root xdmgrp 20338 Nov 1 01:32 BINDIR/xdmshell 98 | .fi 99 | .RE 100 | .LP 101 | If the \fIxdm\fP resources have not been configured to have a key bound to 102 | the \fIabort-display()\fP action, there will be no way for general users to 103 | login to the console directly. Whether or not this is desirable depends on 104 | the particular site. 105 | .SH "SEE ALSO" 106 | .IR X (__miscmansuffix__), 107 | .IR xdm (__adminmansuffix__), 108 | .IR xinit (__appmansuffix__) 109 | -------------------------------------------------------------------------------- /xdm/prngc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. 3 | * Copyright (c) 2001-2002 Damien Miller. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "dm_auth.h" 38 | #include "dm_error.h" 39 | 40 | #ifndef INADDR_LOOPBACK 41 | # define INADDR_LOOPBACK 0x7F000001U 42 | #endif 43 | 44 | static ssize_t atomicio(ssize_t (*)(int, void *, size_t), int, void *, size_t); 45 | 46 | static ssize_t 47 | voidwrite(int d, void *buf, size_t nbytes) 48 | { 49 | return write(d, buf, nbytes); 50 | } 51 | 52 | #ifndef offsetof 53 | # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 54 | #endif 55 | 56 | /* 57 | * Collect 'len' bytes of entropy into 'buf' from PRNGD/EGD daemon 58 | * listening either on 'tcp_port', or via Unix domain socket at * 59 | * 'socket_path'. 60 | * Either a non-zero tcp_port or a non-null socket_path must be 61 | * supplied. 62 | * Returns 0 on success, -1 on error 63 | */ 64 | int 65 | get_prngd_bytes(char *buf, int len, 66 | unsigned short tcp_port, char *socket_path) 67 | { 68 | int fd, addr_len, rval, errors; 69 | char msg[2]; 70 | struct sockaddr *addr; 71 | struct sockaddr_in addr_in; 72 | struct sockaddr_un addr_un; 73 | int af; 74 | void (*old_sigpipe)(int); 75 | 76 | /* Sanity checks */ 77 | if (socket_path == NULL && tcp_port == 0) { 78 | LogError("get_random_prngd: " 79 | "You must specify a port or a socket\n"); 80 | return -1; 81 | } 82 | if (socket_path != NULL && 83 | strlen(socket_path) >= sizeof(addr_un.sun_path)) { 84 | LogError("get_random_prngd: Random pool path is too long\n"); 85 | return -1; 86 | } 87 | if (len > 255) { 88 | LogError("get_random_prngd: " 89 | "Too many bytes to read from PRNGD\n"); 90 | return -1; 91 | } 92 | 93 | memset(&addr_in, '\0', sizeof(addr)); 94 | 95 | if (tcp_port != 0) { 96 | af = addr_in.sin_family = AF_INET; 97 | addr_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 98 | addr_in.sin_port = htons(tcp_port); 99 | addr_len = sizeof(addr_in); 100 | addr = (struct sockaddr *)&addr_in; 101 | } else { 102 | af = addr_un.sun_family = AF_UNIX; 103 | strncpy(addr_un.sun_path, socket_path, 104 | sizeof(addr_un.sun_path)); 105 | addr_len = offsetof(struct sockaddr_un, sun_path) + 106 | strlen(socket_path) + 1; 107 | addr = (struct sockaddr *)&addr_un; 108 | } 109 | 110 | old_sigpipe = signal(SIGPIPE, SIG_IGN); 111 | 112 | errors = 0; 113 | rval = -1; 114 | reopen: 115 | fd = socket(af, SOCK_STREAM, 0); 116 | if (fd == -1) { 117 | LogInfo("Couldn't create socket: %s\n", strerror(errno)); 118 | goto done; 119 | } 120 | 121 | if (connect(fd, (struct sockaddr*)addr, addr_len) == -1) { 122 | if (af == AF_INET) { 123 | LogInfo("Couldn't connect to PRNGD port %d: %s\n", 124 | tcp_port, strerror(errno)); 125 | } else { 126 | LogInfo("Couldn't connect to PRNGD socket" 127 | " \"%s\": %s\n", 128 | addr_un.sun_path, strerror(errno)); 129 | } 130 | goto done; 131 | } 132 | 133 | /* Send blocking read request to PRNGD */ 134 | msg[0] = 0x02; 135 | msg[1] = len; 136 | 137 | if (atomicio(voidwrite, fd, msg, sizeof(msg)) != sizeof(msg)) { 138 | if (errno == EPIPE && errors < 10) { 139 | close(fd); 140 | errors++; 141 | goto reopen; 142 | } 143 | LogInfo("Couldn't write to PRNGD socket: %s\n", 144 | strerror(errno)); 145 | goto done; 146 | } 147 | 148 | if (atomicio(read, fd, buf, len) != len) { 149 | if (errno == EPIPE && errors < 10) { 150 | close(fd); 151 | errors++; 152 | goto reopen; 153 | } 154 | LogInfo("Couldn't read from PRNGD socket: %s\n", 155 | strerror(errno)); 156 | goto done; 157 | } 158 | 159 | rval = 0; 160 | done: 161 | signal(SIGPIPE, old_sigpipe); 162 | if (fd != -1) 163 | close(fd); 164 | return rval; 165 | } 166 | 167 | /* 168 | * ensure all of data on socket comes through. f==read || f==write 169 | */ 170 | static ssize_t 171 | atomicio(ssize_t (*f)(int, void *, size_t), int fd, void *_s, size_t n) 172 | { 173 | char *s = _s; 174 | ssize_t res, pos = 0; 175 | 176 | while (n > pos) { 177 | res = (f) (fd, s + pos, n - pos); 178 | switch (res) { 179 | case -1: 180 | #ifdef EWOULDBLOCK 181 | if (errno == EINTR || errno == EAGAIN 182 | || errno == EWOULDBLOCK) 183 | #else 184 | if (errno == EINTR || errno == EAGAIN) 185 | #endif 186 | continue; 187 | case 0: 188 | return (res); 189 | default: 190 | pos += res; 191 | } 192 | } 193 | return (pos); 194 | } 195 | -------------------------------------------------------------------------------- /xdm/file.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * file.c 34 | */ 35 | 36 | #include "dm.h" 37 | #include "dm_error.h" 38 | 39 | #include 40 | 41 | static int 42 | DisplayTypeMatch (DisplayType d1, DisplayType d2) 43 | { 44 | return d1.location == d2.location && 45 | d1.lifetime == d2.lifetime && 46 | d1.origin == d2.origin; 47 | } 48 | 49 | static void 50 | freeFileArgs (char **args) 51 | { 52 | char **a; 53 | 54 | for (a = args; *a; a++) 55 | free (*a); 56 | free (args); 57 | } 58 | 59 | static char ** 60 | splitIntoWords (char *s) 61 | { 62 | char **args, **newargs; 63 | char *wordStart; 64 | int nargs; 65 | 66 | args = NULL; 67 | nargs = 0; 68 | while (*s) 69 | { 70 | while (*s && isspace (*s)) 71 | ++s; 72 | if (!*s || *s == '#') 73 | break; 74 | wordStart = s; 75 | while (*s && *s != '#' && !isspace (*s)) 76 | ++s; 77 | if (!args) 78 | { 79 | args = calloc (2, sizeof (*args)); 80 | if (!args) 81 | return NULL; 82 | } 83 | else 84 | { 85 | newargs = realloc ((char *) args, (nargs+2)*sizeof (char *)); 86 | if (!newargs) 87 | { 88 | freeFileArgs (args); 89 | return NULL; 90 | } 91 | args = newargs; 92 | } 93 | args[nargs] = calloc (s - wordStart + 1, sizeof (*args[nargs])); 94 | if (!args[nargs]) 95 | { 96 | freeFileArgs (args); 97 | return NULL; 98 | } 99 | strncpy (args[nargs], wordStart, s - wordStart); 100 | args[nargs][s-wordStart] = '\0'; 101 | ++nargs; 102 | args[nargs] = NULL; 103 | } 104 | return args; 105 | } 106 | 107 | static char ** 108 | copyArgs (char **args) 109 | { 110 | char **a, **new, **n; 111 | 112 | for (a = args; *a; a++) 113 | /* SUPPRESS 530 */ 114 | ; 115 | new = calloc ((a - args + 1), sizeof (*new)); 116 | if (!new) 117 | return NULL; 118 | n = new; 119 | a = args; 120 | /* SUPPRESS 560 */ 121 | while ((*n++ = *a++)) 122 | /* SUPPRESS 530 */ 123 | ; 124 | return new; 125 | } 126 | 127 | static void 128 | freeSomeArgs (char **args, int n) 129 | { 130 | char **a; 131 | 132 | a = args; 133 | while (n--) 134 | free (*a++); 135 | free (args); 136 | } 137 | 138 | void 139 | ParseDisplay (char *source, DisplayType *acceptableTypes, int numAcceptable) 140 | { 141 | char **args, **argv, **a; 142 | char *name, *class, *type; 143 | struct display *d; 144 | int usedDefault; 145 | DisplayType displayType; 146 | 147 | args = splitIntoWords (source); 148 | if (!args) 149 | return; 150 | if (!args[0]) 151 | { 152 | LogError ("Missing display name in servers file\n"); 153 | freeFileArgs (args); 154 | return; 155 | } 156 | name = args[0]; 157 | if (!args[1]) 158 | { 159 | LogError ("Missing display type for %s\n", args[0]); 160 | freeFileArgs (args); 161 | return; 162 | } 163 | displayType = parseDisplayType (args[1], &usedDefault); 164 | class = NULL; 165 | type = args[1]; 166 | argv = args + 2; 167 | /* 168 | * extended syntax; if the second argument doesn't 169 | * exactly match a legal display type and the third 170 | * argument does, use the second argument as the 171 | * display class string 172 | */ 173 | if (usedDefault && args[2]) 174 | { 175 | displayType = parseDisplayType (args[2], &usedDefault); 176 | if (!usedDefault) 177 | { 178 | class = args[1]; 179 | type = args[2]; 180 | argv = args + 3; 181 | } 182 | } 183 | while (numAcceptable) 184 | { 185 | if (DisplayTypeMatch (*acceptableTypes, displayType)) 186 | break; 187 | --numAcceptable; 188 | ++acceptableTypes; 189 | } 190 | if (!numAcceptable) 191 | { 192 | LogError ("Unacceptable display type %s for display %s\n", 193 | type, name); 194 | } 195 | d = FindDisplayByName (name); 196 | if (d) 197 | { 198 | d->state = OldEntry; 199 | if (class && strcmp (d->class, class)) 200 | { 201 | char *newclass; 202 | 203 | newclass = strdup (class); 204 | if (newclass) 205 | { 206 | free (d->class); 207 | d->class = newclass; 208 | } 209 | } 210 | Debug ("Found existing display: %s %s %s", d->name, d->class , type); 211 | freeFileArgs (d->argv); 212 | } 213 | else 214 | { 215 | d = NewDisplay (name, class); 216 | Debug ("Found new display: %s %s %s", 217 | d->name, d->class ? d->class : "", type); 218 | } 219 | d->displayType = displayType; 220 | d->argv = copyArgs (argv); 221 | for (a = d->argv; a && *a; a++) 222 | Debug (" %s", *a); 223 | Debug ("\n"); 224 | freeSomeArgs (args, argv - args); 225 | } 226 | 227 | static struct displayMatch { 228 | const char *name; 229 | DisplayType type; 230 | } displayTypes[] = { 231 | { "local", { Local, Permanent, FromFile } }, 232 | { "foreign", { Foreign, Permanent, FromFile } }, 233 | { "dynamic", { Local, Transient, FromFile } }, 234 | { NULL, { Local, Permanent, FromFile } }, 235 | }; 236 | 237 | DisplayType 238 | parseDisplayType (char *string, int *usedDefault) 239 | { 240 | struct displayMatch *d; 241 | 242 | for (d = displayTypes; d->name; d++) 243 | if (!strcmp (d->name, string)) 244 | { 245 | *usedDefault = 0; 246 | return d->type; 247 | } 248 | *usedDefault = 1; 249 | return d->type; 250 | } 251 | -------------------------------------------------------------------------------- /xdm/netaddr.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1991, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - X display manager 31 | * 32 | * netaddr.c - Interpretation of XdmcpNetaddr object. 33 | */ 34 | 35 | #include "dm.h" 36 | #include "dm_error.h" 37 | 38 | #include /* FamilyInternet, etc. */ 39 | 40 | #ifdef XDMCP 41 | 42 | # include "dm_socket.h" 43 | 44 | # if defined(IPv6) && defined(AF_INET6) 45 | # include 46 | # endif 47 | 48 | # ifdef UNIXCONN 49 | # include /* struct sockaddr_un */ 50 | # endif 51 | 52 | /* given an XdmcpNetaddr, returns the socket protocol family used, 53 | e.g., AF_INET */ 54 | 55 | int NetaddrFamily(XdmcpNetaddr netaddrp) 56 | { 57 | return ((struct sockaddr *)netaddrp)->sa_family; 58 | } 59 | 60 | 61 | /* given an XdmcpNetaddr, returns a pointer to the TCP/UDP port used 62 | and sets *lenp to the length of the address 63 | or 0 if not using TCP or UDP. */ 64 | 65 | char * NetaddrPort(XdmcpNetaddr netaddrp, int *lenp) 66 | { 67 | switch (NetaddrFamily(netaddrp)) 68 | { 69 | case AF_INET: 70 | *lenp = 2; 71 | return (char *)&(((struct sockaddr_in *)netaddrp)->sin_port); 72 | # if defined(IPv6) && defined(AF_INET6) 73 | case AF_INET6: 74 | *lenp = 2; 75 | return (char *)&(((struct sockaddr_in6 *)netaddrp)->sin6_port); 76 | # endif 77 | default: 78 | *lenp = 0; 79 | return NULL; 80 | } 81 | } 82 | 83 | 84 | /* given an XdmcpNetaddr, returns a pointer to the network address 85 | and sets *lenp to the length of the address */ 86 | 87 | char * NetaddrAddress(XdmcpNetaddr netaddrp, int *lenp) 88 | { 89 | switch (NetaddrFamily(netaddrp)) { 90 | # ifdef UNIXCONN 91 | case AF_UNIX: 92 | *lenp = strlen(((struct sockaddr_un *)netaddrp)->sun_path); 93 | return (char *) (((struct sockaddr_un *)netaddrp)->sun_path); 94 | # endif 95 | # ifdef TCPCONN 96 | case AF_INET: 97 | *lenp = sizeof (struct in_addr); 98 | return (char *) &(((struct sockaddr_in *)netaddrp)->sin_addr); 99 | # if defined(IPv6) && defined(AF_INET6) 100 | case AF_INET6: 101 | { 102 | struct in6_addr *a = &(((struct sockaddr_in6 *)netaddrp)->sin6_addr); 103 | if (IN6_IS_ADDR_V4MAPPED(a)) { 104 | *lenp = sizeof (struct in_addr); 105 | return ((char *) &(a->s6_addr))+12; 106 | } else { 107 | *lenp = sizeof (struct in6_addr); 108 | return (char *) &(a->s6_addr); 109 | } 110 | } 111 | # endif 112 | # endif 113 | # ifdef AF_CHAOS 114 | case AF_CHAOS: 115 | # endif 116 | default: 117 | *lenp = 0; 118 | return NULL; 119 | } 120 | } 121 | 122 | 123 | /* given an XdmcpNetaddr, sets *addr to the network address used and 124 | sets *len to the number of bytes in addr. 125 | Returns the X protocol family used, e.g., FamilyInternet */ 126 | 127 | int ConvertAddr (XdmcpNetaddr saddr, int *len, char **addr) 128 | { 129 | int retval; 130 | 131 | if ((len == NULL) || (saddr == NULL)) 132 | return -1; 133 | *addr = NetaddrAddress(saddr, len); 134 | switch (NetaddrFamily(saddr)) 135 | { 136 | # ifdef AF_UNSPEC 137 | case AF_UNSPEC: 138 | retval = FamilyLocal; 139 | break; 140 | # endif 141 | # ifdef AF_UNIX 142 | # ifndef hpux 143 | case AF_UNIX: 144 | retval = FamilyLocal; 145 | break; 146 | # endif 147 | # endif 148 | # ifdef TCPCONN 149 | case AF_INET: 150 | retval = FamilyInternet; 151 | break; 152 | # if defined(IPv6) && defined(AF_INET6) 153 | case AF_INET6: 154 | if (*len == sizeof(struct in_addr)) 155 | retval = FamilyInternet; 156 | else 157 | retval = FamilyInternet6; 158 | break; 159 | # endif 160 | # endif 161 | # ifdef AF_CHAOS 162 | case AF_CHAOS: 163 | retval = FamilyChaos; 164 | break; 165 | # endif 166 | default: 167 | retval = -1; 168 | break; 169 | } 170 | Debug ("ConvertAddr returning %d for family %d\n", retval, 171 | NetaddrFamily(saddr)); 172 | return retval; 173 | } 174 | 175 | int 176 | addressEqual (XdmcpNetaddr a1, int len1, XdmcpNetaddr a2, int len2) 177 | { 178 | int partlen1, partlen2; 179 | char *part1, *part2; 180 | 181 | if (len1 != len2) 182 | { 183 | return FALSE; 184 | } 185 | if (NetaddrFamily(a1) != NetaddrFamily(a2)) 186 | { 187 | return FALSE; 188 | } 189 | part1 = NetaddrPort(a1, &partlen1); 190 | part2 = NetaddrPort(a2, &partlen2); 191 | if (partlen1 != partlen2 || memcmp(part1, part2, partlen1) != 0) 192 | { 193 | return FALSE; 194 | } 195 | part1 = NetaddrAddress(a1, &partlen1); 196 | part2 = NetaddrAddress(a2, &partlen2); 197 | if (partlen1 != partlen2 || memcmp(part1, part2, partlen1) != 0) 198 | { 199 | return FALSE; 200 | } 201 | return TRUE; 202 | } 203 | 204 | # ifdef DEBUG 205 | /*ARGSUSED*/ 206 | void 207 | PrintSockAddr (struct sockaddr *a, int len) 208 | { 209 | unsigned char *t, *p; 210 | 211 | Debug ("family %d, ", a->sa_family); 212 | switch (a->sa_family) { 213 | # ifdef AF_INET 214 | case AF_INET: 215 | 216 | p = (unsigned char *) &((struct sockaddr_in *) a)->sin_port; 217 | t = (unsigned char *) &((struct sockaddr_in *) a)->sin_addr; 218 | 219 | Debug ("port %d, host %d.%d.%d.%d\n", 220 | (p[0] << 8) + p[1], t[0], t[1], t[2], t[3]); 221 | break; 222 | # endif 223 | # if defined(IPv6) && defined(AF_INET6) 224 | case AF_INET6: 225 | { 226 | char astr[INET6_ADDRSTRLEN] = ""; 227 | 228 | inet_ntop(a->sa_family, &((struct sockaddr_in6 *) a)->sin6_addr, 229 | astr, sizeof(astr)); 230 | p = (unsigned char *) &((struct sockaddr_in6 *) a)->sin6_port; 231 | 232 | Debug ("port %d, host %s\n", (p[0] << 8) + p[1], astr); 233 | break; 234 | } 235 | # endif 236 | } 237 | } 238 | # endif 239 | 240 | #endif /* XDMCP */ 241 | -------------------------------------------------------------------------------- /xdm/krb5auth.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1994, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Stephen Gildea, The Open Group 32 | */ 33 | 34 | /* 35 | * krb5auth 36 | * 37 | * generate Kerberos Version 5 authorization records 38 | */ 39 | 40 | #include "dm.h" 41 | #include "dm_error.h" 42 | 43 | #include 44 | #include 45 | #include 46 | #include /* for TGTNAME */ 47 | 48 | /*ARGSUSED*/ 49 | void 50 | Krb5InitAuth (unsigned short name_len, char *name) 51 | { 52 | krb5_init_ets(); /* initialize error_message() tables */ 53 | } 54 | 55 | /* 56 | * Returns malloc'ed string that is the credentials cache name. 57 | * name should be freed by caller. 58 | */ 59 | char * 60 | Krb5CCacheName(char *dname) 61 | { 62 | char *name; 63 | char *tmpdir; 64 | 65 | tmpdir = getenv("TMPDIR"); 66 | if (!tmpdir) 67 | tmpdir = "/tmp"; 68 | name = malloc(strlen(tmpdir) + strlen(dname) + 20); 69 | if (!name) 70 | return NULL; 71 | sprintf(name, "FILE:%s/K5C", tmpdir); 72 | CleanUpFileName(dname, name+strlen(name), strlen(dname)+1); 73 | return name; 74 | } 75 | 76 | krb5_error_code 77 | Krb5DisplayCCache(char *dname, krb5_ccache *ccache_return) 78 | { 79 | krb5_error_code code; 80 | char *name; 81 | 82 | name = Krb5CCacheName(dname); 83 | if (!name) 84 | return ENOMEM; 85 | Debug("resolving Kerberos cache %s\n", name); 86 | code = krb5_cc_resolve(name, ccache_return); 87 | free(name); 88 | return code; 89 | } 90 | 91 | Xauth * 92 | Krb5GetAuthFor(unsigned short namelen, char *name, char *dname) 93 | { 94 | Xauth *new; 95 | char *filename; 96 | struct stat statbuf; 97 | 98 | new = malloc (sizeof *new); 99 | if (!new) 100 | return (Xauth *) 0; 101 | new->family = FamilyWild; 102 | new->address_length = 0; 103 | new->address = 0; 104 | new->number_length = 0; 105 | new->number = 0; 106 | 107 | if (dname) 108 | { 109 | filename = Krb5CCacheName(dname); 110 | new->data = malloc (3 + strlen(filename) + 1); 111 | if (!new->data) 112 | { 113 | free (filename); 114 | free (new); 115 | return (Xauth *) 0; 116 | } 117 | strcpy(new->data, "UU:"); 118 | strcat(new->data, filename); 119 | free (filename); 120 | new->data_length = strlen(new->data); 121 | } 122 | else 123 | { 124 | new->data = NULL; 125 | new->data_length = 0; 126 | } 127 | 128 | new->name = malloc (namelen); 129 | if (!new->name) 130 | { 131 | free (new->data); 132 | free (new); 133 | return (Xauth *) 0; 134 | } 135 | memmove( new->name, name, namelen); 136 | new->name_length = namelen; 137 | return new; 138 | } 139 | 140 | Xauth * 141 | Krb5GetAuth (unsigned short namelen, char *name) 142 | { 143 | return Krb5GetAuthFor(namelen, name, NULL); 144 | } 145 | 146 | int preauth_search_list[] = { 147 | 0, 148 | KRB5_PADATA_ENC_TIMESTAMP, 149 | -1 150 | }; 151 | 152 | /* 153 | * Krb5Init - lifted from kinit.c 154 | * Get TGT. 155 | * Returns 0 if successful, 1 if not. 156 | */ 157 | int 158 | Krb5Init( 159 | char *name, 160 | char *passwd, 161 | struct display *d) /* k5_ccache filled in if successful */ 162 | { 163 | krb5_ccache ccache; 164 | krb5_error_code code; 165 | krb5_principal me; 166 | krb5_creds my_creds; 167 | krb5_principal server; 168 | krb5_address **my_addresses; 169 | krb5_timestamp now; 170 | int i; 171 | 172 | if (code = Krb5DisplayCCache(d->name, &ccache)) { 173 | LogError("%s while getting Krb5 ccache for \"%s\"\n", 174 | error_message(code), d->name); 175 | return 1; 176 | } 177 | 178 | if (code = krb5_parse_name (name, &me)) { 179 | LogError("%s while parsing Krb5 name \"%s\"\n", 180 | error_message(code), name); 181 | return 1; 182 | } 183 | 184 | code = krb5_cc_initialize (ccache, me); 185 | if (code != 0) { 186 | LogError("%s while initializing Krb5 cache \"%s\"\n", 187 | error_message(code), krb5_cc_default_name()); 188 | return 1; 189 | } 190 | 191 | memset((char *)&my_creds, 0, sizeof(my_creds)); 192 | 193 | my_creds.client = me; 194 | 195 | if (code = krb5_build_principal_ext(&server, 196 | krb5_princ_realm(me)->length, 197 | krb5_princ_realm(me)->data, 198 | 6, "krbtgt", 199 | krb5_princ_realm(me)->length, 200 | krb5_princ_realm(me)->data, 201 | 0)) { 202 | LogError("%s while building Krb5 TGT server name\n", 203 | error_message(code)); 204 | return 1; 205 | } 206 | 207 | my_creds.server = server; 208 | 209 | code = krb5_os_localaddr(&my_addresses); 210 | if (code != 0) { 211 | LogError("%s while getting my address for Krb5\n", 212 | error_message(code)); 213 | return 1; 214 | } 215 | if (code = krb5_timeofday(&now)) { 216 | LogError("%s while getting time of day for Krb5\n", 217 | error_message(code)); 218 | return 1; 219 | } 220 | my_creds.times.starttime = 0; /* start timer when request 221 | gets to KDC */ 222 | my_creds.times.endtime = now + 60*60*8; /* 8 hours */ 223 | my_creds.times.renew_till = 0; 224 | 225 | for (i = 0; preauth_search_list[i] >= 0; i++) { 226 | code = krb5_get_in_tkt_with_password(0, my_addresses, 227 | preauth_search_list[i], 228 | ETYPE_DES_CBC_CRC, 229 | KEYTYPE_DES, 230 | passwd, 231 | ccache, 232 | &my_creds, 0); 233 | if (code != KRB5KDC_PREAUTH_FAILED && 234 | code != KRB5KRB_ERR_GENERIC) 235 | break; 236 | } 237 | 238 | krb5_free_principal(server); 239 | krb5_free_addresses(my_addresses); 240 | 241 | if (code) { 242 | char *my_name = NULL; 243 | int code2 = krb5_unparse_name(me, &my_name); 244 | if (code == KRB5KRB_AP_ERR_BAD_INTEGRITY) { 245 | LogError ("password incorrect for Krb5 principal \"%s\"\n", 246 | code2 ? name : my_name); 247 | } 248 | else 249 | LogError("%s while getting initial Krb5 credentials for \"%s\"\n", 250 | error_message(code), code2 ? name : my_name); 251 | free (my_name); 252 | return 1; 253 | } 254 | krb5_cc_close(ccache); 255 | return 0; 256 | } 257 | -------------------------------------------------------------------------------- /xdm/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1989, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * util.c 34 | * 35 | * various utility routines 36 | */ 37 | 38 | #include "dm.h" 39 | #include "dm_error.h" 40 | 41 | #include /* for XmuGetHostname */ 42 | 43 | #ifdef X_POSIX_C_SOURCE 44 | # define _POSIX_C_SOURCE X_POSIX_C_SOURCE 45 | # include 46 | # undef _POSIX_C_SOURCE 47 | #else 48 | # if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE) 49 | # include 50 | # else 51 | # define _POSIX_SOURCE 52 | # include 53 | # undef _POSIX_SOURCE 54 | # endif 55 | #endif 56 | 57 | #ifndef HAVE_ASPRINTF 58 | # include 59 | /* Allocating sprintf found in many newer libc's 60 | * Since xdm is single threaded, assumes arguments don't change 61 | * between initial length calculation and copy to result buffer. 62 | */ 63 | int 64 | Asprintf(char ** ret, const char *restrict format, ...) 65 | { 66 | va_list ap; 67 | int len; 68 | char buf[256]; 69 | 70 | va_start(ap, format); 71 | len = vsnprintf(buf, sizeof(buf), format, ap); 72 | if (len >= 0) { 73 | *ret = calloc(len + 1, sizeof (**ret)); 74 | if (*ret) { 75 | if (len < sizeof(buf)) { 76 | memcpy(*ret, buf, len + 1); 77 | } else { 78 | vsnprintf(*ret, len + 1, format, ap); 79 | } 80 | } else { 81 | len = -1; 82 | } 83 | } else { 84 | *ret = NULL; 85 | } 86 | va_end(ap); 87 | 88 | return len; 89 | } 90 | #endif /* !HAVE_ASPRINTF */ 91 | 92 | void 93 | printEnv (char **e) 94 | { 95 | while (*e) 96 | Debug ("%s\n", *e++); 97 | } 98 | 99 | static char * 100 | makeEnv (const char *name, const char *value) 101 | { 102 | char *result; 103 | 104 | if (asprintf(&result, "%s=%s", name, value)) ; 105 | 106 | if (!result) { 107 | LogOutOfMem ("makeEnv"); 108 | return NULL; 109 | } 110 | return result; 111 | } 112 | 113 | char * 114 | getEnv (char **e, const char *name) 115 | { 116 | int l = strlen (name); 117 | 118 | if (!e) return NULL; 119 | 120 | while (*e) { 121 | if ((int)strlen (*e) > l && !strncmp (*e, name, l) && 122 | (*e)[l] == '=') 123 | return (*e) + l + 1; 124 | ++e; 125 | } 126 | return NULL; 127 | } 128 | 129 | char ** 130 | setEnv (char **e, const char *name, const char *value) 131 | { 132 | char **new, **old; 133 | char *newe; 134 | int envsize; 135 | int l; 136 | 137 | l = strlen (name); 138 | newe = makeEnv (name, value); 139 | if (!newe) { 140 | LogOutOfMem ("setEnv"); 141 | return e; 142 | } 143 | if (e) { 144 | for (old = e; *old; old++) 145 | if ((int)strlen (*old) > l && !strncmp (*old, name, l) && (*old)[l] == '=') 146 | break; 147 | if (*old) { 148 | free (*old); 149 | *old = newe; 150 | return e; 151 | } 152 | envsize = old - e; 153 | new = realloc ((char *) e, 154 | (unsigned) ((envsize + 2) * sizeof (char *))); 155 | } else { 156 | envsize = 0; 157 | new = calloc (2, sizeof (*new)); 158 | } 159 | if (!new) { 160 | LogOutOfMem ("setEnv"); 161 | free (newe); 162 | return e; 163 | } 164 | new[envsize] = newe; 165 | new[envsize+1] = NULL; 166 | return new; 167 | } 168 | 169 | char ** 170 | putEnv(const char *string, char **env) 171 | { 172 | char *v, *b, *n; 173 | int nl; 174 | 175 | if ((b = strchr(string, '=')) == NULL) 176 | return NULL; 177 | v = b + 1; 178 | 179 | nl = b - string; 180 | if ((n = calloc(nl + 1, sizeof (*n))) == NULL) 181 | { 182 | LogOutOfMem ("putAllEnv"); 183 | return NULL; 184 | } 185 | 186 | strncpy(n, string,nl + 1); 187 | n[nl] = 0; 188 | 189 | env = setEnv(env,n,v); 190 | free(n); 191 | return env; 192 | } 193 | 194 | void 195 | freeEnv (char **env) 196 | { 197 | char **e; 198 | 199 | if (env) 200 | { 201 | for (e = env; *e; e++) 202 | free (*e); 203 | free (env); 204 | } 205 | } 206 | 207 | #define isblank(c) ((c) == ' ' || c == '\t') 208 | 209 | char ** 210 | parseArgs (char **argv, const char *string) 211 | { 212 | const char *word; 213 | char *save; 214 | char **newargv; 215 | int i; 216 | 217 | i = 0; 218 | while (argv && argv[i]) 219 | ++i; 220 | if (!argv) { 221 | argv = calloc (1, sizeof (*argv)); 222 | if (!argv) { 223 | LogOutOfMem ("parseArgs"); 224 | return NULL; 225 | } 226 | } 227 | word = string; 228 | for (;;) { 229 | if (!*string || isblank (*string)) { 230 | if (word != string) { 231 | newargv = realloc ((char *) argv, 232 | (unsigned) ((i + 2) * sizeof (char *))); 233 | save = calloc ((unsigned) (string - word + 1), sizeof (*save)); 234 | if (!newargv || !save) { 235 | LogOutOfMem ("parseArgs"); 236 | /* free whichever survived realloc() */ 237 | free (newargv ? newargv : argv); 238 | free (save); 239 | return NULL; 240 | } else { 241 | argv = newargv; 242 | } 243 | argv[i] = strncpy (save, word, string-word); 244 | argv[i][string-word] = '\0'; 245 | i++; 246 | } 247 | if (!*string) 248 | break; 249 | word = string + 1; 250 | } 251 | ++string; 252 | } 253 | argv[i] = NULL; 254 | return argv; 255 | } 256 | 257 | void 258 | freeArgs (char **argv) 259 | { 260 | char **a; 261 | 262 | if (!argv) 263 | return; 264 | 265 | for (a = argv; *a; a++) 266 | free (*a); 267 | free (argv); 268 | } 269 | 270 | void 271 | CleanUpChild (void) 272 | { 273 | setsid(); 274 | #ifdef SIGCHLD 275 | (void) Signal (SIGCHLD, SIG_DFL); 276 | #endif 277 | (void) Signal (SIGTERM, SIG_DFL); 278 | (void) Signal (SIGPIPE, SIG_DFL); 279 | (void) Signal (SIGALRM, SIG_DFL); 280 | (void) Signal (SIGHUP, SIG_DFL); 281 | CloseOnFork (); 282 | } 283 | 284 | static char localHostbuf[256]; 285 | 286 | char * 287 | localHostname (void) 288 | { 289 | XmuGetHostname (localHostbuf, sizeof (localHostbuf) - 1); 290 | return localHostbuf; 291 | } 292 | 293 | void (*Signal (int sig, SIGFUNC handler))(int) 294 | { 295 | #ifdef HAVE_SIGACTION 296 | struct sigaction sigact, osigact; 297 | sigact.sa_handler = handler; 298 | sigemptyset(&sigact.sa_mask); 299 | sigact.sa_flags = 0; 300 | sigaction(sig, &sigact, &osigact); 301 | return osigact.sa_handler; 302 | #else /* __UNIXOS2__ */ 303 | return signal(sig, handler); 304 | #endif 305 | } 306 | -------------------------------------------------------------------------------- /xdm/dpylist.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * a simple linked list of known displays 34 | */ 35 | 36 | #include "dm.h" 37 | #include "dm_error.h" 38 | 39 | static struct display *displays; 40 | 41 | int 42 | AnyDisplaysLeft (void) 43 | { 44 | return displays != (struct display *) 0; 45 | } 46 | 47 | void 48 | ForEachDisplay (void (*f)(struct display *)) 49 | { 50 | struct display *d, *next; 51 | 52 | for (d = displays; d; d = next) { 53 | next = d->next; 54 | (*f) (d); 55 | } 56 | } 57 | 58 | int 59 | UntilDisplay (int (*f)(struct display *)) 60 | { 61 | struct display *d, *next; 62 | 63 | for (d = displays; d; d = next) { 64 | next = d->next; 65 | if ((*f) (d)) 66 | return 1; 67 | } 68 | return 0; 69 | } 70 | 71 | struct display * 72 | FindDisplayByName (char *name) 73 | { 74 | struct display *d; 75 | 76 | for (d = displays; d; d = d->next) 77 | if (!strcmp (name, d->name)) 78 | return d; 79 | return NULL; 80 | } 81 | 82 | struct display * 83 | FindDisplayByPid (pid_t pid) 84 | { 85 | struct display *d; 86 | 87 | for (d = displays; d; d = d->next) 88 | if (pid == d->pid) 89 | return d; 90 | return NULL; 91 | } 92 | 93 | struct display * 94 | FindDisplayByServerPid (pid_t serverPid) 95 | { 96 | struct display *d; 97 | 98 | for (d = displays; d; d = d->next) 99 | if (serverPid == d->serverPid) 100 | return d; 101 | return NULL; 102 | } 103 | 104 | #ifdef XDMCP 105 | 106 | struct display * 107 | FindDisplayBySessionID (CARD32 sessionID) 108 | { 109 | struct display *d; 110 | 111 | for (d = displays; d; d = d->next) 112 | if (sessionID == d->sessionID) 113 | return d; 114 | return NULL; 115 | } 116 | 117 | struct display * 118 | FindDisplayByAddress (XdmcpNetaddr addr, int addrlen, CARD16 displayNumber) 119 | { 120 | struct display *d; 121 | 122 | for (d = displays; d; d = d->next) 123 | if (d->displayType.origin == FromXDMCP && 124 | d->displayNumber == displayNumber && 125 | addressEqual (d->from, d->fromlen, addr, addrlen)) 126 | { 127 | return d; 128 | } 129 | return NULL; 130 | } 131 | 132 | #endif /* XDMCP */ 133 | 134 | void 135 | RemoveDisplay (struct display *old) 136 | { 137 | struct display *d, *p; 138 | char **x; 139 | int i; 140 | 141 | p = NULL; 142 | for (d = displays; d; d = d->next) { 143 | if (d == old) { 144 | if (p) 145 | p->next = d->next; 146 | else 147 | displays = d->next; 148 | free (d->name); 149 | free (d->class); 150 | for (x = d->argv; x && *x; x++) 151 | free (*x); 152 | free (d->argv); 153 | free (d->resources); 154 | free (d->xrdb); 155 | free (d->setup); 156 | free (d->startup); 157 | free (d->reset); 158 | free (d->session); 159 | free (d->userPath); 160 | free (d->systemPath); 161 | free (d->systemShell); 162 | free (d->failsafeClient); 163 | free (d->chooser); 164 | free (d->greeter); 165 | if (d->authorizations) 166 | { 167 | for (i = 0; i < d->authNum; i++) 168 | XauDisposeAuth (d->authorizations[i]); 169 | free (d->authorizations); 170 | } 171 | free (d->clientAuthFile); 172 | if (d->authFile) 173 | (void) unlink (d->authFile); 174 | free (d->authFile); 175 | free (d->userAuthDir); 176 | for (x = d->authNames; x && *x; x++) 177 | free (*x); 178 | free (d->authNames); 179 | free (d->authNameLens); 180 | #ifdef XDMCP 181 | free (d->peer); 182 | free (d->from); 183 | XdmcpDisposeARRAY8 (&d->clientAddr); 184 | #endif 185 | free (d->windowPath); 186 | #ifdef USE_SYSTEMD_LOGIN 187 | free (d->vtnr); 188 | free (d->seat); 189 | #endif 190 | free (d); 191 | break; 192 | } 193 | p = d; 194 | } 195 | } 196 | 197 | struct display * 198 | NewDisplay (char *name, char *class) 199 | { 200 | struct display *d; 201 | 202 | d = calloc (1, sizeof (struct display)); 203 | if (!d) { 204 | LogOutOfMem ("NewDisplay"); 205 | return NULL; 206 | } 207 | d->next = displays; 208 | d->name = strdup (name); 209 | if (!d->name) { 210 | LogOutOfMem ("NewDisplay"); 211 | free (d); 212 | return NULL; 213 | } 214 | if (class) 215 | { 216 | d->class = strdup (class); 217 | if (!d->class) { 218 | LogOutOfMem ("NewDisplay"); 219 | free (d->name); 220 | free (d); 221 | return NULL; 222 | } 223 | } 224 | else 225 | { 226 | d->class = NULL; 227 | } 228 | /* initialize every field to avoid possible problems */ 229 | d->argv = NULL; 230 | d->status = notRunning; 231 | d->pid = -1; 232 | d->serverPid = -1; 233 | d->state = NewEntry; 234 | d->resources = NULL; 235 | d->xrdb = NULL; 236 | d->setup = NULL; 237 | d->startup = NULL; 238 | d->reset = NULL; 239 | d->session = NULL; 240 | d->userPath = NULL; 241 | d->systemPath = NULL; 242 | d->systemShell = NULL; 243 | d->failsafeClient = NULL; 244 | d->chooser = NULL; 245 | d->greeter = NULL; 246 | d->authorize = FALSE; 247 | d->authorizations = NULL; 248 | d->authNum = 0; 249 | d->authNameNum = 0; 250 | d->clientAuthFile = NULL; 251 | d->authFile = NULL; 252 | d->userAuthDir = NULL; 253 | d->authNames = NULL; 254 | d->authNameLens = NULL; 255 | d->authComplain = 1; 256 | d->openDelay = 0; 257 | d->openRepeat = 0; 258 | d->openTimeout = 0; 259 | d->startAttempts = 0; 260 | d->startTries = 0; 261 | d->lastReserv = 0; 262 | d->reservAttempts = 0; 263 | d->reservTries = 0; 264 | d->terminateServer = 0; 265 | d->grabTimeout = 0; 266 | #ifdef XDMCP 267 | d->sessionID = 0; 268 | d->peer = NULL; 269 | d->peerlen = 0; 270 | d->from = NULL; 271 | d->fromlen = 0; 272 | d->displayNumber = 0; 273 | d->useChooser = 0; 274 | d->clientAddr.data = NULL; 275 | d->clientAddr.length = 0; 276 | d->connectionType = 0; 277 | d->xdmcpFd = -1; 278 | #endif 279 | d->version = 1; /* registered with The Open Group */ 280 | d->willing = NULL; 281 | d->dpy = NULL; 282 | d->windowPath = NULL; 283 | #ifdef USE_SYSTEMD_LOGIN 284 | d->vtnr = NULL; 285 | d->seat = NULL; 286 | #endif 287 | displays = d; 288 | return d; 289 | } 290 | -------------------------------------------------------------------------------- /greeter/LoginP.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | /* 29 | * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 30 | * 31 | * Permission is hereby granted, free of charge, to any person obtaining a 32 | * copy of this software and associated documentation files (the "Software"), 33 | * to deal in the Software without restriction, including without limitation 34 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 35 | * and/or sell copies of the Software, and to permit persons to whom the 36 | * Software is furnished to do so, subject to the following conditions: 37 | * 38 | * The above copyright notice and this permission notice (including the next 39 | * paragraph) shall be included in all copies or substantial portions of the 40 | * Software. 41 | * 42 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 45 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 47 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 48 | * DEALINGS IN THE SOFTWARE. 49 | */ 50 | 51 | /* 52 | * xdm - display manager daemon 53 | * Author: Keith Packard, MIT X Consortium 54 | */ 55 | 56 | #ifndef _LoginP_h 57 | # define _LoginP_h 58 | 59 | # include "Login.h" 60 | # include 61 | # include 62 | # include 63 | # ifdef USE_XFT 64 | # include 65 | # endif 66 | 67 | # define INITIALIZING 0 68 | # define PROMPTING 1 69 | # define SHOW_MESSAGE 2 70 | # define DONE 3 71 | 72 | typedef void (*LoginFunc)(LoginWidget, LoginData *, int); 73 | 74 | typedef struct { 75 | char * promptText; /* Prompt displayed */ 76 | const char * defaultPrompt; /* Default text for prompt */ 77 | char * valueText; /* Value entered for prompt */ 78 | size_t valueTextMax; /* Size of valueText buffer */ 79 | int valueShownStart;/* Amount of string shown if too */ 80 | int valueShownEnd; /* long to fit in field */ 81 | int cursor; /* current cursor position */ 82 | loginPromptState state; 83 | } loginPromptData; 84 | 85 | # define NUM_PROMPTS 2 /* Currently only 2 prompt fields supported */ 86 | # define LAST_PROMPT (NUM_PROMPTS - 1) 87 | 88 | /* New fields for the login widget instance record */ 89 | typedef struct { 90 | # ifndef USE_XFT 91 | Pixel textpixel; /* foreground pixel */ 92 | Pixel promptpixel; /* prompt pixel */ 93 | Pixel greetpixel; /* greeting pixel */ 94 | Pixel failpixel; /* failure pixel */ 95 | # endif 96 | Pixel hipixel; /* frame hilite pixel */ 97 | Pixel shdpixel; /* shadow frame pixel */ 98 | Pixel inppixel; /* input field bg pixel */ 99 | GC textGC; /* pointer to GraphicsContext */ 100 | GC bgGC; /* pointer to GraphicsContext */ 101 | GC xorGC; /* pointer to GraphicsContext */ 102 | # ifndef USE_XFT 103 | GC promptGC; 104 | GC greetGC; 105 | GC failGC; 106 | # endif 107 | GC hiGC; /* for hilight part of frame */ 108 | GC shdGC; /* for shaded part of frame */ 109 | GC inpGC; /* for input field of frame */ 110 | char *greeting; /* greeting */ 111 | char *unsecure_greet;/* message displayed when insecure */ 112 | char *namePrompt; /* name prompt */ 113 | char *passwdPrompt; /* password prompt */ 114 | char *failMsg; /* failure message */ 115 | char *fail; /* current error message */ 116 | char *passwdChangeMsg; /* message when passwd expires */ 117 | # ifndef USE_XFT 118 | XFontStruct *textFont; /* font for text */ 119 | XFontStruct *promptFont; /* font for prompts */ 120 | XFontStruct *greetFont; /* font for greeting */ 121 | XFontStruct *failFont; /* font for failure message */ 122 | # endif /* USE_XFT */ 123 | int state; /* state */ 124 | int activePrompt; /* which prompt is active */ 125 | int failUp; /* failure message displayed */ 126 | LoginData data; /* name/passwd */ 127 | char *sessionArg; /* argument passed to session */ 128 | LoginFunc notify_done; /* proc to call when done */ 129 | int failTimeout; /* seconds til drop fail msg */ 130 | XtIntervalId interval_id; /* drop fail message note */ 131 | Boolean secure_session; /* session is secured */ 132 | Boolean allow_access; /* disable access control on login */ 133 | Boolean allow_null_passwd; /* allow null password on login */ 134 | Boolean allow_root_login; /* allow root login */ 135 | /* option to display characters such as asterisks, i.e. '**...' 136 | for no-echo prompts like passwords */ 137 | Boolean echo_passwd; 138 | char * echo_passwd_char; 139 | XIC xic; /* input method of input context */ 140 | loginPromptData prompts[NUM_PROMPTS]; 141 | time_t msgTimeout; 142 | 143 | # ifdef DANCING 144 | /*caolan begin*/ 145 | int lastEventTime; 146 | /*caolan end*/ 147 | # endif /* DANCING */ 148 | 149 | int outframewidth; /* outer frame thickness */ 150 | int inframeswidth; /* inner frames thickness */ 151 | int sepwidth; /* width of separator line */ 152 | 153 | # ifdef XPM 154 | char *logoFileName; 155 | unsigned int logoWidth, logoHeight, logoPadding, logoBorderWidth; 156 | int logoX, logoY; 157 | Window logoWindow; 158 | Boolean useShape, logoValid; 159 | Pixmap logoPixmap, logoMask; 160 | # endif /* XPM */ 161 | # ifdef USE_XFT 162 | XftDraw *draw; 163 | XftFont *textFace; /* font for text */ 164 | XftFont *promptFace; /* font for prompts */ 165 | XftFont *greetFace; /* font for greeting */ 166 | XftFont *failFace; /* font for failure message */ 167 | XftColor textcolor; /* foreground color */ 168 | XftColor promptcolor; /* prompt color */ 169 | XftColor greetcolor; /* greeting color */ 170 | XftColor failcolor; /* failure color */ 171 | # endif 172 | } LoginPart; 173 | 174 | /* Full instance record declaration */ 175 | typedef struct _LoginRec { 176 | CorePart core; 177 | LoginPart login; 178 | } LoginRec; 179 | 180 | /* New fields for the Login widget class record */ 181 | typedef struct {int dummy;} LoginClassPart; 182 | 183 | /* Full class record declaration. */ 184 | typedef struct _LoginClassRec { 185 | CoreClassPart core_class; 186 | LoginClassPart login_class; 187 | } LoginClassRec; 188 | 189 | /* Class pointer. */ 190 | extern LoginClassRec loginClassRec; 191 | 192 | #endif /* _LoginP_h */ 193 | -------------------------------------------------------------------------------- /greeter/Login.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | /* 29 | * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 30 | * 31 | * Permission is hereby granted, free of charge, to any person obtaining a 32 | * copy of this software and associated documentation files (the "Software"), 33 | * to deal in the Software without restriction, including without limitation 34 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 35 | * and/or sell copies of the Software, and to permit persons to whom the 36 | * Software is furnished to do so, subject to the following conditions: 37 | * 38 | * The above copyright notice and this permission notice (including the next 39 | * paragraph) shall be included in all copies or substantial portions of the 40 | * Software. 41 | * 42 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 45 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 47 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 48 | * DEALINGS IN THE SOFTWARE. 49 | */ 50 | 51 | /* 52 | * xdm - display manager daemon 53 | * Author: Keith Packard, MIT X Consortium 54 | */ 55 | 56 | 57 | #ifndef _XtLogin_h 58 | # define _XtLogin_h 59 | 60 | /*********************************************************************** 61 | * 62 | * Login Widget 63 | * 64 | ***********************************************************************/ 65 | 66 | /* Parameters: 67 | 68 | Name Class RepType Default Value 69 | ---- ----- ------- ------------- 70 | background Background pixel White 71 | border BorderColor pixel Black 72 | borderWidth BorderWidth int 1 73 | foreground Foreground Pixel Black 74 | height Height int 120 75 | mappedWhenManaged MappedWhenManaged Boolean True 76 | width Width int 120 77 | x Position int 0 78 | y Position int 0 79 | 80 | */ 81 | 82 | # define XtNgreeting "greeting" 83 | # define XtNunsecureGreeting "unsecureGreeting" 84 | # define XtNnamePrompt "namePrompt" 85 | # define XtNpasswdPrompt "passwdPrompt" 86 | # define XtNfail "fail" 87 | # define XtNnotifyDone "notifyDone" 88 | # define XtNpromptColor "promptColor" 89 | # define XtNgreetColor "greetColor" 90 | # define XtNfailColor "failColor" 91 | # define XtNpromptFont "promptFont" 92 | # define XtNgreetFont "greetFont" 93 | # define XtNfailFont "failFont" 94 | # define XtNpromptFace "promptFace" 95 | # define XtNgreetFace "greetFace" 96 | # define XtNfailFace "failFace" 97 | # define XtNfailTimeout "failTimeout" 98 | # define XtNsessionArgument "sessionArgument" 99 | # define XtNsecureSession "secureSession" 100 | # define XtNallowAccess "allowAccess" 101 | # define XtNallowNullPasswd "allowNullPasswd" 102 | # define XtNallowRootLogin "allowRootLogin" 103 | # define XtNechoPasswd "echoPasswd" 104 | # define XtNechoPasswdChar "echoPasswdChar" 105 | 106 | # define XtNface "face" 107 | # define XtCFace "Face" 108 | # define XtRXftFont "XftFont" 109 | # define XtRXftColor "XftColor" 110 | 111 | /* added by Amit Margalit Oct 1996 */ 112 | # define XtNhiColor "hiColor" 113 | # define XtNshdColor "shdColor" 114 | # define XtNinpColor "inpColor" 115 | # define XtNframeWidth "frameWidth" 116 | # define XtCFrameWidth "FrameWidth" 117 | # define XtNinnerFramesWidth "innerFramesWidth" 118 | # define XtNsepWidth "sepWidth" 119 | 120 | # ifdef DANCING 121 | /* caolan begin */ 122 | # define XtNlastEventTime "lastEventTime" 123 | # define XtCLastEventTime "LastEventTime" 124 | /* caolan end */ 125 | # endif /* DANCING */ 126 | 127 | # ifdef XPM 128 | # define XtNuseShape "useShape" 129 | # define XtCUseShape "UseShape" 130 | # define XtNlogoFileName "logoFileName" 131 | # define XtCLogoFileName "LogoFileName" 132 | # define XtNlogoPadding "logoPadding" 133 | # define XtCLogoPadding "LogoPadding" 134 | # endif /* XPM */ 135 | 136 | # define XtCGreeting "Greeting" 137 | # define XtCNamePrompt "NamePrompt" 138 | # define XtCPasswdPrompt "PasswdPrompt" 139 | # define XtCFail "Fail" 140 | # define XtCFailTimeout "FailTimeout" 141 | # define XtCSessionArgument "SessionArgument" 142 | # define XtCSecureSession "SecureSession" 143 | # define XtCAllowAccess "AllowAccess" 144 | # define XtCAllowNullPasswd "AllowNullPasswd" 145 | # define XtCAllowRootLogin "AllowRootLogin" 146 | # define XtCEchoPasswd "EchoPasswd" 147 | # define XtCEchoPasswdChar "EchoPasswdChar" 148 | 149 | # define XtNchangePasswdMessage "changePasswdMessage" 150 | # define XtCChangePasswdMessage "ChangePasswdMessage" 151 | 152 | /* notifyDone interface definition */ 153 | 154 | # ifdef __OpenBSD__ 155 | # include 156 | # endif 157 | 158 | # include 159 | # include 160 | 161 | # ifdef USE_PAM 162 | # define NAME_LEN PAM_MAX_RESP_SIZE 163 | # define PASSWORD_LEN PAM_MAX_RESP_SIZE 164 | # endif 165 | 166 | /* Defined to be in by SUSv2 */ 167 | # if !defined(PASSWORD_LEN) && defined(PASS_MAX) 168 | # define PASSWORD_LEN PASS_MAX 169 | # endif 170 | 171 | /* _PW_NAME_LEN is found in on OpenBSD > 2.8 (200012) */ 172 | # if !defined(NAME_LEN) && defined(_PW_NAME_LEN) 173 | # define NAME_LEN (_PW_NAME_LEN + 2) 174 | # endif 175 | 176 | /* _PASSWORD_LEN appears to come from 4.4BSD-Lite */ 177 | # if !defined(PASSWORD_LEN) && defined(_PASSWORD_LEN) 178 | # define PASSWORD_LEN (_PASSWORD_LEN + 2) 179 | # endif 180 | 181 | /* Fallbacks if no other definition found */ 182 | # ifndef NAME_LEN 183 | # define NAME_LEN 32 184 | # endif 185 | 186 | # ifndef PASSWORD_LEN 187 | # define PASSWORD_LEN 32 188 | # endif 189 | 190 | typedef struct _LoginData { 191 | char name[NAME_LEN], passwd[PASSWORD_LEN]; 192 | } LoginData; 193 | 194 | # define NOTIFY_OK 0 195 | # define NOTIFY_ABORT 1 196 | # define NOTIFY_RESTART 2 197 | # define NOTIFY_ABORT_DISPLAY 3 198 | 199 | typedef struct _LoginRec *LoginWidget; /* completely defined in LoginPrivate.h */ 200 | typedef struct _LoginClassRec *LoginWidgetClass; /* completely defined in LoginPrivate.h */ 201 | 202 | extern WidgetClass loginWidgetClass; 203 | 204 | extern void ErrorMessage(Widget ctx, const char *message, Bool timeout); 205 | extern void ShowChangePasswdMessage(Widget ctx); 206 | 207 | typedef enum { 208 | LOGIN_PROMPT_NOT_SHOWN, /* Neither prompt nor input shown */ 209 | LOGIN_PROMPT_ECHO_ON, /* Both prompt and input shown */ 210 | LOGIN_PROMPT_ECHO_OFF, /* Prompt shown, input accepted but not 211 | shown (bullets may be shown instead) */ 212 | LOGIN_TEXT_INFO /* Prompt shown, no input area */ 213 | } loginPromptState; 214 | 215 | /* Default prompt meanings for simple username/password auth systems */ 216 | # define LOGIN_PROMPT_USERNAME 0 217 | # define LOGIN_PROMPT_PASSWORD 1 218 | 219 | extern int SetPrompt(Widget ctx, int promptId, const char *message, 220 | loginPromptState state, Boolean minimumTime); 221 | extern const char *GetPrompt(Widget ctx, int promptId); 222 | 223 | extern int SetValue(Widget ctx, int promptId, char *value); 224 | extern const char *GetValue(Widget ctx, int promptId); 225 | 226 | #endif /* _XtLogin_h */ 227 | /* DON'T ADD STUFF AFTER THIS #endif */ 228 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002, 2006, 2009, 2010, Oracle and/or its affiliates. 2 | All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a 5 | copy of this software and associated documentation files (the "Software"), 6 | to deal in the Software without restriction, including without limitation 7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice (including the next 12 | paragraph) shall be included in all copies or substantial portions of the 13 | Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | DEALINGS IN THE SOFTWARE. 22 | 23 | ------------------------------------------------------------ 24 | 25 | Copyright 1988, 1989, 1990, 1991, 1994, 1998 The Open Group 26 | 27 | Permission to use, copy, modify, distribute, and sell this software and its 28 | documentation for any purpose is hereby granted without fee, provided that 29 | the above copyright notice appear in all copies and that both that 30 | copyright notice and this permission notice appear in supporting 31 | documentation. 32 | 33 | The above copyright notice and this permission notice shall be included 34 | in all copies or substantial portions of the Software. 35 | 36 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 37 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 38 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 39 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 40 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 41 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 42 | OTHER DEALINGS IN THE SOFTWARE. 43 | 44 | Except as contained in this notice, the name of The Open Group shall 45 | not be used in advertising or otherwise to promote the sale, use or 46 | other dealings in this Software without prior written authorization 47 | from The Open Group. 48 | 49 | ------------------------------------------------------------ 50 | 51 | Copyright 1988, 1990, 1998 The Open Group 52 | 53 | Permission to use, copy, modify, distribute, and sell this software and its 54 | documentation for any purpose is hereby granted without fee, provided that 55 | the above copyright notice appear in all copies and that both that 56 | copyright notice and this permission notice appear in supporting 57 | documentation. 58 | 59 | The above copyright notice and this permission notice shall be included in 60 | all copies or substantial portions of the Software. 61 | 62 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 63 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 64 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 65 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 66 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 67 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 68 | 69 | Except as contained in this notice, the name of a copyright holder shall not be 70 | used in advertising or otherwise to promote the sale, use or other dealings 71 | in this Software without prior written authorization from the copyright holder. 72 | 73 | ------------------------------------------------------------ 74 | 75 | Copyright 1998 by Thomas E. Dickey 76 | 77 | All Rights Reserved 78 | 79 | Permission is hereby granted, free of charge, to any person obtaining a 80 | copy of this software and associated documentation files (the 81 | "Software"), to deal in the Software without restriction, including 82 | without limitation the rights to use, copy, modify, merge, publish, 83 | distribute, sublicense, and/or sell copies of the Software, and to 84 | permit persons to whom the Software is furnished to do so, subject to 85 | the following conditions: 86 | 87 | The above copyright notice and this permission notice shall be included 88 | in all copies or substantial portions of the Software. 89 | 90 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 91 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 92 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 93 | IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 94 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 95 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 96 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 97 | 98 | Except as contained in this notice, the name(s) of the above copyright 99 | holders shall not be used in advertising or otherwise to promote the 100 | sale, use or other dealings in this Software without prior written 101 | authorization. 102 | 103 | ------------------------------------------------------------ 104 | 105 | md5 code in genauth.c implements something close to the MD5 message-digest 106 | algorithm. This code is based on code written by Colin Plumb in 1993, 107 | no copyright is claimed. 108 | This code is in the public domain; do with it what you wish. 109 | 110 | ------------------------------------------------------------ 111 | 112 | Copyright Theodore Ts'o, 1994, 1995, 1996, 1997, 1998, 1999. All 113 | rights reserved. 114 | 115 | Redistribution and use in source and binary forms, with or without 116 | modification, are permitted provided that the following conditions 117 | are met: 118 | 1. Redistributions of source code must retain the above copyright 119 | notice, and the entire permission notice in its entirety, 120 | including the disclaimer of warranties. 121 | 2. Redistributions in binary form must reproduce the above copyright 122 | notice, this list of conditions and the following disclaimer in the 123 | documentation and/or other materials provided with the distribution. 124 | 3. The name of the author may not be used to endorse or promote 125 | products derived from this software without specific prior 126 | written permission. 127 | 128 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 129 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 130 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 131 | WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 132 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 133 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 134 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 135 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 136 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 137 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 138 | USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 139 | DAMAGE. 140 | 141 | ------------------------------------------------------------ 142 | 143 | Copyright (c) 1995,1999 Theo de Raadt. All rights reserved. 144 | Copyright (c) 2001-2002 Damien Miller. All rights reserved. 145 | 146 | Redistribution and use in source and binary forms, with or without 147 | modification, are permitted provided that the following conditions 148 | are met: 149 | 1. Redistributions of source code must retain the above copyright 150 | notice, this list of conditions and the following disclaimer. 151 | 2. Redistributions in binary form must reproduce the above copyright 152 | notice, this list of conditions and the following disclaimer in the 153 | documentation and/or other materials provided with the distribution. 154 | 155 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 156 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 157 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 158 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 159 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 160 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 161 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 162 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 163 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 164 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 165 | 166 | -------------------------------------------------------------------------------- /xdm/xdmauth.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | /* 29 | * xdm - display manager daemon 30 | * Author: Keith Packard, MIT X Consortium 31 | * 32 | * xdmauth 33 | * 34 | * generate authorization data for XDM-AUTHORIZATION-1 as per XDMCP spec 35 | */ 36 | 37 | #include "dm.h" 38 | #include "dm_auth.h" 39 | #include "dm_error.h" 40 | 41 | #ifdef HASXDMAUTH 42 | 43 | static char auth_name[256]; 44 | static int auth_name_len; 45 | 46 | static void 47 | XdmPrintDataHex (const char *s, const char *a, int l) 48 | { 49 | int i; 50 | 51 | Debug ("%s", s); 52 | for (i = 0; i < l; i++) 53 | Debug (" %02x", a[i] & 0xff); 54 | Debug ("\n"); 55 | } 56 | 57 | # ifdef XDMCP 58 | static void 59 | XdmPrintArray8Hex (const char *s, ARRAY8Ptr a) 60 | { 61 | XdmPrintDataHex (s, (char *) a->data, a->length); 62 | } 63 | # endif 64 | 65 | void 66 | XdmInitAuth (unsigned short name_len, char *name) 67 | { 68 | if (name_len > 256) 69 | name_len = 256; 70 | auth_name_len = name_len; 71 | memmove( auth_name, name, name_len); 72 | } 73 | 74 | /* 75 | * Generate authorization for XDM-AUTHORIZATION-1 76 | * 77 | * When being used with XDMCP, 8 bytes are generated for the session key 78 | * (sigma), as the random number (rho) is already shared between xdm and 79 | * the server. Otherwise, we'll prepend a random number to pass in the file 80 | * between xdm and the server (16 bytes total) 81 | */ 82 | 83 | static Xauth * 84 | XdmGetAuthHelper (unsigned short namelen, char *name, int includeRho) 85 | { 86 | Xauth *new; 87 | new = malloc (sizeof (Xauth)); 88 | 89 | if (!new) 90 | return (Xauth *) 0; 91 | new->family = FamilyWild; 92 | new->address_length = 0; 93 | new->address = NULL; 94 | new->number_length = 0; 95 | new->number = NULL; 96 | if (includeRho) 97 | new->data_length = 16; 98 | else 99 | new->data_length = 8; 100 | 101 | new->data = malloc (new->data_length); 102 | if (!new->data) 103 | { 104 | free (new); 105 | return (Xauth *) 0; 106 | } 107 | new->name = malloc (namelen); 108 | if (!new->name) 109 | { 110 | free (new->data); 111 | free (new); 112 | return (Xauth *) 0; 113 | } 114 | memmove( (char *)new->name, name, namelen); 115 | new->name_length = namelen; 116 | if (!GenerateAuthData ((char *)new->data, new->data_length)) 117 | { 118 | free (new->name); 119 | free (new->data); 120 | free (new); 121 | return (Xauth *) 0; 122 | } 123 | /* 124 | * set the first byte of the session key to zero as it 125 | * is a DES key and only uses 56 bits 126 | */ 127 | ((char *)new->data)[new->data_length - 8] = '\0'; 128 | XdmPrintDataHex ("Local server auth", (char *)new->data, new->data_length); 129 | return new; 130 | } 131 | 132 | Xauth * 133 | XdmGetAuth (unsigned short namelen, char *name) 134 | { 135 | return XdmGetAuthHelper (namelen, name, TRUE); 136 | } 137 | 138 | # ifdef XDMCP 139 | 140 | void 141 | XdmGetXdmcpAuth (struct protoDisplay *pdpy, 142 | unsigned short authorizationNameLen, char *authorizationName) 143 | { 144 | Xauth *fileauth, *xdmcpauth; 145 | 146 | if (pdpy->fileAuthorization && pdpy->xdmcpAuthorization) 147 | return; 148 | xdmcpauth = XdmGetAuthHelper (authorizationNameLen, authorizationName, FALSE); 149 | if (!xdmcpauth) 150 | return; 151 | fileauth = malloc (sizeof (Xauth)); 152 | if (!fileauth) 153 | { 154 | XauDisposeAuth(xdmcpauth); 155 | return; 156 | } 157 | /* build the file auth from the XDMCP auth */ 158 | *fileauth = *xdmcpauth; 159 | fileauth->name = malloc (xdmcpauth->name_length); 160 | fileauth->data = malloc (16); 161 | fileauth->data_length = 16; 162 | if (!fileauth->name || !fileauth->data) 163 | { 164 | XauDisposeAuth (xdmcpauth); 165 | free (fileauth->name); 166 | free (fileauth->data); 167 | free (fileauth); 168 | return; 169 | } 170 | /* 171 | * for the file authorization, prepend the random number (rho) 172 | * which is simply the number we've been passing back and 173 | * forth via XDMCP 174 | */ 175 | memmove( fileauth->name, xdmcpauth->name, xdmcpauth->name_length); 176 | memmove( fileauth->data, pdpy->authenticationData.data, 8); 177 | memmove( fileauth->data + 8, xdmcpauth->data, 8); 178 | XdmPrintDataHex ("Accept packet auth", xdmcpauth->data, xdmcpauth->data_length); 179 | XdmPrintDataHex ("Auth file auth", fileauth->data, fileauth->data_length); 180 | /* encrypt the session key for its trip back to the server */ 181 | XdmcpWrap ((unsigned char *)xdmcpauth->data, (unsigned char *)&pdpy->key, 182 | (unsigned char *)xdmcpauth->data, 8); 183 | pdpy->fileAuthorization = fileauth; 184 | pdpy->xdmcpAuthorization = xdmcpauth; 185 | } 186 | 187 | # define atox(c) ('0' <= c && c <= '9' ? c - '0' : \ 188 | 'a' <= c && c <= 'f' ? c - 'a' + 10 : \ 189 | 'A' <= c && c <= 'F' ? c - 'A' + 10 : -1) 190 | 191 | static int 192 | HexToBinary(char *key) 193 | { 194 | char *out, *in; 195 | int top, bottom; 196 | 197 | in = key + 2; 198 | out= key; 199 | while (in[0] && in[1]) 200 | { 201 | top = atox(in[0]); 202 | if (top == -1) 203 | return 0; 204 | bottom = atox(in[1]); 205 | if (bottom == -1) 206 | return 0; 207 | *out++ = (top << 4) | bottom; 208 | in += 2; 209 | } 210 | if (in[0]) 211 | return 0; 212 | *out++ = '\0'; 213 | return 1; 214 | } 215 | 216 | /* 217 | * Search the Keys file for the entry matching this display. This 218 | * routine accepts either plain ascii strings for keys, or hex-encoded numbers 219 | */ 220 | 221 | static int 222 | XdmGetKey(struct protoDisplay *pdpy, ARRAY8Ptr displayID) 223 | { 224 | FILE *keys; 225 | char line[1024], id[1024], key[1024]; 226 | int keylen; 227 | 228 | Debug ("Lookup key for %*.*s\n", displayID->length, displayID->length, displayID->data); 229 | keys = fopen (keyFile, "r"); 230 | if (!keys) 231 | return FALSE; 232 | while (fgets (line, sizeof (line) - 1, keys)) 233 | { 234 | if (line[0] == '#' || sscanf (line, "%s %s", id, key) != 2) 235 | continue; 236 | bzero(line, sizeof(line)); 237 | Debug ("Key entry for \"%s\" %ld bytes\n", id, strlen(key)); 238 | if (strlen (id) == displayID->length && 239 | !strncmp (id, (char *)displayID->data, displayID->length)) 240 | { 241 | if (!strncmp (key, "0x", 2) || !strncmp (key, "0X", 2)) 242 | if (!HexToBinary (key)) 243 | break; 244 | keylen = strlen (key); 245 | while (keylen < 7) 246 | key[keylen++] = '\0'; 247 | pdpy->key.data[0] = '\0'; 248 | memmove( pdpy->key.data + 1, key, 7); 249 | bzero(key, sizeof(key)); 250 | fclose (keys); 251 | return TRUE; 252 | } 253 | } 254 | bzero(line, sizeof(line)); 255 | bzero(key, sizeof(key)); 256 | fclose (keys); 257 | return FALSE; 258 | } 259 | 260 | /*ARGSUSED*/ 261 | int 262 | XdmCheckAuthentication(struct protoDisplay *pdpy, ARRAY8Ptr displayID, 263 | ARRAY8Ptr authenticationName, ARRAY8Ptr authenticationData) 264 | { 265 | XdmAuthKeyPtr incoming; 266 | 267 | if (!XdmGetKey (pdpy, displayID)) 268 | return FALSE; 269 | if (authenticationData->length != 8) 270 | return FALSE; 271 | XdmcpUnwrap (authenticationData->data, (unsigned char *)&pdpy->key, 272 | authenticationData->data, 8); 273 | XdmPrintArray8Hex ("Request packet auth", authenticationData); 274 | if (!XdmcpCopyARRAY8(authenticationData, &pdpy->authenticationData)) 275 | return FALSE; 276 | incoming = (XdmAuthKeyPtr) authenticationData->data; 277 | XdmcpIncrementKey (incoming); 278 | XdmcpWrap (authenticationData->data, (unsigned char *)&pdpy->key, 279 | authenticationData->data, 8); 280 | return TRUE; 281 | } 282 | 283 | # endif /* XDMCP */ 284 | #endif /* HASXDMAUTH (covering the entire file) */ 285 | -------------------------------------------------------------------------------- /xdm/policy.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * policy.c. Implement site-dependent policy for XDMCP connections 34 | */ 35 | 36 | #include "dm.h" 37 | #include "dm_auth.h" 38 | 39 | #include 40 | 41 | #ifdef XDMCP 42 | 43 | # include 44 | 45 | # include "dm_socket.h" 46 | 47 | static ARRAY8 noAuthentication = { (CARD16) 0, (CARD8Ptr) 0 }; 48 | 49 | typedef struct _XdmAuth { 50 | ARRAY8 authentication; 51 | ARRAY8 authorization; 52 | } XdmAuthRec, *XdmAuthPtr; 53 | 54 | static XdmAuthRec auth[] = { 55 | # ifdef HASXDMAUTH 56 | { {(CARD16) 20, (CARD8 *) "XDM-AUTHENTICATION-1"}, 57 | {(CARD16) 19, (CARD8 *) "XDM-AUTHORIZATION-1"}, 58 | }, 59 | # endif 60 | { {(CARD16) 0, (CARD8 *) 0}, 61 | {(CARD16) 0, (CARD8 *) 0}, 62 | } 63 | }; 64 | 65 | # define NumAuth (sizeof auth / sizeof auth[0]) 66 | 67 | ARRAY8Ptr 68 | ChooseAuthentication (ARRAYofARRAY8Ptr authenticationNames) 69 | { 70 | int i, j; 71 | 72 | for (i = 0; i < (int)authenticationNames->length; i++) 73 | for (j = 0; j < NumAuth; j++) 74 | if (XdmcpARRAY8Equal (&authenticationNames->data[i], 75 | &auth[j].authentication)) 76 | return &authenticationNames->data[i]; 77 | return &noAuthentication; 78 | } 79 | 80 | int 81 | CheckAuthentication ( 82 | struct protoDisplay *pdpy, 83 | ARRAY8Ptr displayID, 84 | ARRAY8Ptr name, 85 | ARRAY8Ptr data) 86 | { 87 | # ifdef HASXDMAUTH 88 | if (name->length && !strncmp ((char *)name->data, "XDM-AUTHENTICATION-1", 20)) 89 | return XdmCheckAuthentication (pdpy, displayID, name, data); 90 | # endif 91 | return TRUE; 92 | } 93 | 94 | int 95 | SelectAuthorizationTypeIndex ( 96 | ARRAY8Ptr authenticationName, 97 | ARRAYofARRAY8Ptr authorizationNames) 98 | { 99 | int i, j; 100 | 101 | for (j = 0; j < NumAuth; j++) 102 | if (XdmcpARRAY8Equal (authenticationName, 103 | &auth[j].authentication)) 104 | break; 105 | if (j < NumAuth) 106 | { 107 | for (i = 0; i < (int)authorizationNames->length; i++) 108 | if (XdmcpARRAY8Equal (&authorizationNames->data[i], 109 | &auth[j].authorization)) 110 | return i; 111 | } 112 | for (i = 0; i < (int)authorizationNames->length; i++) 113 | if (ValidAuthorization (authorizationNames->data[i].length, 114 | (char *) authorizationNames->data[i].data)) 115 | return i; 116 | return -1; 117 | } 118 | 119 | /*ARGSUSED*/ 120 | int 121 | Willing ( 122 | ARRAY8Ptr addr, 123 | CARD16 connectionType, 124 | ARRAY8Ptr authenticationName, 125 | ARRAY8Ptr status, 126 | xdmOpCode type) 127 | { 128 | char statusBuf[256]; 129 | int ret; 130 | 131 | ret = AcceptableDisplayAddress (addr, connectionType, type); 132 | if (!ret) 133 | snprintf (statusBuf, sizeof(statusBuf), 134 | "Display not authorized to connect"); 135 | else 136 | { 137 | if (*willing) 138 | { FILE *fd = NULL; 139 | if ((fd = popen(willing, "r"))) 140 | { 141 | char *s = NULL; 142 | errno = 0; 143 | while(!(s = fgets(statusBuf, 256, fd)) && errno == EINTR) 144 | errno = 0; 145 | if (s && strlen(statusBuf) > 0) 146 | statusBuf[strlen(statusBuf)-1] = 0; /* chop newline */ 147 | else 148 | snprintf (statusBuf, sizeof(statusBuf), 149 | "Willing, but %s failed", willing); 150 | } 151 | else 152 | snprintf (statusBuf, sizeof(statusBuf), 153 | "Willing, but %s failed", willing); 154 | if (fd) pclose(fd); 155 | } 156 | else 157 | snprintf (statusBuf, sizeof(statusBuf), "Willing to manage"); 158 | } 159 | status->length = strlen (statusBuf); 160 | status->data = calloc (status->length, sizeof (*status->data)); 161 | if (!status->data) 162 | status->length = 0; 163 | else 164 | memmove( status->data, statusBuf, status->length); 165 | return ret; 166 | } 167 | 168 | static ARRAY8 noAccessACL = { (CARD16) 33, (CARD8Ptr) "Display not authorized to connect" }; 169 | 170 | /*ARGSUSED*/ 171 | ARRAY8Ptr 172 | Accept ( 173 | ARRAY8Ptr addr, 174 | CARD16 connectionType, 175 | CARD16 displayNumber) 176 | { 177 | int ret; 178 | 179 | /* 180 | * Probably the biggest gapping security hole in XDM: all one has to do is 181 | * skip the Query/Willing exchange and move directly to Request/Accept to 182 | * completely bypass the ACL. 183 | */ 184 | ret = AcceptableDisplayAddress (addr, connectionType, REQUEST); 185 | if (!ret) 186 | return &noAccessACL; 187 | 188 | return NULL; 189 | } 190 | 191 | /*ARGSUSED*/ 192 | int 193 | SelectConnectionTypeIndex ( 194 | ARRAY8Ptr addr, 195 | CARD16 family, 196 | ARRAY16Ptr connectionTypes, 197 | ARRAYofARRAY8Ptr connectionAddresses, 198 | CARD16Ptr connectionType, 199 | ARRAY8Ptr connectionAddress) 200 | { 201 | int i, ret = -1; 202 | 203 | /* 204 | * Select one supported connection type 205 | */ 206 | 207 | /* 208 | * I suppose this was written when it was not usual to have more than one IP 209 | * address or network interface for a host. I have a machine with 2 NICs 210 | * with an IPv4LL allocated address on one NIC that is disconnected, and a 211 | * regular IPv4 address on the other. Both NICs have IPv6 link scope 212 | * addresses assigned. Xorg servers are sending 4 addresses in the list 213 | * when looping back on IPv4: with the non-function IPv4LL address first in 214 | * the list. This function would never let it connect. 215 | */ 216 | 217 | /* 218 | * Problem #2: Xorg servers (1.16) are placing link-local IPv6 address in 219 | * the connection addresses. The problem is that they are missing the 220 | * scope-id. Another problem is that the Xorg servers (1.16) are placing 221 | * *all* link-local IPv6 addresses in the list, which means that the 222 | * correct scope-id is not necessarily the same as the interface on which 223 | * the MANAGE packet was received. What is worse, the Xorg servers (1.16) 224 | * are placeing the link-local IPv6 addresses first in the list when 225 | * executed as X :%d -indirect ::1. 226 | */ 227 | 228 | for (i = 0; i < connectionTypes->length; i++) { 229 | switch (connectionTypes->data[i]) { 230 | case FamilyLocal: 231 | # if defined(TCPCONN) 232 | case FamilyInternet: 233 | # if defined(IPv6) && defined(AF_INET6) 234 | case FamilyInternet6: 235 | # endif /* IPv6 */ 236 | # endif /* TCPCONN */ 237 | if (family == connectionTypes->data[i] && 238 | XdmcpARRAY8Equal(addr, &connectionAddresses->data[i])) { 239 | /* if the address is the same as the request address, use it */ 240 | *connectionType = connectionTypes->data[i]; 241 | connectionAddress->length = connectionAddresses->data[i].length; 242 | connectionAddress->data = connectionAddresses->data[i].data; 243 | return i; 244 | } 245 | if (ret == -1) { 246 | /* tentatively use the first usable address */ 247 | *connectionType = connectionTypes->data[i]; 248 | connectionAddress->length = connectionAddresses->data[i].length; 249 | connectionAddress->data = connectionAddresses->data[i].data; 250 | ret = i; 251 | } 252 | } 253 | } /* for */ 254 | /* 255 | * This is really only meant to handle old xqproxy which placed zero 256 | * connections in the connection list, or for situations with Xorg servers 257 | * such as: X :%d -nolisten tcp -indirect localhost, in which case there 258 | * will be no connections in the connection list for Xorg servers. 259 | */ 260 | if (ret == -1 && isLocalAddress(addr, family)) { 261 | /* maybe FamilyLocal or FamilyLocalHost here? */ 262 | *connectionType = family; 263 | connectionAddress->length = addr->length; 264 | connectionAddress->data = addr->data; 265 | ret = connectionTypes->length; 266 | } 267 | return (ret); 268 | } 269 | 270 | #endif /* XDMCP */ 271 | -------------------------------------------------------------------------------- /include/greet.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1994, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * greet.h - interface to xdm's dynamically-loadable modular greeter 31 | */ 32 | #include 33 | #include 34 | 35 | /* 36 | * Do this rather than break a build over a const-mismatch 37 | */ 38 | #if defined(__linux__) || defined(CSRG_BASED) || (defined(sun) && defined(SVR4)) 39 | # define CRYPT_ARGS const char *s1, const char *s2 40 | # define GETSPNAM_ARGS const char *name 41 | # define GETPWNAM_ARGS const char *name 42 | #else 43 | # define CRYPT_ARGS /*unknown*/ 44 | # define GETSPNAM_ARGS /*unknown*/ 45 | # define GETPWNAM_ARGS /*unknown*/ 46 | #endif 47 | 48 | #if defined(__FreeBSD__) || defined(__bsdi__) || defined(__osf__) 49 | # define SETGRENT_TYPE int 50 | #else 51 | # define SETGRENT_TYPE void 52 | #endif 53 | 54 | struct dlfuncs { 55 | int (*_PingServer)(struct display *d, Display *alternateDpy); 56 | void (*_SessionPingFailed)(struct display *d); 57 | void (*_Debug)(const char * fmt, ...) _X_ATTRIBUTE_PRINTF(1,2); 58 | void (*_RegisterCloseOnFork)(int fd); 59 | void (*_SecureDisplay)(struct display *d, Display *dpy); 60 | void (*_UnsecureDisplay)(struct display *d, Display *dpy); 61 | void (*_ClearCloseOnFork)(int fd); 62 | void (*_SetupDisplay)(struct display *d); 63 | void (*_LogError)(const char * fmt, ...) _X_ATTRIBUTE_PRINTF(1,2); 64 | void (*_SessionExit)(struct display *d, int status, int removeAuth); 65 | void (*_DeleteXloginResources)(struct display *d, Display *dpy); 66 | int (*_source)(char **environ, char *file); 67 | char **(*_defaultEnv)(void); 68 | char **(*_setEnv)(char **e, const char *name, const char *value); 69 | char **(*_putEnv)(const char *string, char **env); 70 | char **(*_parseArgs)(char **argv, const char *string); 71 | void (*_printEnv)(char **e); 72 | char **(*_systemEnv)(struct display *d, char *user, char *home); 73 | void (*_LogOutOfMem)(const char * fmt, ...) _X_ATTRIBUTE_PRINTF(1,2); 74 | SETGRENT_TYPE (*_setgrent)(void); /* no longer used */ 75 | struct group *(*_getgrent)(void); /* no longer used */ 76 | void (*_endgrent)(void); /* no longer used */ 77 | #ifdef HAVE_GETSPNAM 78 | struct spwd *(*_getspnam)(GETSPNAM_ARGS); 79 | # ifndef QNX4 80 | void (*_endspent)(void); 81 | # endif /* QNX4 doesn't use endspent */ 82 | #endif 83 | struct passwd *(*_getpwnam)(GETPWNAM_ARGS); 84 | #if defined(linux) || defined(__GLIBC__) 85 | void (*_endpwent)(void); 86 | #endif 87 | char *(*_crypt)(CRYPT_ARGS); 88 | #ifdef USE_PAM 89 | pam_handle_t **(*_thepamhp)(void); 90 | #endif 91 | }; 92 | 93 | /* 94 | * Return values for GreetUser(); 95 | * Values must be explictly defined because the greet library 96 | * may come from a different vendor. 97 | * Negative values indicate an error. 98 | */ 99 | typedef enum { 100 | Greet_Session_Over = 0, /* session managed and over */ 101 | Greet_Success = 1, /* greet succeeded, session not managed */ 102 | Greet_Failure = -1 /* greet failed */ 103 | } greet_user_rtn; 104 | 105 | /* 106 | * GreetUser can either handle the user's session or allow xdm to do it. 107 | * The return or exit status of GreetUser indicates to xdm whether it 108 | * should start a session. 109 | * 110 | * GreetUser is passed the xdm struct display pointer, a pointer to a 111 | * Display, and pointers to greet and verify structs. If it expectes xdm 112 | * to run the session, it fills in the Display pointer and the fields 113 | * of the greet and verify structs. 114 | * 115 | * The verify struct includes the uid, gid, arguments to run the session, 116 | * environment for the session, and environment for startup/reset. 117 | * 118 | * The greet struct includes the user's name and password but these are 119 | * really only needed if xdm is compiled with a user-based authorization 120 | * option such as SECURE_RPC or K5AUTH. 121 | */ 122 | 123 | extern greet_user_rtn GreetUser(struct display *, Display **, 124 | struct verify_info *, struct greet_info *, struct dlfuncs *); 125 | 126 | typedef greet_user_rtn (*GreetUserProc)(struct display *, Display **, 127 | struct verify_info *, struct greet_info *, struct dlfuncs *dlfcns); 128 | 129 | #ifdef GREET_LIB 130 | /* 131 | * The greeter uses some symbols from the main xdm executable. Since some 132 | * dynamic linkers are broken, we need to fix things up so that the symbols 133 | * are referenced indirectly through function pointers. The definitions 134 | * here, are used to hold the pointers to the functions in the main xdm 135 | * executable. The pointers are filled in when the GreetUser function is 136 | * called, with the pointer values passed as a paramter. 137 | */ 138 | 139 | extern int (*__xdm_PingServer)(struct display *d, Display *alternateDpy); 140 | extern void (*__xdm_SessionPingFailed)(struct display *d); 141 | extern void (*__xdm_Debug)(const char * fmt, ...); 142 | extern void (*__xdm_RegisterCloseOnFork)(int fd); 143 | extern void (*__xdm_SecureDisplay)(struct display *d, Display *dpy); 144 | extern void (*__xdm_UnsecureDisplay)(struct display *d, Display *dpy); 145 | extern void (*__xdm_ClearCloseOnFork)(int fd); 146 | extern void (*__xdm_SetupDisplay)(struct display *d); 147 | extern void (*__xdm_LogError)(const char * fmt, ...); 148 | extern void (*__xdm_SessionExit)(struct display *d, int status, int removeAuth); 149 | extern void (*__xdm_DeleteXloginResources)(struct display *d, Display *dpy); 150 | extern int (*__xdm_source)(char **environ, char *file); 151 | extern char **(*__xdm_defaultEnv)(void); 152 | extern char **(*__xdm_setEnv)(char **e, const char *name, const char *value); 153 | extern char **(*__xdm_putEnv)(const char *string, char **env); 154 | extern char **(*__xdm_parseArgs)(char **argv, const char *string); 155 | extern void (*__xdm_printEnv)(char **e); 156 | extern char **(*__xdm_systemEnv)(struct display *d, char *user, char *home); 157 | extern void (*__xdm_LogOutOfMem)(const char * fmt, ...); 158 | extern void (*__xdm_setgrent)(void); 159 | extern struct group *(*__xdm_getgrent)(void); 160 | extern void (*__xdm_endgrent)(void); 161 | # ifdef HAVE_GETSPNAM 162 | extern struct spwd *(*__xdm_getspnam)(GETSPNAM_ARGS); 163 | # ifndef QNX4 164 | extern void (*__xdm_endspent)(void); 165 | # endif /* QNX4 doesn't use endspent */ 166 | # endif 167 | extern struct passwd *(*__xdm_getpwnam)(GETPWNAM_ARGS); 168 | # if defined(linux) || defined(__GLIBC__) 169 | extern void (*__xdm_endpwent)(void); 170 | # endif 171 | extern char *(*__xdm_crypt)(CRYPT_ARGS); 172 | # ifdef USE_PAM 173 | extern pam_handle_t **(*__xdm_thepamhp)(void); 174 | # endif 175 | 176 | /* 177 | * Force the shared library to call through the function pointer 178 | * initialized during the initial call into the library. 179 | */ 180 | 181 | # define PingServer (*__xdm_PingServer) 182 | # define SessionPingFailed (*__xdm_SessionPingFailed) 183 | # define Debug (*__xdm_Debug) 184 | # define RegisterCloseOnFork (*__xdm_RegisterCloseOnFork) 185 | # define SecureDisplay (*__xdm_SecureDisplay) 186 | # define UnsecureDisplay (*__xdm_UnsecureDisplay) 187 | # define ClearCloseOnFork (*__xdm_ClearCloseOnFork) 188 | # define SetupDisplay (*__xdm_SetupDisplay) 189 | # define LogError (*__xdm_LogError) 190 | # define SessionExit (*__xdm_SessionExit) 191 | # define DeleteXloginResources (*__xdm_DeleteXloginResources) 192 | # define source (*__xdm_source) 193 | # define defaultEnv (*__xdm_defaultEnv) 194 | # define setEnv (*__xdm_setEnv) 195 | # define putEnv (*__xdm_putEnv) 196 | # define parseArgs (*__xdm_parseArgs) 197 | # define printEnv (*__xdm_printEnv) 198 | # define systemEnv (*__xdm_systemEnv) 199 | # define LogOutOfMem (*__xdm_LogOutOfMem) 200 | # define setgrent (*__xdm_setgrent) 201 | # define getgrent (*__xdm_getgrent) 202 | # define endgrent (*__xdm_endgrent) 203 | # ifdef HAVE_GETSPNAM 204 | # define getspnam (*__xdm_getspnam) 205 | # ifndef QNX4 206 | # define endspent (*__xdm_endspent) 207 | # endif /* QNX4 doesn't use endspent */ 208 | # endif 209 | # define getpwnam (*__xdm_getpwnam) 210 | # if defined(linux) || defined(__GLIBC__) 211 | # define endpwent (*__xdm_endpwent) 212 | # endif 213 | # define crypt (*__xdm_crypt) 214 | # ifdef USE_PAM 215 | # define thepamhp (*__xdm_thepamhp) 216 | # endif 217 | 218 | #endif /* GREET_LIB */ 219 | -------------------------------------------------------------------------------- /xdm/server.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * server.c - manage the X server 34 | */ 35 | 36 | #include "dm.h" 37 | #include "dm_error.h" 38 | #include "dm_socket.h" 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | static int receivedUsr1; 48 | 49 | static int serverPause (unsigned t, pid_t serverPid); 50 | 51 | /* ARGSUSED */ 52 | static void 53 | CatchUsr1 (int n) 54 | { 55 | int olderrno = errno; 56 | 57 | #ifdef SIGNALS_RESET_WHEN_CAUGHT 58 | (void) Signal (SIGUSR1, CatchUsr1); 59 | #endif 60 | Debug ("display manager caught SIGUSR1\n"); 61 | ++receivedUsr1; 62 | errno = olderrno; 63 | } 64 | 65 | const char *_SysErrorMsg (int n) 66 | { 67 | const char *s = strerror(n); 68 | return (s ? s : "unknown error"); 69 | } 70 | 71 | static int 72 | StartServerOnce (struct display *d) 73 | { 74 | char **f; 75 | char **argv; 76 | char arg[1024]; 77 | pid_t pid; 78 | 79 | Debug ("StartServer for %s\n", d->name); 80 | receivedUsr1 = 0; 81 | (void) Signal (SIGUSR1, CatchUsr1); 82 | argv = d->argv; 83 | switch (pid = fork ()) { 84 | case 0: 85 | CleanUpChild (); 86 | #ifdef XDMCP 87 | /* The chooser socket is not closed by CleanUpChild() */ 88 | DestroyWellKnownSockets(); 89 | #endif 90 | if (d->authFile) { 91 | snprintf (arg, sizeof(arg), "-auth %s", d->authFile); 92 | argv = parseArgs (argv, arg); 93 | } 94 | if (!argv) { 95 | LogError ("StartServer: no arguments\n"); 96 | sleep ((unsigned) d->openDelay); 97 | exit (UNMANAGE_DISPLAY); 98 | } 99 | for (f = argv; *f; f++) 100 | Debug ("'%s' ", *f); 101 | Debug ("\n"); 102 | /* 103 | * give the server SIGUSR1 ignored, 104 | * it will notice that and send SIGUSR1 105 | * when ready 106 | */ 107 | (void) Signal (SIGUSR1, SIG_IGN); 108 | (void) execv (argv[0], argv); 109 | LogError ("server %s cannot be executed\n", 110 | argv[0]); 111 | sleep ((unsigned) d->openDelay); 112 | exit (REMANAGE_DISPLAY); 113 | case -1: 114 | LogError ("fork failed, sleeping\n"); 115 | return 0; 116 | default: 117 | break; 118 | } 119 | Debug ("Server Started %d\n", pid); 120 | d->serverPid = pid; 121 | if (serverPause ((unsigned) d->openDelay, pid)) 122 | return FALSE; 123 | return TRUE; 124 | } 125 | 126 | int 127 | StartServer (struct display *d) 128 | { 129 | int i; 130 | int ret = FALSE; 131 | 132 | i = 0; 133 | while (d->serverAttempts == 0 || i < d->serverAttempts) 134 | { 135 | if ((ret = StartServerOnce (d)) == TRUE) 136 | break; 137 | sleep (d->openDelay); 138 | i++; 139 | } 140 | return ret; 141 | } 142 | 143 | /* 144 | * sleep for t seconds, return 1 if the server is dead when 145 | * the sleep finishes, 0 else 146 | */ 147 | 148 | static Jmp_buf pauseAbort; 149 | static int serverPauseRet; 150 | 151 | /* ARGSUSED */ 152 | _X_NORETURN 153 | static void 154 | serverPauseAbort (int n) 155 | { 156 | Longjmp (pauseAbort, 1); 157 | } 158 | 159 | /* ARGSUSED */ 160 | _X_NORETURN 161 | static void 162 | serverPauseUsr1 (int n) 163 | { 164 | Debug ("display manager paused til SIGUSR1\n"); 165 | ++receivedUsr1; 166 | Longjmp (pauseAbort, 1); 167 | } 168 | 169 | static int 170 | serverPause (unsigned t, pid_t serverPid) 171 | { 172 | pid_t pid; 173 | 174 | serverPauseRet = 0; 175 | if (!Setjmp (pauseAbort)) { 176 | (void) Signal (SIGALRM, serverPauseAbort); 177 | (void) Signal (SIGUSR1, serverPauseUsr1); 178 | #ifdef SYSV 179 | if (receivedUsr1) 180 | (void) alarm ((unsigned) 1); 181 | else 182 | (void) alarm (t); 183 | #else 184 | if (!receivedUsr1) 185 | (void) alarm (t); 186 | else 187 | Debug ("Already received USR1\n"); 188 | #endif 189 | for (;;) { 190 | /* 191 | * wait() is unsafe. Other Xserver or xdm processes may 192 | * exit at this time and this will remove the wait status. 193 | * This means the main loop will not restart the display. 194 | */ 195 | if (!receivedUsr1) 196 | pid = waitpid (serverPid, (int *) 0, 0); 197 | else 198 | pid = waitpid (serverPid, (int *) 0, WNOHANG); 199 | 200 | if (pid == serverPid || 201 | (pid == -1 && errno == ECHILD)) 202 | { 203 | Debug ("Server dead\n"); 204 | serverPauseRet = 1; 205 | break; 206 | } 207 | 208 | if (pid == 0) { 209 | Debug ("Server alive and kicking\n"); 210 | break; 211 | } 212 | } 213 | } 214 | (void) alarm ((unsigned) 0); 215 | (void) Signal (SIGALRM, SIG_DFL); 216 | (void) Signal (SIGUSR1, CatchUsr1); 217 | if (serverPauseRet) { 218 | Debug ("Server died\n"); 219 | LogError ("server unexpectedly died\n"); 220 | } 221 | return serverPauseRet; 222 | } 223 | 224 | 225 | /* 226 | * this code is complicated by some TCP failings. On 227 | * many systems, the connect will occasionally hang forever, 228 | * this trouble is avoided by setting up a timeout to Longjmp 229 | * out of the connect (possibly leaving piles of garbage around 230 | * inside Xlib) and give up, terminating the server. 231 | */ 232 | 233 | static Jmp_buf openAbort; 234 | 235 | /* ARGSUSED */ 236 | _X_NORETURN 237 | static void 238 | abortOpen (int n) 239 | { 240 | Longjmp (openAbort, 1); 241 | } 242 | 243 | #ifdef XDMCP 244 | 245 | 246 | static void 247 | GetRemoteAddress (struct display *d, int fd) 248 | { 249 | char buf[512]; 250 | int len = sizeof (buf); 251 | 252 | free (d->peer); 253 | getpeername (fd, (struct sockaddr *) buf, (void *)&len); 254 | d->peerlen = 0; 255 | if (len) 256 | { 257 | d->peer = calloc (len, sizeof (*d->peer)); 258 | if (d->peer) 259 | { 260 | memmove( (char *) d->peer, buf, len); 261 | d->peerlen = len; 262 | } 263 | } 264 | Debug ("Got remote address %s %d\n", d->name, d->peerlen); 265 | } 266 | 267 | #endif /* XDMCP */ 268 | 269 | static int 270 | openErrorHandler (Display *dpy) 271 | { 272 | LogError ("IO Error in XOpenDisplay\n"); 273 | exit (OPENFAILED_DISPLAY); 274 | /*NOTREACHED*/ 275 | return(0); 276 | } 277 | 278 | int 279 | WaitForServer (struct display *d) 280 | { 281 | static int i; 282 | 283 | for (i = 0; i < (d->openRepeat > 0 ? d->openRepeat : 1); i++) { 284 | (void) Signal (SIGALRM, abortOpen); 285 | (void) alarm ((unsigned) d->openTimeout); 286 | if (!Setjmp (openAbort)) { 287 | Debug ("Before XOpenDisplay(%s)\n", d->name); 288 | errno = 0; 289 | (void) XSetIOErrorHandler (openErrorHandler); 290 | d->dpy = XOpenDisplay (d->name); 291 | (void) alarm ((unsigned) 0); 292 | (void) Signal (SIGALRM, SIG_DFL); 293 | (void) XSetIOErrorHandler ((int (*)(Display *)) 0); 294 | Debug ("After XOpenDisplay(%s)\n", d->name); 295 | if (d->dpy) { 296 | #ifdef XDMCP 297 | if (d->displayType.location == Foreign) 298 | GetRemoteAddress (d, ConnectionNumber (d->dpy)); 299 | #endif 300 | RegisterCloseOnFork (ConnectionNumber (d->dpy)); 301 | (void) fcntl (ConnectionNumber (d->dpy), F_SETFD, 0); 302 | return 1; 303 | } else { 304 | Debug ("OpenDisplay failed %d (%s) on \"%s\"\n", 305 | errno, strerror (errno), d->name); 306 | } 307 | Debug ("waiting for server to start %d\n", i); 308 | sleep ((unsigned) d->openDelay); 309 | } else { 310 | Debug ("hung in open, aborting\n"); 311 | LogError ("Hung in XOpenDisplay(%s), aborting\n", d->name); 312 | (void) Signal (SIGALRM, SIG_DFL); 313 | break; 314 | } 315 | } 316 | Debug ("giving up on server\n"); 317 | LogError ("server open failed for %s, giving up\n", d->name); 318 | return 0; 319 | } 320 | 321 | void 322 | ResetServer (struct display *d) 323 | { 324 | if (d->dpy && d->displayType.origin != FromXDMCP) 325 | pseudoReset (d->dpy); 326 | } 327 | 328 | static Jmp_buf pingTime; 329 | 330 | _X_NORETURN 331 | static void 332 | PingLost (void) 333 | { 334 | Longjmp (pingTime, 1); 335 | } 336 | 337 | /* ARGSUSED */ 338 | static int 339 | PingLostIOErr (Display *dpy) 340 | { 341 | PingLost(); 342 | return 0; 343 | } 344 | 345 | /* ARGSUSED */ 346 | _X_NORETURN 347 | static void 348 | PingLostSig (int n) 349 | { 350 | PingLost(); 351 | } 352 | 353 | int 354 | PingServer (struct display *d, Display *alternateDpy) 355 | { 356 | int (*oldError)(Display *); 357 | void (*oldSig)(int); 358 | int oldAlarm; 359 | static Display *aDpy; 360 | 361 | aDpy = (alternateDpy != NULL ? alternateDpy : d->dpy); 362 | oldError = XSetIOErrorHandler (PingLostIOErr); 363 | oldAlarm = alarm (0); 364 | oldSig = Signal (SIGALRM, PingLostSig); 365 | (void) alarm (d->pingTimeout * 60); 366 | if (!Setjmp (pingTime)) 367 | { 368 | Debug ("Ping server\n"); 369 | XSync (aDpy, 0); 370 | } 371 | else 372 | { 373 | Debug ("Server dead\n"); 374 | (void) alarm (0); 375 | (void) Signal (SIGALRM, SIG_DFL); 376 | XSetIOErrorHandler (oldError); 377 | return 0; 378 | } 379 | (void) alarm (0); 380 | (void) Signal (SIGALRM, oldSig); 381 | (void) alarm (oldAlarm); 382 | Debug ("Server alive\n"); 383 | XSetIOErrorHandler (oldError); 384 | return 1; 385 | } 386 | -------------------------------------------------------------------------------- /xdm/choose.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | Copyright 1990, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | 21 | Except as contained in this notice, the name of The Open Group shall not be 22 | used in advertising or otherwise to promote the sale, use or other dealings 23 | in this Software without prior written authorization from The Open Group. 24 | * 25 | * Author: Keith Packard, MIT X Consortium 26 | */ 27 | 28 | 29 | /* 30 | * choose.c 31 | * 32 | * xdm interface to chooser program 33 | */ 34 | 35 | #include "dm.h" 36 | #include "dm_error.h" 37 | 38 | #ifdef XDMCP 39 | 40 | # include 41 | # include 42 | 43 | # include "dm_socket.h" 44 | # include 45 | # include 46 | 47 | # include 48 | # include 49 | 50 | 51 | # ifdef HAVE_SETPROCTITLE 52 | # ifdef __linux__ 53 | # include 54 | # else 55 | # include 56 | # endif 57 | # endif 58 | 59 | # include 60 | # define Time_t time_t 61 | 62 | # ifdef HAVE_SETPROCTITLE 63 | # include 64 | # include 65 | # endif 66 | 67 | static int 68 | FormatBytes ( 69 | unsigned char *data, 70 | int length, 71 | char *buf, 72 | int buflen) 73 | { 74 | int i; 75 | static char HexChars[] = "0123456789abcdef"; 76 | 77 | if (buflen < length * 2 + 1) 78 | return 0; 79 | for (i = 0; i < length; i++) 80 | { 81 | *buf++ = HexChars[(data[i] >> 4) & 0xf]; 82 | *buf++ = HexChars[(data[i]) & 0xf]; 83 | } 84 | *buf++ = '\0'; 85 | return 1; 86 | } 87 | 88 | static int 89 | FormatARRAY8 ( 90 | ARRAY8Ptr a, 91 | char *buf, 92 | int buflen) 93 | { 94 | return FormatBytes (a->data, a->length, buf, buflen); 95 | } 96 | 97 | /* Converts an Internet address in ARRAY8 format to a string in 98 | familiar dotted address notation, e.g., "18.24.0.11" 99 | Returns 1 if successful, 0 if not. 100 | */ 101 | static int 102 | ARRAY8ToDottedDecimal ( 103 | ARRAY8Ptr a, 104 | char *buf, 105 | int buflen) 106 | { 107 | int outlen; 108 | if (a->length != 4) 109 | return 0; 110 | outlen = snprintf(buf, buflen, "%d.%d.%d.%d", 111 | a->data[0], a->data[1], a->data[2], a->data[3]); 112 | if (outlen >= buflen) { 113 | return 0; 114 | } 115 | return 1; 116 | } 117 | 118 | typedef struct _IndirectUsers { 119 | struct _IndirectUsers *next; 120 | ARRAY8 client; 121 | CARD16 connectionType; 122 | } IndirectUsersRec, *IndirectUsersPtr; 123 | 124 | static IndirectUsersPtr indirectUsers; 125 | 126 | int 127 | RememberIndirectClient ( 128 | ARRAY8Ptr clientAddress, 129 | CARD16 connectionType) 130 | { 131 | IndirectUsersPtr i; 132 | 133 | for (i = indirectUsers; i; i = i->next) 134 | if (XdmcpARRAY8Equal (clientAddress, &i->client) && 135 | connectionType == i->connectionType) 136 | return 1; 137 | i = calloc (1, sizeof (IndirectUsersRec)); 138 | if (!i) 139 | { 140 | LogOutOfMem ("RememberIndirectClient\n"); 141 | return 0; 142 | } 143 | if (!XdmcpCopyARRAY8 (clientAddress, &i->client)) 144 | { 145 | free (i); 146 | return 0; 147 | } 148 | i->connectionType = connectionType; 149 | i->next = indirectUsers; 150 | indirectUsers = i; 151 | return 1; 152 | } 153 | 154 | void 155 | ForgetIndirectClient ( 156 | ARRAY8Ptr clientAddress, 157 | CARD16 connectionType) 158 | { 159 | IndirectUsersPtr i, prev; 160 | 161 | prev = NULL; 162 | for (i = indirectUsers; i; i = i->next) 163 | { 164 | if (XdmcpARRAY8Equal (clientAddress, &i->client) && 165 | connectionType == i->connectionType) 166 | { 167 | if (prev) 168 | prev->next = i->next; 169 | else 170 | indirectUsers = i->next; 171 | XdmcpDisposeARRAY8 (&i->client); 172 | free (i); 173 | break; 174 | } 175 | prev = i; 176 | } 177 | } 178 | 179 | int 180 | IsIndirectClient ( 181 | ARRAY8Ptr clientAddress, 182 | CARD16 connectionType) 183 | { 184 | IndirectUsersPtr i; 185 | 186 | for (i = indirectUsers; i; i = i->next) 187 | if (XdmcpARRAY8Equal (clientAddress, &i->client) && 188 | connectionType == i->connectionType) 189 | return 1; 190 | return 0; 191 | } 192 | 193 | static int 194 | FormatChooserArgument (char *buf, int len) 195 | { 196 | unsigned char addr_buf[1024]; 197 | int addr_len = sizeof (addr_buf); 198 | unsigned char result_buf[1024]; 199 | int result_len = 0; 200 | int netfamily; 201 | 202 | if (GetChooserAddr ((char *)addr_buf, &addr_len) == -1) 203 | { 204 | LogError ("Cannot get return address for chooser socket\n"); 205 | Debug ("Cannot get chooser socket address\n"); 206 | return 0; 207 | } 208 | netfamily = NetaddrFamily((XdmcpNetaddr)addr_buf); 209 | switch (netfamily) { 210 | case AF_INET: 211 | # if defined(IPv6) && defined(AF_INET6) 212 | case AF_INET6: 213 | # endif 214 | { 215 | char *port; 216 | int portlen; 217 | ARRAY8Ptr localAddress = getLocalAddress (); 218 | 219 | # if defined(IPv6) && defined(AF_INET6) 220 | if (localAddress->length == 16) 221 | netfamily = AF_INET6; 222 | else 223 | netfamily = AF_INET; 224 | # endif 225 | 226 | port = NetaddrPort((XdmcpNetaddr)addr_buf, &portlen); 227 | if (port == NULL) { 228 | LogError ("Cannot get port for chooser socket\n"); 229 | return 0; 230 | } 231 | result_buf[0] = netfamily >> 8; 232 | result_buf[1] = netfamily & 0xFF; 233 | result_buf[2] = port[0]; 234 | result_buf[3] = port[1]; 235 | memmove( (char *)result_buf+4, (char *)localAddress->data, 236 | localAddress->length); 237 | result_len = 4 + localAddress->length; 238 | } 239 | break; 240 | # ifdef AF_DECnet 241 | case AF_DECnet: 242 | break; 243 | # endif 244 | default: 245 | Debug ("Chooser family %d isn't known\n", netfamily); 246 | return 0; 247 | } 248 | 249 | return FormatBytes (result_buf, result_len, buf, len); 250 | } 251 | 252 | typedef struct _Choices { 253 | struct _Choices *next; 254 | ARRAY8 client; 255 | CARD16 connectionType; 256 | ARRAY8 choice; 257 | Time_t time; 258 | } ChoiceRec, *ChoicePtr; 259 | 260 | static ChoicePtr choices; 261 | 262 | ARRAY8Ptr 263 | IndirectChoice ( 264 | ARRAY8Ptr clientAddress, 265 | CARD16 connectionType) 266 | { 267 | ChoicePtr c, next, prev; 268 | Time_t now; 269 | 270 | now = time ((Time_t*)0); 271 | prev = NULL; 272 | for (c = choices; c; c = next) 273 | { 274 | next = c->next; 275 | Debug ("Choice checking timeout: %ld >? %d\n", 276 | (long)(now - c->time), choiceTimeout); 277 | if (now - c->time > (Time_t)choiceTimeout) 278 | { 279 | Debug ("Timeout choice %ld > %d\n", 280 | (long)(now - c->time), choiceTimeout); 281 | if (prev) 282 | prev->next = next; 283 | else 284 | choices = next; 285 | XdmcpDisposeARRAY8 (&c->client); 286 | XdmcpDisposeARRAY8 (&c->choice); 287 | free (c); 288 | } 289 | else 290 | { 291 | if (XdmcpARRAY8Equal (clientAddress, &c->client) && 292 | connectionType == c->connectionType) 293 | return &c->choice; 294 | prev = c; 295 | } 296 | } 297 | return NULL; 298 | } 299 | 300 | static int 301 | RegisterIndirectChoice ( 302 | ARRAY8Ptr clientAddress, 303 | CARD16 connectionType, 304 | ARRAY8Ptr choice) 305 | { 306 | ChoicePtr c; 307 | int insert; 308 | 309 | Debug ("Got indirect choice back\n"); 310 | for (c = choices; c; c = c->next) { 311 | if (XdmcpARRAY8Equal (clientAddress, &c->client) && 312 | connectionType == c->connectionType) { 313 | break; 314 | } 315 | } 316 | insert = 0; 317 | if (!c) 318 | { 319 | c = calloc (1, sizeof (ChoiceRec)); 320 | insert = 1; 321 | if (!c) 322 | return 0; 323 | c->connectionType = connectionType; 324 | if (!XdmcpCopyARRAY8 (clientAddress, &c->client)) 325 | { 326 | free (c); 327 | return 0; 328 | } 329 | } 330 | else 331 | { 332 | XdmcpDisposeARRAY8 (&c->choice); 333 | } 334 | if (!XdmcpCopyARRAY8 (choice, &c->choice)) 335 | { 336 | XdmcpDisposeARRAY8 (&c->client); 337 | free (c); 338 | return 0; 339 | } 340 | if (insert) 341 | { 342 | c->next = choices; 343 | choices = c; 344 | } 345 | c->time = time ((Time_t *) 0); 346 | return 1; 347 | } 348 | 349 | # ifdef notdef 350 | static 351 | RemoveIndirectChoice (clientAddress, connectionType) 352 | ARRAY8Ptr clientAddress; 353 | CARD16 connectionType; 354 | { 355 | ChoicePtr c, prev; 356 | 357 | prev = 0; 358 | for (c = choices; c; c = c->next) 359 | { 360 | if (XdmcpARRAY8Equal (clientAddress, &c->client) && 361 | connectionType == c->connectionType) 362 | { 363 | if (prev) 364 | prev->next = c->next; 365 | else 366 | choices = c->next; 367 | XdmcpDisposeARRAY8 (&c->client); 368 | XdmcpDisposeARRAY8 (&c->choice); 369 | free (c); 370 | return; 371 | } 372 | prev = c; 373 | } 374 | } 375 | # endif 376 | 377 | /*ARGSUSED*/ 378 | static void 379 | AddChooserHost ( 380 | CARD16 connectionType, 381 | ARRAY8Ptr addr, 382 | char *closure) 383 | { 384 | char ***argp; 385 | char hostbuf[1024]; 386 | 387 | argp = (char ***) closure; 388 | if (addr->length == strlen ("BROADCAST") && 389 | !strncmp ((char *)addr->data, "BROADCAST", addr->length)) 390 | { 391 | *argp = parseArgs (*argp, "BROADCAST"); 392 | } 393 | # if defined(IPv6) && defined(AF_INET6) 394 | else if ( (addr->length == 16) && 395 | (inet_ntop(AF_INET6, addr->data, hostbuf, sizeof(hostbuf)))) 396 | { 397 | *argp = parseArgs (*argp, hostbuf); 398 | } 399 | # endif 400 | else if (ARRAY8ToDottedDecimal (addr, hostbuf, sizeof (hostbuf))) 401 | { 402 | *argp = parseArgs (*argp, hostbuf); 403 | } 404 | } 405 | 406 | void 407 | ProcessChooserSocket (int fd) 408 | { 409 | int client_fd; 410 | char buf[1024]; 411 | int len; 412 | XdmcpBuffer buffer; 413 | ARRAY8 clientAddress = {0, NULL}; 414 | CARD16 connectionType; 415 | ARRAY8 choice = {0, NULL}; 416 | 417 | Debug ("Process chooser socket\n"); 418 | len = sizeof (buf); 419 | client_fd = accept (fd, (struct sockaddr *)buf, (void *)&len); 420 | if (client_fd == -1) 421 | { 422 | LogError ("Cannot accept chooser connection\n"); 423 | return; 424 | } 425 | Debug ("Accepted %d\n", client_fd); 426 | 427 | len = read (client_fd, buf, sizeof (buf)); 428 | Debug ("Read returns %d\n", len); 429 | if (len > 0) 430 | { 431 | buffer.data = (BYTE *) buf; 432 | buffer.size = sizeof (buf); 433 | buffer.count = len; 434 | buffer.pointer = 0; 435 | if (XdmcpReadARRAY8 (&buffer, &clientAddress)) { 436 | if (XdmcpReadCARD16 (&buffer, &connectionType)) { 437 | if (XdmcpReadARRAY8 (&buffer, &choice)) { 438 | Debug ("Read from chooser succesfully\n"); 439 | RegisterIndirectChoice (&clientAddress, connectionType, &choice); 440 | XdmcpDisposeARRAY8 (&choice); 441 | } else { 442 | LogError ("Invalid choice response length %d\n", len); 443 | } 444 | } else { 445 | LogError ("Invalid choice response length %d\n", len); 446 | } 447 | XdmcpDisposeARRAY8 (&clientAddress); 448 | } else { 449 | LogError ("Invalid choice response length %d\n", len); 450 | } 451 | } 452 | else 453 | { 454 | LogError ("Choice response read error: %s\n", _SysErrorMsg(errno)); 455 | } 456 | 457 | close (client_fd); 458 | } 459 | 460 | 461 | void 462 | RunChooser (struct display *d) 463 | { 464 | char **args; 465 | char buf[1024]; 466 | char **env; 467 | 468 | Debug ("RunChooser %s\n", d->name); 469 | # ifndef HAVE_SETPROCTITLE 470 | SetTitle (d->name, "chooser", (char *) 0); 471 | # else 472 | setproctitle("chooser %s", d->name); 473 | # endif 474 | LoadXloginResources (d); 475 | args = parseArgs ((char **) 0, d->chooser); 476 | strcpy (buf, "-xdmaddress "); 477 | if (FormatChooserArgument (buf + strlen (buf), sizeof (buf) - strlen (buf))) 478 | args = parseArgs (args, buf); 479 | strcpy (buf, "-clientaddress "); 480 | if (FormatARRAY8 (&d->clientAddr, buf + strlen (buf), sizeof (buf) - strlen (buf))) 481 | args = parseArgs (args, buf); 482 | snprintf (buf, sizeof(buf), "-connectionType %d", d->connectionType); 483 | args = parseArgs (args, buf); 484 | ForEachChooserHost (&d->clientAddr, d->connectionType, AddChooserHost, 485 | (char *) &args); 486 | env = systemEnv (d, (char *) 0, (char *) 0); 487 | Debug ("Running %s\n", args[0]); 488 | execute (args, env); 489 | Debug ("Couldn't run %s\n", args[0]); 490 | LogError ("Cannot execute %s\n", args[0]); 491 | exit (REMANAGE_DISPLAY); 492 | } 493 | 494 | #endif /* XDMCP */ 495 | -------------------------------------------------------------------------------- /greeter/verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * verify.c 34 | * 35 | * typical unix verification routine. 36 | */ 37 | 38 | #include "dm.h" 39 | #include "dm_error.h" 40 | 41 | #include 42 | 43 | #if defined(USE_PAM) 44 | # include 45 | #elif defined(HAVE_GETSPNAM) 46 | # include 47 | # include 48 | #elif defined(USE_BSDAUTH) 49 | # include 50 | # include 51 | # include 52 | #endif 53 | 54 | #include "greet.h" 55 | 56 | #ifdef QNX4 57 | extern char *crypt(const char *, const char *); 58 | #endif 59 | 60 | static const char *envvars[] = { 61 | "TZ", /* SYSV and SVR4, but never hurts */ 62 | #if defined(sony) && !defined(SYSTYPE_SYSV) && !defined(_SYSTYPE_SYSV) 63 | "bootdev", 64 | "boothowto", 65 | "cputype", 66 | "ioptype", 67 | "machine", 68 | "model", 69 | "CONSDEVTYPE", 70 | "SYS_LANGUAGE", 71 | "SYS_CODE", 72 | #endif 73 | #if (defined(SVR4) || defined(SYSV)) && defined(i386) && !defined(sun) 74 | "XLOCAL", 75 | #endif 76 | NULL 77 | }; 78 | 79 | #ifdef KERBEROS 80 | # include 81 | # include 82 | /* OpenBSD 2.8 needs this. */ 83 | # if defined(OpenBSD) && (OpenBSD <= 200012) 84 | # include 85 | # endif 86 | static char krbtkfile[MAXPATHLEN]; 87 | #endif 88 | 89 | static char ** 90 | userEnv (struct display *d, int useSystemPath, char *user, char *home, char *shell) 91 | { 92 | char **env; 93 | const char **envvar; 94 | const char *str; 95 | 96 | env = defaultEnv (); 97 | env = setEnv (env, "DISPLAY", d->name); 98 | env = setEnv (env, "HOME", home); 99 | env = setEnv (env, "LOGNAME", user); /* POSIX, System V */ 100 | env = setEnv (env, "USER", user); /* BSD */ 101 | env = setEnv (env, "PATH", useSystemPath ? d->systemPath : d->userPath); 102 | env = setEnv (env, "SHELL", shell); 103 | #ifdef KERBEROS 104 | if (krbtkfile[0] != '\0') 105 | env = setEnv (env, "KRBTKFILE", krbtkfile); 106 | #endif 107 | for (envvar = envvars; *envvar; envvar++) 108 | { 109 | str = getenv(*envvar); 110 | if (str) 111 | env = setEnv (env, *envvar, str); 112 | } 113 | return env; 114 | } 115 | 116 | #ifdef USE_BSDAUTH 117 | _X_INTERNAL 118 | int 119 | Verify (struct display *d, struct greet_info *greet, struct verify_info *verify) 120 | { 121 | struct passwd *p; 122 | login_cap_t *lc; 123 | auth_session_t *as; 124 | char *style, *shell, *home, *s, **argv; 125 | char path[MAXPATHLEN]; 126 | int authok; 127 | 128 | /* User may have specified an authentication style. */ 129 | if ((style = strchr(greet->name, ':')) != NULL) 130 | *style++ = '\0'; 131 | 132 | Debug ("Verify %s, style %s ...\n", greet->name, 133 | style ? style : "default"); 134 | 135 | p = getpwnam (greet->name); 136 | endpwent(); 137 | 138 | if (!p || strlen (greet->name) == 0) { 139 | Debug("getpwnam() failed.\n"); 140 | bzero(greet->password, strlen(greet->password)); 141 | return 0; 142 | } 143 | 144 | if ((lc = login_getclass(p->pw_class)) == NULL) { 145 | Debug("login_getclass() failed.\n"); 146 | bzero(greet->password, strlen(greet->password)); 147 | return 0; 148 | } 149 | if ((style = login_getstyle(lc, style, "xdm")) == NULL) { 150 | Debug("login_getstyle() failed.\n"); 151 | bzero(greet->password, strlen(greet->password)); 152 | return 0; 153 | } 154 | if ((as = auth_open()) == NULL) { 155 | Debug("auth_open() failed.\n"); 156 | login_close(lc); 157 | bzero(greet->password, strlen(greet->password)); 158 | return 0; 159 | } 160 | if (auth_setoption(as, "login", "yes") == -1) { 161 | Debug("auth_setoption() failed.\n"); 162 | login_close(lc); 163 | bzero(greet->password, strlen(greet->password)); 164 | return 0; 165 | } 166 | 167 | /* Set up state for no challenge, just check a response. */ 168 | auth_setstate(as, 0); 169 | auth_setdata(as, "", 1); 170 | auth_setdata(as, greet->password, strlen(greet->password) + 1); 171 | 172 | /* Build path of the auth script and call it */ 173 | snprintf(path, sizeof(path), _PATH_AUTHPROG "%s", style); 174 | auth_call(as, path, style, "-s", "response", greet->name, 175 | lc->lc_class, (void *)NULL); 176 | authok = auth_getstate(as); 177 | 178 | if ((authok & AUTH_ALLOW) == 0) { 179 | Debug("password verify failed\n"); 180 | bzero(greet->password, strlen(greet->password)); 181 | auth_close(as); 182 | login_close(lc); 183 | return 0; 184 | } 185 | /* Run the approval script */ 186 | if (!auth_approval(as, lc, greet->name, "auth-xdm")) { 187 | Debug("login not approved\n"); 188 | bzero(greet->password, strlen(greet->password)); 189 | auth_close(as); 190 | login_close(lc); 191 | return 0; 192 | } 193 | auth_close(as); 194 | login_close(lc); 195 | /* Check empty passwords against allowNullPasswd */ 196 | if (!greet->allow_null_passwd && strlen(greet->password) == 0) { 197 | Debug("empty password not allowed\n"); 198 | return 0; 199 | } 200 | /* Only accept root logins if allowRootLogin resource is set */ 201 | if (p->pw_uid == 0 && !greet->allow_root_login) { 202 | Debug("root logins not allowed\n"); 203 | bzero(greet->password, strlen(greet->password)); 204 | return 0; 205 | } 206 | 207 | /* 208 | * Shell must be in /etc/shells 209 | */ 210 | for (;;) { 211 | s = getusershell(); 212 | if (s == NULL) { 213 | /* did not found the shell in /etc/shells 214 | -> failure */ 215 | Debug("shell not in /etc/shells\n"); 216 | bzero(greet->password, strlen(greet->password)); 217 | endusershell(); 218 | return 0; 219 | } 220 | if (strcmp(s, p->pw_shell) == 0) { 221 | /* found the shell in /etc/shells */ 222 | endusershell(); 223 | break; 224 | } 225 | } 226 | #else /* !USE_BSDAUTH */ 227 | _X_INTERNAL 228 | int 229 | Verify (struct display *d, struct greet_info *greet, struct verify_info *verify) 230 | { 231 | struct passwd *p; 232 | # ifndef USE_PAM 233 | # ifdef HAVE_GETSPNAM 234 | struct spwd *sp; 235 | # endif 236 | char *user_pass = NULL; 237 | char *crypted_pass = NULL; 238 | # endif 239 | # ifdef __OpenBSD__ 240 | char *s; 241 | struct timeval tp; 242 | # endif 243 | char *shell, *home; 244 | char **argv; 245 | 246 | Debug ("Verify %s ...\n", greet->name); 247 | 248 | p = getpwnam (greet->name); 249 | endpwent(); 250 | 251 | if (!p || strlen (greet->name) == 0) { 252 | Debug ("getpwnam() failed.\n"); 253 | if (greet->password != NULL) 254 | bzero(greet->password, strlen(greet->password)); 255 | return 0; 256 | } 257 | 258 | /* 259 | * Only accept root logins if allowRootLogin resource is not false 260 | */ 261 | if ((p->pw_uid == 0) && !greet->allow_root_login) { 262 | Debug("root logins not allowed\n"); 263 | if (greet->password != NULL) 264 | bzero(greet->password, strlen(greet->password)); 265 | return 0; 266 | } 267 | 268 | # if defined(sun) && defined(SVR4) 269 | /* Solaris: If CONSOLE is set to /dev/console in /etc/default/login, 270 | then root can only login on system console */ 271 | 272 | # define SOLARIS_LOGIN_DEFAULTS "/etc/default/login" 273 | 274 | if (p->pw_uid == 0) { 275 | char *console = NULL, *tmp = NULL; 276 | FILE *fs; 277 | 278 | if ((fs= fopen(SOLARIS_LOGIN_DEFAULTS, "r")) != NULL) 279 | { 280 | char str[120]; 281 | while (!feof(fs)) 282 | { 283 | fgets(str, 120, fs); 284 | if(str[0] == '#' || strlen(str) < 8) 285 | continue; 286 | if((tmp = strstr(str, "CONSOLE=")) != NULL) 287 | console = strdup((tmp+8)); 288 | } 289 | fclose(fs); 290 | if ( console != NULL && 291 | (strncmp(console, "/dev/console", 12) == 0) && 292 | (strncmp(d->name,":0",2) != 0) ) 293 | { 294 | Debug("Not on system console\n"); 295 | if (greet->password != NULL) 296 | bzero(greet->password, strlen(greet->password)); 297 | free(console); 298 | return 0; 299 | } 300 | free(console); 301 | } 302 | else 303 | { 304 | Debug("Could not open %s\n", SOLARIS_LOGIN_DEFAULTS); 305 | } 306 | } 307 | # endif 308 | 309 | # ifndef USE_PAM /* PAM authentication happened in GreetUser already */ 310 | # ifdef linux 311 | if (!strcmp(p->pw_passwd, "!") || !strcmp(p->pw_passwd, "*")) { 312 | Debug ("The account is locked, no login allowed.\n"); 313 | bzero(greet->password, strlen(greet->password)); 314 | return 0; 315 | } 316 | # endif 317 | user_pass = p->pw_passwd; 318 | # ifdef KERBEROS 319 | if(strcmp(greet->name, "root") != 0){ 320 | char name[ANAME_SZ]; 321 | char realm[REALM_SZ]; 322 | char *q; 323 | int ret; 324 | 325 | if(krb_get_lrealm(realm, 1)){ 326 | Debug ("Can't get Kerberos realm.\n"); 327 | } else { 328 | 329 | snprintf(krbtkfile, sizeof(krbktfile), "%s.%s", 330 | TKT_ROOT, d->name); 331 | krb_set_tkt_string(krbtkfile); 332 | unlink(krbtkfile); 333 | 334 | ret = krb_verify_user(greet->name, "", realm, 335 | greet->password, 1, "rcmd"); 336 | 337 | if(ret == KSUCCESS){ 338 | chown(krbtkfile, p->pw_uid, p->pw_gid); 339 | Debug("kerberos verify succeeded\n"); 340 | if (k_hasafs()) { 341 | if (k_setpag() == -1) 342 | LogError ("setpag() failed for %s\n", 343 | greet->name); 344 | 345 | if((ret = k_afsklog(NULL, NULL)) != KSUCCESS) 346 | LogError("Warning %s\n", 347 | krb_get_err_text(ret)); 348 | } 349 | goto done; 350 | } else if(ret != KDC_PR_UNKNOWN && ret != SKDC_CANT){ 351 | /* failure */ 352 | Debug("kerberos verify failure %d\n", ret); 353 | krbtkfile[0] = '\0'; 354 | } 355 | } 356 | } 357 | # endif 358 | # ifdef HAVE_GETSPNAM 359 | errno = 0; 360 | sp = getspnam(greet->name); 361 | if (sp == NULL) { 362 | Debug ("getspnam() failed: %s\n", _SysErrorMsg (errno)); 363 | } else { 364 | user_pass = sp->sp_pwdp; 365 | } 366 | # ifndef QNX4 367 | endspent(); 368 | # endif /* QNX4 doesn't need endspent() to end shadow passwd ops */ 369 | # endif /* HAVE_GETSPNAM */ 370 | # if defined(ultrix) || defined(__ultrix__) 371 | if (authenticate_user(p, greet->password, NULL) < 0) 372 | # else 373 | crypted_pass = crypt (greet->password, user_pass); 374 | if ((crypted_pass == NULL) 375 | || (strcmp (crypted_pass, user_pass))) 376 | # endif 377 | { 378 | if(!greet->allow_null_passwd || strlen(p->pw_passwd) > 0) { 379 | Debug ("password verify failed\n"); 380 | bzero(greet->password, strlen(greet->password)); 381 | return 0; 382 | } /* else: null passwd okay */ 383 | } 384 | # ifdef KERBEROS 385 | done: 386 | # endif 387 | /* 388 | * Only accept root logins if allowRootLogin resource is set 389 | */ 390 | if ((p->pw_uid == 0) && !greet->allow_root_login) { 391 | Debug("root logins not allowed\n"); 392 | bzero(greet->password, strlen(greet->password)); 393 | return 0; 394 | } 395 | # ifdef __OpenBSD__ 396 | /* 397 | * Shell must be in /etc/shells 398 | */ 399 | for (;;) { 400 | s = getusershell(); 401 | if (s == NULL) { 402 | /* did not found the shell in /etc/shells 403 | -> failure */ 404 | Debug("shell not in /etc/shells\n"); 405 | bzero(greet->password, strlen(greet->password)); 406 | endusershell(); 407 | return 0; 408 | } 409 | if (strcmp(s, p->pw_shell) == 0) { 410 | /* found the shell in /etc/shells */ 411 | endusershell(); 412 | break; 413 | } 414 | } 415 | /* 416 | * Test for expired password 417 | */ 418 | if (p->pw_change || p->pw_expire) 419 | (void)gettimeofday(&tp, (struct timezone *)NULL); 420 | if (p->pw_change) { 421 | if (tp.tv_sec >= p->pw_change) { 422 | Debug("Password has expired.\n"); 423 | bzero(greet->password, strlen(greet->password)); 424 | return 0; 425 | } 426 | } 427 | if (p->pw_expire) { 428 | if (tp.tv_sec >= p->pw_expire) { 429 | Debug("account has expired.\n"); 430 | bzero(greet->password, strlen(greet->password)); 431 | return 0; 432 | } 433 | } 434 | # endif /* __OpenBSD__ */ 435 | bzero(user_pass, strlen(user_pass)); /* in case shadow password */ 436 | 437 | # endif /* USE_PAM */ 438 | #endif /* USE_BSDAUTH */ 439 | 440 | Debug ("verify succeeded\n"); 441 | /* The password is passed to StartClient() for use by user-based 442 | authorization schemes. It is zeroed there. */ 443 | verify->uid = p->pw_uid; 444 | verify->gid = p->pw_gid; 445 | home = p->pw_dir; 446 | shell = p->pw_shell; 447 | argv = NULL; 448 | if (d->session) 449 | argv = parseArgs (argv, d->session); 450 | if (greet->string) 451 | argv = parseArgs (argv, greet->string); 452 | if (!argv) 453 | argv = parseArgs (argv, "xsession"); 454 | verify->argv = argv; 455 | verify->userEnviron = userEnv (d, p->pw_uid == 0, 456 | greet->name, home, shell); 457 | Debug ("user environment:\n"); 458 | printEnv (verify->userEnviron); 459 | verify->systemEnviron = systemEnv (d, greet->name, home); 460 | Debug ("system environment:\n"); 461 | printEnv (verify->systemEnviron); 462 | Debug ("end of environments\n"); 463 | return 1; 464 | } 465 | -------------------------------------------------------------------------------- /xdm/resource.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 1988, 1998 The Open Group 4 | 5 | Permission to use, copy, modify, distribute, and sell this software and its 6 | documentation for any purpose is hereby granted without fee, provided that 7 | the above copyright notice appear in all copies and that both that 8 | copyright notice and this permission notice appear in supporting 9 | documentation. 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of The Open Group shall 23 | not be used in advertising or otherwise to promote the sale, use or 24 | other dealings in this Software without prior written authorization 25 | from The Open Group. 26 | 27 | */ 28 | 29 | /* 30 | * xdm - display manager daemon 31 | * Author: Keith Packard, MIT X Consortium 32 | * 33 | * resource.c 34 | */ 35 | 36 | #include "dm.h" 37 | #include "dm_error.h" 38 | 39 | #include 40 | #include 41 | 42 | char *config; 43 | 44 | char *servers; 45 | int request_port; 46 | int debugLevel; 47 | char *errorLogFile; 48 | int daemonMode; 49 | char *pidFile; 50 | int lockPidFile; 51 | int sourceAddress; 52 | char *authDir; 53 | int autoRescan; 54 | int removeDomainname; 55 | char *keyFile; 56 | char *accessFile; 57 | char **exportList; 58 | #if !defined(HAVE_ARC4RANDOM) 59 | char *randomFile; 60 | #endif 61 | #ifdef DEV_RANDOM 62 | char *randomDevice; 63 | #endif 64 | #if !defined(HAVE_ARC4RANDOM) 65 | char *prngdSocket; 66 | int prngdPort; 67 | #endif 68 | 69 | char *greeterLib; 70 | char *willing; 71 | int choiceTimeout; /* chooser choice timeout */ 72 | 73 | #define DM_STRING 0 74 | #define DM_INT 1 75 | #define DM_BOOL 2 76 | #define DM_ARGV 3 77 | 78 | /* 79 | * The following constants are supposed to be set in Makefile or config.h 80 | * from parameters set in configure. DO NOT CHANGE THESE DEFINITIONS! 81 | */ 82 | #ifndef DEF_SERVER_LINE 83 | # define DEF_SERVER_LINE ":0 local /usr/bin/X11/X :0" 84 | #endif 85 | #ifndef XRDB_PROGRAM 86 | # define XRDB_PROGRAM "/usr/bin/X11/xrdb" 87 | #endif 88 | #ifndef DEF_SESSION 89 | # define DEF_SESSION "/usr/bin/X11/xterm -ls" 90 | #endif 91 | #ifndef DEF_USER_PATH 92 | # define DEF_USER_PATH ":/bin:/usr/bin:/usr/bin/X11:/usr/ucb" 93 | #endif 94 | #ifndef DEF_SYSTEM_PATH 95 | # define DEF_SYSTEM_PATH "/etc:/bin:/usr/bin:/usr/bin/X11:/usr/ucb" 96 | #endif 97 | #ifndef DEF_SYSTEM_SHELL 98 | # define DEF_SYSTEM_SHELL "/bin/sh" 99 | #endif 100 | #ifndef DEF_FAILSAFE_CLIENT 101 | # define DEF_FAILSAFE_CLIENT "/usr/bin/X11/xterm" 102 | #endif 103 | #ifndef DEF_XDM_CONFIG 104 | # define DEF_XDM_CONFIG "/usr/lib/X11/xdm/xdm-config" 105 | #endif 106 | #ifndef DEF_CHOOSER 107 | # define DEF_CHOOSER "/usr/lib/X11/xdm/chooser" 108 | #endif 109 | #ifndef DEF_GREETER 110 | # define DEF_GREETER "" 111 | #endif 112 | #ifndef DEF_AUTH_NAME 113 | # ifdef HASXDMAUTH 114 | # define DEF_AUTH_NAME "XDM-AUTHORIZATION-1 MIT-MAGIC-COOKIE-1" 115 | # else 116 | # define DEF_AUTH_NAME "MIT-MAGIC-COOKIE-1" 117 | # endif 118 | #endif 119 | #ifndef DEF_AUTH_DIR 120 | # define DEF_AUTH_DIR "/usr/lib/X11/xdm" 121 | #endif 122 | #ifndef DEF_USER_AUTH_DIR 123 | # define DEF_USER_AUTH_DIR "/tmp" 124 | #endif 125 | #ifndef DEF_KEY_FILE 126 | # define DEF_KEY_FILE "" 127 | #endif 128 | #ifndef DEF_ACCESS_FILE 129 | # define DEF_ACCESS_FILE "" 130 | #endif 131 | #ifndef DEF_RANDOM_FILE 132 | # define DEF_RANDOM_FILE "/dev/mem" 133 | #endif 134 | #ifndef DEF_PRNGD_SOCKET 135 | # define DEF_PRNGD_SOCKET "/tmp/entropy" 136 | #endif 137 | #ifndef DEF_PRNGD_PORT 138 | # define DEF_PRNGD_PORT "0" 139 | #endif 140 | #ifndef DEF_GREETER_LIB 141 | # define DEF_GREETER_LIB "/usr/lib/X11/xdm/libXdmGreet.so" 142 | #endif 143 | 144 | #define DEF_UDP_PORT "177" /* registered XDMCP port, dont change */ 145 | 146 | struct dmResources { 147 | const char *name, *class; 148 | int type; 149 | char **dm_value; 150 | const char *default_value; 151 | } DmResources[] = { 152 | { "servers", "Servers", DM_STRING, &servers, 153 | DEF_SERVER_LINE} , 154 | { "requestPort","RequestPort", DM_INT, (char **) &request_port, 155 | DEF_UDP_PORT} , 156 | { "debugLevel", "DebugLevel", DM_INT, (char **) &debugLevel, 157 | "0"} , 158 | { "errorLogFile","ErrorLogFile", DM_STRING, &errorLogFile, 159 | ""} , 160 | { "daemonMode", "DaemonMode", DM_BOOL, (char **) &daemonMode, 161 | "true"} , 162 | { "pidFile", "PidFile", DM_STRING, &pidFile, 163 | ""} , 164 | { "lockPidFile","LockPidFile", DM_BOOL, (char **) &lockPidFile, 165 | "true"} , 166 | { "authDir", "authDir", DM_STRING, &authDir, 167 | DEF_AUTH_DIR} , 168 | { "autoRescan", "AutoRescan", DM_BOOL, (char **) &autoRescan, 169 | "true"} , 170 | { "removeDomainname","RemoveDomainname",DM_BOOL,(char **) &removeDomainname, 171 | "true"} , 172 | { "keyFile", "KeyFile", DM_STRING, &keyFile, 173 | DEF_KEY_FILE} , 174 | { "accessFile", "AccessFile", DM_STRING, &accessFile, 175 | DEF_ACCESS_FILE} , 176 | { "exportList", "ExportList", DM_ARGV, (char **) &exportList, 177 | ""} , 178 | #if !defined(HAVE_ARC4RANDOM) 179 | { "randomFile", "RandomFile", DM_STRING, &randomFile, 180 | DEF_RANDOM_FILE} , 181 | { "prngdSocket", "PrngdSocket", DM_STRING, &prngdSocket, 182 | DEF_PRNGD_SOCKET}, 183 | { "prngdPort", "PrngdPort", DM_INT, (char **) &prngdPort, 184 | DEF_PRNGD_PORT}, 185 | #endif 186 | #ifdef DEV_RANDOM 187 | { "randomDevice", "RandomDevice", DM_STRING, &randomDevice, 188 | DEV_RANDOM} , 189 | #endif 190 | { "greeterLib", "GreeterLib", DM_STRING, &greeterLib, 191 | DEF_GREETER_LIB} , 192 | { "choiceTimeout","ChoiceTimeout",DM_INT, (char **) &choiceTimeout, 193 | "15"} , 194 | { "sourceAddress","SourceAddress",DM_BOOL, (char **) &sourceAddress, 195 | "false"} , 196 | { "willing", "Willing", DM_STRING, &willing, 197 | ""} , 198 | }; 199 | 200 | #define NUM_DM_RESOURCES (sizeof DmResources / sizeof DmResources[0]) 201 | 202 | #define boffset(f) XtOffsetOf(struct display, f) 203 | 204 | struct displayResource { 205 | const char *name, *class; 206 | int type; 207 | int offset; 208 | const char *default_value; 209 | }; 210 | 211 | /* resources for managing the server */ 212 | 213 | struct displayResource serverResources[] = { 214 | { "serverAttempts","ServerAttempts",DM_INT, boffset(serverAttempts), 215 | "1" }, 216 | { "openDelay", "OpenDelay", DM_INT, boffset(openDelay), 217 | "15" }, 218 | { "openRepeat", "OpenRepeat", DM_INT, boffset(openRepeat), 219 | "5" }, 220 | { "openTimeout","OpenTimeout", DM_INT, boffset(openTimeout), 221 | "120" }, 222 | { "startAttempts","StartAttempts",DM_INT, boffset(startAttempts), 223 | "4" }, 224 | { "reservAttempts","ReservAttempts",DM_INT, boffset(reservAttempts), 225 | "2" }, 226 | { "pingInterval","PingInterval",DM_INT, boffset(pingInterval), 227 | "5" }, 228 | { "pingTimeout","PingTimeout", DM_INT, boffset(pingTimeout), 229 | "5" }, 230 | { "terminateServer","TerminateServer",DM_BOOL, boffset(terminateServer), 231 | "false" }, 232 | { "grabServer", "GrabServer", DM_BOOL, boffset(grabServer), 233 | "false" }, 234 | { "grabTimeout","GrabTimeout", DM_INT, boffset(grabTimeout), 235 | "3" }, 236 | { "resetSignal","Signal", DM_INT, boffset(resetSignal), 237 | "1" }, /* SIGHUP */ 238 | { "termSignal", "Signal", DM_INT, boffset(termSignal), 239 | "15" }, /* SIGTERM */ 240 | { "resetForAuth","ResetForAuth",DM_BOOL, boffset(resetForAuth), 241 | "false" }, 242 | { "authorize", "Authorize", DM_BOOL, boffset(authorize), 243 | "true" }, 244 | { "authComplain","AuthComplain",DM_BOOL, boffset(authComplain), 245 | "true" }, 246 | { "authName", "AuthName", DM_ARGV, boffset(authNames), 247 | DEF_AUTH_NAME }, 248 | { "authFile", "AuthFile", DM_STRING, boffset(clientAuthFile), 249 | "" }, 250 | }; 251 | 252 | #define NUM_SERVER_RESOURCES (sizeof serverResources/\ 253 | sizeof serverResources[0]) 254 | 255 | /* resources which control the session behaviour */ 256 | 257 | struct displayResource sessionResources[] = { 258 | { "resources", "Resources", DM_STRING, boffset(resources), 259 | "" }, 260 | { "xrdb", "Xrdb", DM_STRING, boffset(xrdb), 261 | XRDB_PROGRAM }, 262 | { "setup", "Setup", DM_STRING, boffset(setup), 263 | "" }, 264 | { "startup", "Startup", DM_STRING, boffset(startup), 265 | "" }, 266 | { "reset", "Reset", DM_STRING, boffset(reset), 267 | "" }, 268 | { "session", "Session", DM_STRING, boffset(session), 269 | DEF_SESSION }, 270 | { "userPath", "Path", DM_STRING, boffset(userPath), 271 | DEF_USER_PATH }, 272 | { "systemPath", "Path", DM_STRING, boffset(systemPath), 273 | DEF_SYSTEM_PATH }, 274 | { "systemShell","Shell", DM_STRING, boffset(systemShell), 275 | DEF_SYSTEM_SHELL }, 276 | { "failsafeClient","FailsafeClient", DM_STRING, boffset(failsafeClient), 277 | DEF_FAILSAFE_CLIENT }, 278 | { "userAuthDir","UserAuthDir", DM_STRING, boffset(userAuthDir), 279 | DEF_USER_AUTH_DIR }, 280 | { "chooser", "Chooser", DM_STRING, boffset(chooser), 281 | DEF_CHOOSER }, 282 | { "greeter", "Greeter", DM_STRING, boffset(greeter), 283 | DEF_GREETER }, 284 | }; 285 | 286 | #define NUM_SESSION_RESOURCES (sizeof sessionResources/\ 287 | sizeof sessionResources[0]) 288 | 289 | XrmDatabase DmResourceDB; 290 | 291 | static void 292 | GetResource ( 293 | const char *name, 294 | const char *class, 295 | int valueType, 296 | char **valuep, 297 | const char *default_value) 298 | { 299 | char *type; 300 | XrmValue value; 301 | const char *string; 302 | char *new_string; 303 | char str_buf[50]; 304 | int len; 305 | 306 | if (DmResourceDB && XrmGetResource (DmResourceDB, 307 | name, class, 308 | &type, &value)) 309 | { 310 | string = value.addr; 311 | len = value.size; 312 | } 313 | else 314 | { 315 | string = default_value; 316 | len = strlen (string); 317 | } 318 | 319 | Debug ("%s/%s value %*.*s\n", name, class, len, len, string); 320 | 321 | if (valueType == DM_STRING && *valuep) 322 | { 323 | if (strlen (*valuep) == len && !strncmp (*valuep, string, len)) 324 | return; 325 | else 326 | free (*valuep); 327 | } 328 | 329 | switch (valueType) { 330 | case DM_STRING: 331 | new_string = calloc ((unsigned) (len+1), sizeof(*new_string)); 332 | if (!new_string) { 333 | LogOutOfMem ("GetResource"); 334 | return; 335 | } 336 | strncpy (new_string, string, len); 337 | new_string[len] = '\0'; 338 | *(valuep) = new_string; 339 | break; 340 | case DM_INT: 341 | strncpy (str_buf, string, sizeof (str_buf)); 342 | str_buf[sizeof (str_buf)-1] = '\0'; 343 | *((int *) valuep) = atoi (str_buf); 344 | break; 345 | case DM_BOOL: 346 | strncpy (str_buf, string, sizeof (str_buf)); 347 | str_buf[sizeof (str_buf)-1] = '\0'; 348 | XmuCopyISOLatin1Lowered (str_buf, str_buf); 349 | if (!strcmp (str_buf, "true") || 350 | !strcmp (str_buf, "on") || 351 | !strcmp (str_buf, "yes")) 352 | *((int *) valuep) = 1; 353 | else if (!strcmp (str_buf, "false") || 354 | !strcmp (str_buf, "off") || 355 | !strcmp (str_buf, "no")) 356 | *((int *) valuep) = 0; 357 | break; 358 | case DM_ARGV: 359 | freeArgs (*(char ***) valuep); 360 | *((char ***) valuep) = parseArgs ((char **) 0, string); 361 | break; 362 | } 363 | } 364 | 365 | XrmOptionDescRec configTable [] = { 366 | {"-server", NULL, XrmoptionSkipArg, (caddr_t) NULL }, 367 | {"-udpPort", NULL, XrmoptionSkipArg, (caddr_t) NULL }, 368 | {"-error", NULL, XrmoptionSkipArg, (caddr_t) NULL }, 369 | {"-resources", NULL, XrmoptionSkipArg, (caddr_t) NULL }, 370 | {"-session", NULL, XrmoptionSkipArg, (caddr_t) NULL }, 371 | {"-debug", NULL, XrmoptionSkipArg, (caddr_t) NULL }, 372 | {"-xrm", NULL, XrmoptionSkipArg, (caddr_t) NULL }, 373 | {"-config", ".configFile", XrmoptionSepArg, (caddr_t) NULL } 374 | }; 375 | 376 | XrmOptionDescRec optionTable [] = { 377 | {"-server", ".servers", XrmoptionSepArg, (caddr_t) NULL }, 378 | {"-udpPort", ".requestPort", XrmoptionSepArg, (caddr_t) NULL }, 379 | {"-error", ".errorLogFile", XrmoptionSepArg, (caddr_t) NULL }, 380 | {"-resources", "*resources", XrmoptionSepArg, (caddr_t) NULL }, 381 | {"-session", "*session", XrmoptionSepArg, (caddr_t) NULL }, 382 | {"-debug", "*debugLevel", XrmoptionSepArg, (caddr_t) NULL }, 383 | {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL }, 384 | {"-daemon", ".daemonMode", XrmoptionNoArg, "true" }, 385 | {"-nodaemon", ".daemonMode", XrmoptionNoArg, "false" } 386 | }; 387 | 388 | static int originalArgc; 389 | static char **originalArgv; 390 | 391 | void 392 | InitResources (int argc, char **argv) 393 | { 394 | XrmInitialize (); 395 | originalArgc = argc; 396 | originalArgv = argv; 397 | ReinitResources (); 398 | } 399 | 400 | void 401 | ReinitResources (void) 402 | { 403 | int argc; 404 | char **a; 405 | char **argv; 406 | XrmDatabase newDB; 407 | 408 | argv = calloc ((originalArgc + 1), sizeof (char *)); 409 | if (!argv) 410 | LogPanic ("no space for argument realloc\n"); 411 | for (argc = 0; argc < originalArgc; argc++) 412 | argv[argc] = originalArgv[argc]; 413 | argv[argc] = NULL; 414 | if (DmResourceDB) 415 | XrmDestroyDatabase (DmResourceDB); 416 | DmResourceDB = XrmGetStringDatabase (""); 417 | /* pre-parse the command line to get the -config option, if any */ 418 | XrmParseCommand (&DmResourceDB, configTable, 419 | sizeof (configTable) / sizeof (configTable[0]), 420 | "DisplayManager", &argc, argv); 421 | GetResource ("DisplayManager.configFile", "DisplayManager.ConfigFile", 422 | DM_STRING, &config, DEF_XDM_CONFIG); 423 | newDB = XrmGetFileDatabase ( config ); 424 | if (newDB) 425 | { 426 | if (DmResourceDB) 427 | XrmDestroyDatabase (DmResourceDB); 428 | DmResourceDB = newDB; 429 | } 430 | else if (argc != originalArgc) 431 | LogError ("Can't open configuration file %s\n", config ); 432 | XrmParseCommand (&DmResourceDB, optionTable, 433 | sizeof (optionTable) / sizeof (optionTable[0]), 434 | "DisplayManager", &argc, argv); 435 | if (argc > 1) 436 | { 437 | LogError ("extra arguments on command line:"); 438 | for (a = argv + 1; *a; a++) 439 | LogAppend (" \"%s\"", *a); 440 | LogAppend ("\n"); 441 | } 442 | free (argv); 443 | } 444 | 445 | void 446 | LoadDMResources (void) 447 | { 448 | int i; 449 | char name[1024], class[1024]; 450 | 451 | for (i = 0; i < NUM_DM_RESOURCES; i++) { 452 | snprintf (name, sizeof(name), "DisplayManager.%s", DmResources[i].name); 453 | snprintf (class, sizeof(class), "DisplayManager.%s", DmResources[i].class); 454 | GetResource (name, class, DmResources[i].type, 455 | (char **) DmResources[i].dm_value, 456 | DmResources[i].default_value); 457 | } 458 | } 459 | 460 | static void 461 | CleanUpName (char *src, char *dst, int len) 462 | { 463 | while (*src) { 464 | if (--len <= 0) 465 | break; 466 | switch (*src) 467 | { 468 | case ':': 469 | case '.': 470 | *dst++ = '_'; 471 | break; 472 | default: 473 | *dst++ = *src; 474 | } 475 | ++src; 476 | } 477 | *dst = '\0'; 478 | } 479 | 480 | static void 481 | LoadDisplayResources ( 482 | struct display *d, 483 | struct displayResource *resources, 484 | int numResources) 485 | { 486 | int i; 487 | char name[1024], class[1024]; 488 | char dpyName[512], dpyClass[512]; 489 | 490 | CleanUpName (d->name, dpyName, sizeof (dpyName)); 491 | CleanUpName (d->class ? d->class : d->name, dpyClass, sizeof (dpyClass)); 492 | for (i = 0; i < numResources; i++) { 493 | snprintf (name, sizeof(name), "DisplayManager.%s.%s", 494 | dpyName, resources[i].name); 495 | snprintf (class, sizeof(class), "DisplayManager.%s.%s", 496 | dpyClass, resources[i].class); 497 | GetResource (name, class, resources[i].type, 498 | (char **) (((char *) d) + resources[i].offset), 499 | resources[i].default_value); 500 | } 501 | } 502 | 503 | void 504 | LoadServerResources (struct display *d) 505 | { 506 | LoadDisplayResources (d, serverResources, NUM_SERVER_RESOURCES); 507 | } 508 | 509 | void 510 | LoadSessionResources (struct display *d) 511 | { 512 | LoadDisplayResources (d, sessionResources, NUM_SESSION_RESOURCES); 513 | } 514 | --------------------------------------------------------------------------------