3 * Glue routines to allow the database stuff to be linked in to
4 * a program expecting a library level interface.
6 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
12 #include "mr_server.h"
24 extern char *krb_get_lrealm(char *, int);
28 static int already_connected = 0;
30 #define CHECK_CONNECTED { if (!already_connected) return MR_NOT_CONNECTED; }
32 static client pseudo_client;
37 int callback(int argc, char **argv, void *arg);
39 int mr_connect(char *server)
42 extern int query_timeout;
43 struct sigaction action;
45 if (already_connected)
46 return MR_ALREADY_CONNECTED;
48 initialize_sms_error_table();
49 initialize_krb_error_table();
50 memset(&pseudo_client, 0, sizeof(pseudo_client));
53 status = mr_open_database();
55 already_connected = 1;
58 sigemptyset(&action.sa_mask);
59 sigaddset(&action.sa_mask, SIGCHLD);
60 action.sa_handler = reapchild;
61 if (sigaction(SIGCHLD, &action, NULL) < 0)
63 com_err(whoami, errno, "Unable to establish signal handlers.");
69 int mr_disconnect(void)
73 already_connected = 0;
84 * This routine is rather bogus, as it only fills in who you claim to be.
86 int mr_auth(char *prog)
89 extern char *krb_realm;
93 pw = getpwuid(getuid());
95 return KDC_PR_UNKNOWN + ERROR_TABLE_BASE_krb;
96 strcpy(pseudo_client.kname.name, pw->pw_name);
97 krb_get_lrealm(pseudo_client.kname.realm, 1);
98 krb_realm = pseudo_client.kname.realm;
100 strcpy(buf, pw->pw_name);
102 strcat(buf, pseudo_client.kname.realm);
103 strcpy(pseudo_client.clname, buf);
104 pseudo_client.users_id = 0;
105 name_to_id(pseudo_client.kname.name, USERS_TABLE, &pseudo_client.users_id);
106 pseudo_client.client_id = pseudo_client.users_id;
107 strncpy(pseudo_client.entity, prog, 8);
108 pseudo_client.args = malloc(sizeof(mr_params));
109 pseudo_client.args->mr_version_no = MR_VERSION_2;
114 int (*proc)(int, char **, void *);
118 int callback(int argc, char **argv, void *arg)
120 struct hint *hint = arg;
121 if (mr_trim_args(argc, argv) == MR_NO_MEM)
122 com_err(whoami, MR_NO_MEM, "while trimmming args");
123 return (*hint->proc)(argc, argv, hint->hint);
127 int mr_query(char *name, int argc, char **argv,
128 int (*callproc)(int, char **, void *), void *callarg)
133 hints.proc = callproc;
134 hints.hint = callarg;
136 return mr_process_query(&pseudo_client, name, argc,
137 mr_copy_args(argv, argc), callback,
141 int mr_access(char *name, int argc, char **argv)
144 return mr_check_access(&pseudo_client, name, argc,
145 mr_copy_args(argv, argc));
148 /* trigger_dcm is also used as a followup routine to the
149 * set_server_host_override query, hence the two dummy arguments.
152 struct query pseudo_query = {
157 int trigger_dcm(struct query *q, char *argv[], client *cl)
162 if ((status = check_query_access(&pseudo_query, 0, cl)))
165 sprintf(prog, "%s/startdcm", BIN_DIR);
170 execl(prog, "startdcm", 0);
186 while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
193 if (WTERMSIG(status) != 0 || WEXITSTATUS(status) != 0)
195 com_err(whoami, 0, "%d: child exits with signal %d status %d",
196 pid, WTERMSIG(status), WEXITSTATUS(status));