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"
23 krb5_context context = NULL;
24 krb5_auth_context auth_con = NULL;
28 /* Authenticate this client with the Moira server. prog is the name of the
29 * client program, and will be recorded in the database.
32 int mr_auth(char *prog)
36 mr_params params, reply;
39 char realm[REALM_SZ], host[BUFSIZ], *p;
44 if ((status = mr_host(host, sizeof(host) - 1)))
47 strcpy(realm, krb_realmofhost(host));
48 for (p = host; *p && *p != '.'; p++)
55 status = krb_mk_req(&auth, MOIRA_SNAME, host, realm, 0);
56 if (status != KSUCCESS)
58 status += ERROR_TABLE_BASE_krb;
61 params.u.mr_procno = MR_AUTH;
63 params.mr_argv = args;
64 params.mr_argl = argl;
65 params.mr_argv[0] = (char *)auth.dat;
66 params.mr_argl[0] = auth.length;
67 params.mr_argv[1] = prog;
68 params.mr_argl[1] = strlen(prog) + 1;
70 if ((status = mr_do_call(¶ms, &reply)) == MR_SUCCESS)
71 status = reply.u.mr_status;
73 mr_destroy_reply(reply);
81 int mr_proxy(char *principal, char *orig_authtype)
84 mr_params params, reply;
89 params.u.mr_procno = MR_PROXY;
91 params.mr_argv = args;
92 params.mr_argv[0] = principal;
93 params.mr_argv[1] = orig_authtype;
94 params.mr_argl = NULL;
96 if ((status = mr_do_call(¶ms, &reply)) == MR_SUCCESS)
97 status = reply.u.mr_status;
99 mr_destroy_reply(reply);
104 int mr_krb5_auth(char *prog)
106 mr_params params, reply;
107 char host[BUFSIZ], *p;
110 krb5_ccache ccache = NULL;
112 krb5_error_code problem = 0;
116 memset(&auth, 0, sizeof(auth));
118 if ((problem = mr_host(host, sizeof(host) - 1)))
123 problem = krb5_init_context(&context);
128 problem = krb5_auth_con_init(context, &auth_con);
132 problem = krb5_cc_default(context, &ccache);
136 problem = krb5_mk_req(context, &auth_con, 0, MOIRA_SNAME, host, NULL,
141 params.u.mr_procno = MR_KRB5_AUTH;
143 params.mr_argv = args;
144 params.mr_argl = argl;
145 params.mr_argv[0] = (char *)auth.data;
146 params.mr_argl[0] = auth.length;
147 params.mr_argv[1] = prog;
148 params.mr_argl[1] = strlen(prog) + 1;
150 if ((problem = mr_do_call(¶ms, &reply)) == MR_SUCCESS)
151 problem = reply.u.mr_status;
153 mr_destroy_reply(reply);
157 krb5_cc_close(context, ccache);
158 krb5_free_data_contents(context, &auth);
160 krb5_auth_con_free(context, auth_con);