1 | /* |
---|
2 | * $Header: /afs/dev.mit.edu/source/repository/athena/bin/rkinit/rkinitd/rkinitd.c,v 1.1 1989-11-12 19:34:58 qjb Exp $ |
---|
3 | * $Source: /afs/dev.mit.edu/source/repository/athena/bin/rkinit/rkinitd/rkinitd.c,v $ |
---|
4 | * $Author: qjb $ |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #if !defined(lint) && !defined(SABER) |
---|
9 | static char *rcsid = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/rkinit/rkinitd/rkinitd.c,v 1.1 1989-11-12 19:34:58 qjb Exp $"; |
---|
10 | #endif lint || SABER |
---|
11 | |
---|
12 | #include <stdio.h> |
---|
13 | #include <ctype.h> |
---|
14 | #include <errno.h> |
---|
15 | #include <sys/types.h> |
---|
16 | #include <sys/file.h> |
---|
17 | #include <sys/socket.h> |
---|
18 | #include <netinet/in.h> |
---|
19 | #include <netdb.h> |
---|
20 | #include <strings.h> |
---|
21 | #include <signal.h> |
---|
22 | #include <sys/time.h> |
---|
23 | #include <pwd.h> |
---|
24 | #include <krb.h> |
---|
25 | #include <des.h> |
---|
26 | #include <syslog.h> |
---|
27 | |
---|
28 | #include <rkinit.h> |
---|
29 | #include <rkinit_err.h> |
---|
30 | #include <rkinit_private.h> |
---|
31 | |
---|
32 | extern int errno; |
---|
33 | extern char *sys_errlist[]; |
---|
34 | |
---|
35 | static int inetd = TRUE; /* True if we were started by inetd */ |
---|
36 | |
---|
37 | void usage() |
---|
38 | { |
---|
39 | syslog(LOG_ERR, "rkinitd usage: rkinitd [-notimeout]\n"); |
---|
40 | exit(1); |
---|
41 | } |
---|
42 | |
---|
43 | void error() |
---|
44 | { |
---|
45 | char errbuf[BUFSIZ]; |
---|
46 | |
---|
47 | strcpy(errbuf, rkinit_errmsg(0)); |
---|
48 | if (inetd) |
---|
49 | syslog(LOG_ERR, "rkinitd: %s", errbuf); |
---|
50 | else |
---|
51 | fprintf(stderr, "rkinitd: %s\n", errbuf); |
---|
52 | } |
---|
53 | |
---|
54 | main(argc, argv) |
---|
55 | int argc; |
---|
56 | char *argv[]; |
---|
57 | { |
---|
58 | int version; /* Version of the transaction */ |
---|
59 | |
---|
60 | int notimeout = FALSE; /* Should we not timeout? */ |
---|
61 | |
---|
62 | static char *envinit[1]; /* Empty environment */ |
---|
63 | extern char **environ; /* This process's environment */ |
---|
64 | |
---|
65 | int status = 0; /* General error code */ |
---|
66 | |
---|
67 | /* |
---|
68 | * Clear the environment so that this process does not inherit |
---|
69 | * kerberos ticket variable information from the person who started |
---|
70 | * the process (if a person started it...). |
---|
71 | */ |
---|
72 | environ = envinit; |
---|
73 | |
---|
74 | /* Initialize com_err error table */ |
---|
75 | initialize_rkin_error_table(); |
---|
76 | |
---|
77 | #ifdef DEBUG |
---|
78 | /* This only works if the library was compiled with DEBUG defined */ |
---|
79 | rki_i_am_server(); |
---|
80 | #endif DEBUG |
---|
81 | |
---|
82 | /* |
---|
83 | * Make sure that we are running as root or can arrange to be |
---|
84 | * running as root. We need both to be able to read /etc/srvtab |
---|
85 | * and to be able to change uid to create tickets. |
---|
86 | */ |
---|
87 | |
---|
88 | (void) setuid(0); |
---|
89 | if (getuid() != 0) { |
---|
90 | syslog(LOG_ERR, "rkinitd: not running as root.\n"); |
---|
91 | exit(1); |
---|
92 | } |
---|
93 | |
---|
94 | /* Determine whether to time out */ |
---|
95 | if (argc == 2) { |
---|
96 | if (strcmp(argv[1], "-notimeout")) |
---|
97 | usage(); |
---|
98 | else |
---|
99 | notimeout = TRUE; |
---|
100 | } |
---|
101 | else if (argc != 1) |
---|
102 | usage(); |
---|
103 | |
---|
104 | inetd = setup_rpc(notimeout); |
---|
105 | |
---|
106 | if ((status = choose_version(&version) != RKINIT_SUCCESS)) { |
---|
107 | error(); |
---|
108 | exit(1); |
---|
109 | } |
---|
110 | |
---|
111 | if ((status = get_tickets(version) != RKINIT_SUCCESS)) { |
---|
112 | error(); |
---|
113 | exit(1); |
---|
114 | } |
---|
115 | |
---|
116 | exit(0); |
---|
117 | } |
---|
118 | |
---|
119 | |
---|