6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
13 static char *rcsid_sms_sauth_c = "$Header$";
16 #include <mit-copyright.h>
18 #include "mr_server.h"
27 char *kname_unparse(char *, char *, char *);
30 * Handle a MOIRA_AUTH RPC request.
32 * argv[0] is a kerberos authenticator. Decompose it, and if
33 * successful, store the name the user authenticated to in
44 char hostbuf[BUFSIZ], *host, *p;
47 auth.length = cl->args->mr_argl[0];
48 memcpy((char *)auth.dat, cl->args->mr_argv[0], auth.length);
50 if (gethostname(hostbuf, sizeof(hostbuf)) < 0)
51 com_err(whoami, errno, "Unable to get local hostname");
52 host = canonicalize_hostname(strsave(hostbuf));
53 for (p = host; *p && *p != '.'; p++)
58 if ((status = krb_rd_req (&auth, MOIRA_SNAME, host,
59 cl->haddr.sin_addr.s_addr, &ad, "")) != 0) {
60 status += ERROR_TABLE_BASE_krb;
61 cl->reply.mr_status = status;
62 if (log_flags & LOG_RES)
63 com_err(whoami, status, "(authentication failed)");
68 memcpy(cl->kname.name, ad.pname, ANAME_SZ);
69 memcpy(cl->kname.inst, ad.pinst, INST_SZ);
70 memcpy(cl->kname.realm, ad.prealm, REALM_SZ);
71 strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm));
73 if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm))
77 /* this is in a separate function because it accesses the database */
78 status = set_krb_mapping(cl->clname, ad.pname, ok,
79 &cl->client_id, &cl->users_id);
81 if (cl->args->mr_version_no == MR_VERSION_2) {
82 strncpy(cl->entity, cl->args->mr_argv[1], 8);
85 strcpy(cl->entity, "???");
87 memset(&ad, 0, sizeof(ad)); /* Clean up session key, etc. */
89 if (log_flags & LOG_RES)
90 com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d",
91 cl->clname, cl->entity, cl->users_id, cl->client_id);
92 if (status != MR_SUCCESS)
93 cl->reply.mr_status = status;
94 else if (cl->users_id == 0)
95 cl->reply.mr_status = MR_USER_AUTH;