6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
10 * Glue routines to allow the database stuff to be linked in to
11 * a program expecting a library level interface.
15 static char *rcsid_mr_glue_c = "$Header$";
18 #include <mit-copyright.h>
19 #include <sys/types.h>
20 #include <sys/signal.h>
24 #include "mr_server.h"
27 static int already_connected = 0;
29 #define CHECK_CONNECTED { if (!already_connected) return MR_NOT_CONNECTED; }
31 static client pseudo_client;
41 extern int query_timeout;
42 struct sigaction action;
44 if (already_connected) return MR_ALREADY_CONNECTED;
46 initialize_sms_error_table();
47 initialize_krb_error_table();
48 memset((char *)&pseudo_client, 0, sizeof(pseudo_client)); /* XXX */
51 status = mr_open_database();
52 if (!status) already_connected = 1;
55 sigemptyset(&action.sa_mask);
56 sigaddset(&action.sa_mask, SIGCHLD);
57 action.sa_handler = reapchild;
58 if (sigaction(SIGCHLD, &action, NULL) < 0) {
59 com_err(whoami, errno, "Unable to establish signal handlers.");
69 already_connected = 0;
79 * This routine is rather bogus, as it only fills in who you claim to be.
85 extern char *krb_realm;
86 char buf[1024], *strsave();
89 pw = getpwuid(getuid());
90 if (!pw) return (KDC_PR_UNKNOWN + ERROR_TABLE_BASE_krb); /* XXX hack (we
94 strcpy(pseudo_client.kname.name, pw->pw_name);
95 krb_get_lrealm(pseudo_client.kname.realm, 1);
96 krb_realm = pseudo_client.kname.realm;
98 strcpy(buf, pw->pw_name);
100 strcat(buf, pseudo_client.kname.realm);
101 strcpy(pseudo_client.clname, buf);
102 pseudo_client.users_id = 0;
103 name_to_id(pseudo_client.kname.name, USERS_TABLE, &pseudo_client.users_id);
104 pseudo_client.client_id = pseudo_client.users_id;
105 strncpy(pseudo_client.entity, prog, 8);
106 pseudo_client.args = (mr_params *) malloc(sizeof(mr_params));
107 pseudo_client.args->mr_version_no = MR_VERSION_2;
116 callback(argc, argv, arg)
121 if (mr_trim_args(argc, argv) == MR_NO_MEM) {
122 com_err(whoami, MR_NO_MEM, "while trimmming args");
124 (*arg->proc)(argc, argv, arg->hint);
128 int mr_query(name, argc, argv, callproc, callarg)
129 char *name; /* Query name */
130 int argc; /* Arg count */
131 char **argv; /* Args */
132 int (*callproc)(); /* Callback procedure */
133 char *callarg; /* Callback argument */
138 hints.proc = callproc;
139 hints.hint = callarg;
141 return mr_process_query(&pseudo_client, name, argc,
142 mr_copy_args(argv, argc), callback, &hints);
146 int mr_access(name, argc, argv)
147 char *name; /* Query name */
148 int argc; /* Arg count */
149 char **argv; /* Args */
152 return mr_check_access(&pseudo_client, name, argc,
153 mr_copy_args(argv, argc));
156 int mr_query_internal(argc, argv, callproc, callarg)
165 hints.proc = callproc;
166 hints.hint = callarg;
168 return mr_process_query(&pseudo_client, argv[0], argc-1,
169 mr_copy_args(argv+1, argc-1), callback, &hints);
172 int mr_access_internal(argc, argv)
177 return mr_check_access(&pseudo_client, argv[0], argc-1,
178 mr_copy_args(argv+1, argc-1));
184 fprintf(stderr, "Sorry, not implemented\n");
188 /* trigger_dcm is also used as a followup routine to the
189 * set_server_host_override query, hence the two dummy arguments.
192 struct query pseudo_query = {
197 trigger_dcm(dummy0, dummy1, cl)
201 register int pid, status;
204 if (status = check_query_access(&pseudo_query, 0, cl))
207 sprintf(prog, "%s/startdcm", BIN_DIR);
211 execl(prog, "startdcm", 0);
227 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
228 if (pid == inc_pid) {
232 if (WTERMSIG(status) != 0 || WEXITSTATUS(status) != 0)
233 com_err(whoami, 0, "%d: child exits with signal %d status %d",
234 pid, WTERMSIG(status), WEXITSTATUS(status));