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 "sms_server.h"
24 extern char *malloc();
26 char *kname_unparse();
29 * Handle a SMS_AUTH RPC request.
31 * argv[0] is a kerberos authenticator. Decompose it, and if
32 * successful, store the name the user authenticated to in
43 char buf[REALM_SZ+INST_SZ+ANAME_SZ], hostbuf[BUFSIZ], *host, *p;
46 auth.length = cl->args->sms_argl[0];
47 bcopy(cl->args->sms_argv[0], (char *)auth.dat, auth.length);
49 if (gethostname(hostbuf, sizeof(hostbuf)) < 0)
50 com_err(whoami, errno, "Unable to get local hostname");
51 host = canonicalize_hostname(strsave(hostbuf));
52 for (p = host; *p && *p != '.'; p++)
57 if ((status = krb_rd_req (&auth, MOIRA_SNAME, host, cl->haddr.sin_addr,
59 /* for backwards compatability with old clients */
60 (status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
62 status += ERROR_TABLE_BASE_krb;
63 cl->reply.sms_status = status;
64 if (log_flags & LOG_RES)
65 com_err(whoami, status, "(authentication failed)");
70 bcopy(ad.pname, cl->kname.name, ANAME_SZ);
71 bcopy(ad.pinst, cl->kname.inst, INST_SZ);
72 bcopy(ad.prealm, cl->kname.realm, REALM_SZ);
73 strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm));
75 if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm))
79 /* this is in a separate function because it accesses the database */
80 set_krb_mapping(cl->clname, ad.pname, ok,
81 &cl->client_id, &cl->users_id);
83 if (cl->args->sms_version_no == SMS_VERSION_2) {
84 bcopy(cl->args->sms_argv[1], cl->entity, 8);
87 strcpy(cl->entity, "???");
89 bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */
91 if (log_flags & LOG_RES)
92 com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d",
93 cl->clname, cl->entity, cl->users_id, cl->client_id);
94 if (cl->users_id == 0)
95 cl->reply.sms_status = SMS_USER_AUTH;
99 /* Turn a principal, instance, realm triple into a single non-ambiguous
100 * string. This is the inverse of kname_parse(). It returns a pointer
101 * to a static buffer, or NULL on error.
104 char *kname_unparse(p, i, r)
109 static char name[MAX_K_NAME_SZ];
113 if (!p || strlen(p) > ANAME_SZ)
135 if (strlen(i) > INST_SZ)
159 if (!r || strlen(r) > REALM_SZ)