]>
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_sms_glue_c = "$Header$"; | |
16 | #endif lint | |
17 | ||
18 | #include <mit-copyright.h> | |
19 | #include "sms_server.h" | |
20 | #include <krb_et.h> | |
21 | #include <pwd.h> | |
22 | #include "query.h" | |
23 | ||
24 | static int already_connected = 0; | |
25 | ||
26 | #define CHECK_CONNECTED { if (!already_connected) return SMS_NOT_CONNECTED; } | |
27 | ||
28 | static client pseudo_client; | |
29 | extern int errno; | |
30 | extern char *malloc(), *whoami; | |
31 | extern time_t now; | |
32 | ||
33 | sms_connect(server) | |
34 | char *server; | |
35 | { | |
36 | register int status; | |
37 | extern int query_timeout; | |
38 | ||
39 | if (already_connected) return SMS_ALREADY_CONNECTED; | |
40 | ||
41 | initialize_sms_error_table(); | |
42 | initialize_krb_error_table(); | |
43 | bzero((char *)&pseudo_client, sizeof(pseudo_client)); /* XXX */ | |
44 | ||
45 | query_timeout = 0; | |
46 | status = sms_open_database(); | |
47 | if (!status) already_connected = 1; | |
48 | return status; | |
49 | } | |
50 | ||
51 | sms_disconnect() | |
52 | { | |
53 | CHECK_CONNECTED; | |
54 | sms_close_database(); | |
55 | already_connected = 0; | |
56 | return 0; | |
57 | } | |
58 | ||
59 | sms_noop() | |
60 | { | |
61 | CHECK_CONNECTED; | |
62 | return 0; | |
63 | } | |
64 | /* | |
65 | * This routine is rather bogus, as it only fills in who you claim to be. | |
66 | */ | |
67 | sms_auth(prog) | |
68 | char *prog; | |
69 | { | |
70 | struct passwd *pw; | |
71 | extern char *krb_realm; | |
72 | char buf[1024], *strsave(); | |
73 | ||
74 | CHECK_CONNECTED; | |
75 | pw = getpwuid(getuid()); | |
76 | if (!pw) return (KDC_PR_UNKNOWN + ERROR_TABLE_BASE_krb); /* XXX hack (we | |
77 | * need an extended | |
78 | * error code table) | |
79 | */ | |
80 | strcpy(pseudo_client.kname.name, pw->pw_name); | |
81 | get_krbrlm(pseudo_client.kname.realm, 1); | |
82 | krb_realm = pseudo_client.kname.realm; | |
83 | ||
84 | strcpy(buf, pw->pw_name); | |
85 | strcat(buf, "@"); | |
86 | strcat(buf, pseudo_client.kname.realm); | |
87 | pseudo_client.clname = malloc(strlen(buf)+1); | |
88 | strcpy(pseudo_client.clname, buf); | |
89 | pseudo_client.users_id = get_users_id(pseudo_client.kname.name); | |
90 | pseudo_client.entity = strsave(prog); | |
91 | pseudo_client.args = (sms_params *) malloc(sizeof(sms_params)); | |
92 | pseudo_client.args->sms_version_no = SMS_VERSION_2; | |
93 | return 0; | |
94 | } | |
95 | ||
96 | struct hint { | |
97 | int (*proc)(); | |
98 | char *hint; | |
99 | }; | |
100 | ||
101 | callback(argc, argv, arg) | |
102 | int argc; | |
103 | char **argv; | |
104 | struct hint *arg; | |
105 | { | |
106 | if (sms_trim_args(argc, argv) == SMS_NO_MEM) { | |
107 | com_err(whoami, SMS_NO_MEM, "while trimmming args"); | |
108 | } | |
109 | (*arg->proc)(argc, argv, arg->hint); | |
110 | } | |
111 | ||
112 | ||
113 | int sms_query(name, argc, argv, callproc, callarg) | |
114 | char *name; /* Query name */ | |
115 | int argc; /* Arg count */ | |
116 | char **argv; /* Args */ | |
117 | int (*callproc)(); /* Callback procedure */ | |
118 | char *callarg; /* Callback argument */ | |
119 | { | |
120 | struct hint hints; | |
121 | ||
122 | time(&now); | |
123 | hints.proc = callproc; | |
124 | hints.hint = callarg; | |
125 | return sms_process_query(&pseudo_client, name, argc, argv, | |
126 | callback, &hints); | |
127 | } | |
128 | ||
129 | int sms_access(name, argc, argv) | |
130 | char *name; /* Query name */ | |
131 | int argc; /* Arg count */ | |
132 | char **argv; /* Args */ | |
133 | { | |
134 | time(&now); | |
135 | return sms_check_access(&pseudo_client, name, argc, argv); | |
136 | } | |
137 | ||
138 | int sms_query_internal(argc, argv, callproc, callarg) | |
139 | int argc; | |
140 | char **argv; | |
141 | int (*callproc)(); | |
142 | char *callarg; | |
143 | { | |
144 | struct hint hints; | |
145 | ||
146 | time(&now); | |
147 | hints.proc = callproc; | |
148 | hints.hint = callarg; | |
149 | return sms_process_query(&pseudo_client, argv[0], argc-1, argv+1, | |
150 | callback, &hints); | |
151 | } | |
152 | ||
153 | int sms_access_internal(argc, argv) | |
154 | int argc; | |
155 | char **argv; | |
156 | { | |
157 | time(&now); | |
158 | return sms_check_access(&pseudo_client, argv[0], argc-1, argv+1); | |
159 | } | |
160 | ||
161 | sms_shutdown(why) | |
162 | char *why; | |
163 | { | |
164 | fprintf(stderr, "Sorry, not implemented\n"); | |
165 | } | |
166 | ||
167 | ||
168 | /* trigger_dcm is also used as a followup routine to the | |
169 | * set_server_host_override query, hence the two dummy arguments. | |
170 | */ | |
171 | ||
172 | struct query pseudo_query = { | |
173 | "trigger_dcm", | |
174 | "tdcm", | |
175 | }; | |
176 | ||
177 | trigger_dcm(dummy0, dummy1, cl) | |
178 | int dummy0, dummy1; | |
179 | client *cl; | |
180 | { | |
181 | register int pid, status; | |
182 | ||
183 | if (status = check_query_access(&pseudo_query, 0, cl)) | |
184 | return(status); | |
185 | ||
186 | pid = vfork(); | |
187 | switch (pid) { | |
188 | case 0: | |
189 | execl("/u1/sms/bin/startdcm", "startdcm", 0); | |
190 | exit(1); | |
191 | ||
192 | case -1: | |
193 | return(errno); | |
194 | ||
195 | default: | |
196 | return(SMS_SUCCESS); | |
197 | } | |
198 | } |