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"
25 char *kname_unparse();
28 * Handle a MOIRA_AUTH RPC request.
30 * argv[0] is a kerberos authenticator. Decompose it, and if
31 * successful, store the name the user authenticated to in
42 char buf[REALM_SZ+INST_SZ+ANAME_SZ], hostbuf[BUFSIZ], *host, *p;
45 auth.length = cl->args->mr_argl[0];
46 bcopy(cl->args->mr_argv[0], (char *)auth.dat, auth.length);
48 if (gethostname(hostbuf, sizeof(hostbuf)) < 0)
49 com_err(whoami, errno, "Unable to get local hostname");
50 host = canonicalize_hostname(strsave(hostbuf));
51 for (p = host; *p && *p != '.'; p++)
56 if ((status = krb_rd_req (&auth, MOIRA_SNAME, host, cl->haddr.sin_addr,
58 /* for backwards compatability with old clients */
59 (status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
61 status += ERROR_TABLE_BASE_krb;
62 cl->reply.mr_status = status;
63 if (log_flags & LOG_RES)
64 com_err(whoami, status, "(authentication failed)");
69 bcopy(ad.pname, cl->kname.name, ANAME_SZ);
70 bcopy(ad.pinst, cl->kname.inst, INST_SZ);
71 bcopy(ad.prealm, cl->kname.realm, REALM_SZ);
72 strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm));
74 if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm))
78 /* this is in a separate function because it accesses the database */
79 status = set_krb_mapping(cl->clname, ad.pname, ok,
80 &cl->client_id, &cl->users_id);
82 if (cl->args->mr_version_no == MR_VERSION_2) {
83 strncpy(cl->entity, cl->args->mr_argv[1], 8);
86 strcpy(cl->entity, "???");
88 bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */
90 if (log_flags & LOG_RES)
91 com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d",
92 cl->clname, cl->entity, cl->users_id, cl->client_id);
93 if (status != MR_SUCCESS)
94 cl->reply.mr_status = status;
95 else if (cl->users_id == 0)
96 cl->reply.mr_status = MR_USER_AUTH;
100 /* Turn a principal, instance, realm triple into a single non-ambiguous
101 * string. This is the inverse of kname_parse(). It returns a pointer
102 * to a static buffer, or NULL on error.
105 char *kname_unparse(p, i, r)
110 static char name[MAX_K_NAME_SZ];
114 if (!p || strlen(p) > ANAME_SZ)
136 if (strlen(i) > INST_SZ)
160 if (!r || strlen(r) > REALM_SZ)