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"
23 extern char *malloc();
25 char *kname_unparse();
28 * Handle a SMS_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];
44 auth.length = cl->args->sms_argl[0];
45 bcopy(cl->args->sms_argv[0], (char *)auth.dat, auth.length);
48 if ((status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
50 status += ERROR_TABLE_BASE_krb;
51 cl->reply.sms_status = status;
52 if (log_flags & LOG_RES)
53 com_err(whoami, status, "(authentication failed)");
57 bcopy(ad.pname, cl->kname.name, ANAME_SZ);
58 bcopy(ad.pinst, cl->kname.inst, INST_SZ);
59 bcopy(ad.prealm, cl->kname.realm, REALM_SZ);
60 strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm));
62 if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm))
66 /* this is in a separate function because it accesses the database */
67 set_krb_mapping(cl->clname, ad.pname, ok,
68 &cl->client_id, &cl->users_id);
70 if (cl->args->sms_version_no == SMS_VERSION_2) {
71 bcopy(cl->args->sms_argv[1], cl->entity, 8);
74 strcpy(cl->entity, "???");
76 bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */
78 if (log_flags & LOG_RES)
79 com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d",
80 cl->clname, cl->entity, cl->users_id, cl->client_id);
81 if (cl->users_id == 0)
82 cl->reply.sms_status = SMS_USER_AUTH;
86 /* Turn a principal, instance, realm triple into a single non-ambiguous
87 * string. This is the inverse of kname_parse(). It returns a pointer
88 * to a static buffer, or NULL on error.
91 char *kname_unparse(p, i, r)
96 static char name[MAX_K_NAME_SZ];
100 if (!p || strlen(p) > ANAME_SZ)
122 if (strlen(i) > INST_SZ)
146 if (!r || strlen(r) > REALM_SZ)