summaryrefslogtreecommitdiff
path: root/xc/programs/xdm/greeter/greet.c
blob: bd6c2e3b73d51873bf207a8922ceae1346e38a7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * xdm - display manager daemon
 *
 * $XConsortium: greet.c,v 1.5 88/10/15 19:10:59 keith Exp $
 *
 * Copyright 1988 Massachusetts Institute of Technology
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of M.I.T. not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  M.I.T. makes no representations about the
 * suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 *
 * Author:  Keith Packard, MIT X Consortium
 */

/*
 * widget to get username/password
 *
 */

# include <X11/Xlib.h>
# include <X11/Intrinsic.h>
# include <X11/StringDefs.h>
# include <X11/Xmu.h>
# include "Login.h"
# include <X11/Shell.h>
# include <X11/Command.h>
# include <X11/Logo.h>
# include "dm.h"

extern Display	*dpy;

static int	done;
static char	name[128], password[128];
static Widget		toplevel;
static Widget		login;
static Widget		logoToplevel;
static Widget		logo;

GreetDone (w, data, status)
    Widget	w;
    LoginData	*data;
    int		status;
{
	Debug ("GreetDone: %s, %s\n", data->name, data->passwd);
	switch (status) {
	case NOTIFY_OK:
		strcpy (name, data->name);
		strcpy (password, data->passwd);
		done = 1;
		break;
	case NOTIFY_ABORT:
		Debug ("ABORT_DISPLAY\n");
		exit (ABORT_DISPLAY);
	case NOTIFY_RESTART:
		Debug ("RESTART_DISPLAY\n");
		exit (RESTART_DISPLAY);
	case NOTIFY_ABORT_DISPLAY:
		Debug ("DISABLE_DISPLAY\n");
		exit (DISABLE_DISPLAY);
	}
}

InitGreet (d)
struct display	*d;
{
	Arg		arglist[10];
	int		i;
	int		argc;
	static char	*argv[] = { "xlogin", "-display", 0, 0 };

	Debug ("greet %s\n", d->name);
	argv[2] = d->name;
	argc = 3;
	toplevel = XtInitialize ("main", "Xlogin", 0, 0, &argc, argv);
	Debug ("top level shell created\n");

	i = 0;
	XtSetArg (arglist[i], XtNnotifyDone, GreetDone); i++;

	login = XtCreateManagedWidget ("login", loginWidgetClass, toplevel,
					arglist, i);
	XtRealizeWidget (toplevel);
#ifdef DRAWLOGO
	i = 0;
	XtSetArg (arglist[i], XtNgeometry, "100x100-0-0"); i++;
	logoToplevel = XtCreateApplicationShell (0, topLevelShellWidgetClass,
						arglist, i);
	i = 0;
	logo = XtCreateManagedWidget ("logo", logoWidgetClass, logoToplevel,
					arglist, i);
	XtRealizeWidget (logoToplevel);
#endif
}

CloseGreet (d)
struct display	*d;
{
	XCloseDisplay (XtDisplay (toplevel));
}

Greet (d, greet)
struct display		*d;
struct greet_info	*greet;
{
	XEvent		event;
	Arg		args[1];

	Debug ("dispatching\n");
	done = 0;
	while (!done) {
		XtAppNextEvent (_XtDefaultAppContext(), &event);
		XtDispatchEvent (&event);
	}
	XFlush (XtDisplay (toplevel));
	greet->name = name;
	greet->password = password;
	XtSetArg (args[0], XtNsessionArgument, (char *) &(greet->string));
	XtGetValues (login, args, 1);
	Debug ("sessionArgument: %s\n", greet->string ? greet->string : "<NULL>");
}


FailedLogin (d, greet)
struct display	*d;
struct greet_info	*greet;
{
	DrawFail (login);
}