3 * Handles the client side of the sending of authenticators to the moira server
5 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
12 #include "mr_private.h"
21 krb5_context context = NULL;
22 krb5_auth_context auth_con = NULL;
26 /* Authenticate this client with the Moira server. prog is the name of the
27 * client program, and will be recorded in the database.
30 int mr_auth(char *prog)
33 mr_params params, reply;
36 char realm[REALM_SZ], host[BUFSIZ], *p;
41 if ((status = mr_host(host, sizeof(host) - 1)))
44 strcpy(realm, krb_realmofhost(host));
45 for (p = host; *p && *p != '.'; p++)
52 status = krb_mk_req(&auth, MOIRA_SNAME, host, realm, 0);
53 if (status != KSUCCESS)
55 status += ERROR_TABLE_BASE_krb;
58 params.u.mr_procno = MR_AUTH;
60 params.mr_argv = args;
61 params.mr_argl = argl;
62 params.mr_argv[0] = (char *)auth.dat;
63 params.mr_argl[0] = auth.length;
64 params.mr_argv[1] = prog;
65 params.mr_argl[1] = strlen(prog) + 1;
67 if ((status = mr_do_call(¶ms, &reply)) == MR_SUCCESS)
68 status = reply.u.mr_status;
70 mr_destroy_reply(reply);
75 int mr_proxy(char *principal, char *orig_authtype)
78 mr_params params, reply;
81 params.u.mr_procno = MR_PROXY;
83 params.mr_argv = args;
84 params.mr_argv[0] = principal;
85 params.mr_argv[1] = orig_authtype;
86 params.mr_argl = NULL;
88 if ((status = mr_do_call(¶ms, &reply)) == MR_SUCCESS)
89 status = reply.u.mr_status;
91 mr_destroy_reply(reply);
96 int mr_krb5_auth(char *prog)
98 mr_params params, reply;
99 char host[BUFSIZ], *p;
102 krb5_ccache ccache = NULL;
104 krb5_error_code problem = 0;
108 memset(&auth, 0, sizeof(auth));
110 if ((problem = mr_host(host, sizeof(host) - 1)))
113 for (p = host; *p && *p != '.'; p++)
122 problem = krb5_init_context(&context);
127 problem = krb5_auth_con_init(context, &auth_con);
131 problem = krb5_cc_default(context, &ccache);
135 problem = krb5_mk_req(context, &auth_con, NULL, MOIRA_SNAME, host, NULL,
140 params.u.mr_procno = MR_KRB5_AUTH;
142 params.mr_argv = args;
143 params.mr_argl = argl;
144 params.mr_argv[0] = (char *)auth.data;
145 params.mr_argl[0] = auth.length;
146 params.mr_argv[1] = prog;
147 params.mr_argl[1] = strlen(prog) + 1;
149 if ((problem = mr_do_call(¶ms, &reply)) == MR_SUCCESS)
150 problem = reply.u.mr_status;
152 mr_destroy_reply(reply);
156 krb5_cc_close(context, ccache);
157 krb5_free_data_contents(context, &auth);
159 krb5_auth_con_free(context, auth_con);