]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * For copying and distribution information, please see the file | |
8 | * <mit-copyright.h>. | |
9 | * | |
10 | * Glue routines to allow the database stuff to be linked in to | |
11 | * a program expecting a library level interface. | |
12 | */ | |
13 | ||
14 | #ifndef lint | |
15 | static char *rcsid_mr_glue_c = "$Header$"; | |
16 | #endif lint | |
17 | ||
18 | #include <mit-copyright.h> | |
19 | #include "mr_server.h" | |
20 | #include <sys/types.h> | |
21 | #include <sys/signal.h> | |
22 | #include <sys/wait.h> | |
23 | #include <krb_et.h> | |
24 | #include <pwd.h> | |
25 | #include "query.h" | |
26 | ||
27 | static int already_connected = 0; | |
28 | ||
29 | #define CHECK_CONNECTED { if (!already_connected) return MR_NOT_CONNECTED; } | |
30 | ||
31 | static client pseudo_client; | |
32 | extern int errno; | |
33 | extern char *malloc(), *whoami; | |
34 | extern time_t now; | |
35 | void reapchild(); | |
36 | ||
37 | mr_connect(server) | |
38 | char *server; | |
39 | { | |
40 | register int status; | |
41 | extern int query_timeout; | |
42 | ||
43 | if (already_connected) return MR_ALREADY_CONNECTED; | |
44 | ||
45 | initialize_sms_error_table(); | |
46 | initialize_krb_error_table(); | |
47 | bzero((char *)&pseudo_client, sizeof(pseudo_client)); /* XXX */ | |
48 | ||
49 | query_timeout = 0; | |
50 | status = mr_open_database(); | |
51 | if (!status) already_connected = 1; | |
52 | ||
53 | signal(SIGCHLD, reapchild); | |
54 | return status; | |
55 | } | |
56 | ||
57 | mr_disconnect() | |
58 | { | |
59 | CHECK_CONNECTED; | |
60 | mr_close_database(); | |
61 | already_connected = 0; | |
62 | return 0; | |
63 | } | |
64 | ||
65 | mr_noop() | |
66 | { | |
67 | CHECK_CONNECTED; | |
68 | return 0; | |
69 | } | |
70 | /* | |
71 | * This routine is rather bogus, as it only fills in who you claim to be. | |
72 | */ | |
73 | mr_auth(prog) | |
74 | char *prog; | |
75 | { | |
76 | struct passwd *pw; | |
77 | extern char *krb_realm; | |
78 | char buf[1024], *strsave(); | |
79 | ||
80 | CHECK_CONNECTED; | |
81 | pw = getpwuid(getuid()); | |
82 | if (!pw) return (KDC_PR_UNKNOWN + ERROR_TABLE_BASE_krb); /* XXX hack (we | |
83 | * need an extended | |
84 | * error code table) | |
85 | */ | |
86 | strcpy(pseudo_client.kname.name, pw->pw_name); | |
87 | krb_get_lrealm(pseudo_client.kname.realm, 1); | |
88 | krb_realm = pseudo_client.kname.realm; | |
89 | ||
90 | strcpy(buf, pw->pw_name); | |
91 | strcat(buf, "@"); | |
92 | strcat(buf, pseudo_client.kname.realm); | |
93 | strcpy(pseudo_client.clname, buf); | |
94 | pseudo_client.users_id = 0; | |
95 | name_to_id(pseudo_client.kname.name, "USER", &pseudo_client.users_id); | |
96 | pseudo_client.client_id = pseudo_client.users_id; | |
97 | strcpy(pseudo_client.entity, prog); | |
98 | pseudo_client.args = (mr_params *) malloc(sizeof(mr_params)); | |
99 | pseudo_client.args->mr_version_no = MR_VERSION_2; | |
100 | return 0; | |
101 | } | |
102 | ||
103 | struct hint { | |
104 | int (*proc)(); | |
105 | char *hint; | |
106 | }; | |
107 | ||
108 | callback(argc, argv, arg) | |
109 | int argc; | |
110 | char **argv; | |
111 | struct hint *arg; | |
112 | { | |
113 | if (mr_trim_args(argc, argv) == MR_NO_MEM) { | |
114 | com_err(whoami, MR_NO_MEM, "while trimmming args"); | |
115 | } | |
116 | (*arg->proc)(argc, argv, arg->hint); | |
117 | } | |
118 | ||
119 | ||
120 | int mr_query(name, argc, argv, callproc, callarg) | |
121 | char *name; /* Query name */ | |
122 | int argc; /* Arg count */ | |
123 | char **argv; /* Args */ | |
124 | int (*callproc)(); /* Callback procedure */ | |
125 | char *callarg; /* Callback argument */ | |
126 | { | |
127 | struct hint hints; | |
128 | ||
129 | time(&now); | |
130 | hints.proc = callproc; | |
131 | hints.hint = callarg; | |
132 | next_incremental(); | |
133 | return mr_process_query(&pseudo_client, name, argc, | |
134 | mr_copy_args(argv, argc), callback, &hints); | |
135 | ||
136 | } | |
137 | ||
138 | int mr_access(name, argc, argv) | |
139 | char *name; /* Query name */ | |
140 | int argc; /* Arg count */ | |
141 | char **argv; /* Args */ | |
142 | { | |
143 | time(&now); | |
144 | return mr_check_access(&pseudo_client, name, argc, | |
145 | mr_copy_args(argv, argc)); | |
146 | } | |
147 | ||
148 | int mr_query_internal(argc, argv, callproc, callarg) | |
149 | int argc; | |
150 | char **argv; | |
151 | int (*callproc)(); | |
152 | char *callarg; | |
153 | { | |
154 | struct hint hints; | |
155 | ||
156 | time(&now); | |
157 | hints.proc = callproc; | |
158 | hints.hint = callarg; | |
159 | next_incremental(); | |
160 | return mr_process_query(&pseudo_client, argv[0], argc-1, | |
161 | mr_copy_args(argv+1, argc-1), callback, &hints); | |
162 | } | |
163 | ||
164 | int mr_access_internal(argc, argv) | |
165 | int argc; | |
166 | char **argv; | |
167 | { | |
168 | time(&now); | |
169 | return mr_check_access(&pseudo_client, argv[0], argc-1, | |
170 | mr_copy_args(argv+1, argc-1)); | |
171 | } | |
172 | ||
173 | mr_shutdown(why) | |
174 | char *why; | |
175 | { | |
176 | fprintf(stderr, "Sorry, not implemented\n"); | |
177 | } | |
178 | ||
179 | ||
180 | /* trigger_dcm is also used as a followup routine to the | |
181 | * set_server_host_override query, hence the two dummy arguments. | |
182 | */ | |
183 | ||
184 | struct query pseudo_query = { | |
185 | "trigger_dcm", | |
186 | "tdcm", | |
187 | }; | |
188 | ||
189 | trigger_dcm(dummy0, dummy1, cl) | |
190 | int dummy0, dummy1; | |
191 | client *cl; | |
192 | { | |
193 | register int pid, status; | |
194 | char prog[128]; | |
195 | ||
196 | if (status = check_query_access(&pseudo_query, 0, cl)) | |
197 | return(status); | |
198 | ||
199 | sprintf(prog, "%s/startdcm", BIN_DIR); | |
200 | pid = vfork(); | |
201 | switch (pid) { | |
202 | case 0: | |
203 | execl(prog, "startdcm", 0); | |
204 | exit(1); | |
205 | ||
206 | case -1: | |
207 | return(errno); | |
208 | ||
209 | default: | |
210 | return(MR_SUCCESS); | |
211 | } | |
212 | } | |
213 | ||
214 | ||
215 | void reapchild() | |
216 | { | |
217 | union wait status; | |
218 | int pid; | |
219 | ||
220 | while ((pid = wait3(&status, WNOHANG, (struct rusage *)0)) > 0) { | |
221 | if (pid == inc_pid) { | |
222 | inc_running = 0; | |
223 | next_incremental(); | |
224 | } | |
225 | if (status.w_termsig != 0 || status.w_retcode != 0) | |
226 | com_err(whoami, 0, "%d: child exits with signal %d status %d", | |
227 | pid, status.w_termsig, status.w_retcode); | |
228 | } | |
229 | } |