]>
Commit | Line | Data |
---|---|---|
a3cf6921 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
c801de4c | 7 | * For copying and distribution information, please see the file |
8 | * <mit-copyright.h>. | |
a3cf6921 | 9 | * |
a3cf6921 | 10 | */ |
11 | ||
12 | #ifndef lint | |
13 | static char *rcsid_sms_sauth_c = "$Header$"; | |
14 | #endif lint | |
15 | ||
c801de4c | 16 | #include <mit-copyright.h> |
a3cf6921 | 17 | #include <strings.h> |
a3cf6921 | 18 | #include "sms_server.h" |
40165bd0 | 19 | #include <krb_et.h> |
a3cf6921 | 20 | |
21 | extern char buf1[]; | |
22 | extern char *whoami; | |
23 | extern char *malloc(); | |
24 | ||
25 | /* | |
26 | * Handle a SMS_AUTH RPC request. | |
27 | * | |
28 | * argv[0] is a kerberos authenticator. Decompose it, and if | |
29 | * successful, store the name the user authenticated to in | |
30 | * cl->cl_name. | |
31 | */ | |
32 | ||
33 | void | |
34 | do_auth(cl) | |
35 | client *cl; | |
36 | { | |
37 | KTEXT_ST auth; | |
38 | AUTH_DAT ad; | |
39 | int status; | |
40 | char buf[REALM_SZ+INST_SZ+ANAME_SZ]; | |
90021a6f | 41 | static char *unknown = "???"; |
a3cf6921 | 42 | |
23e476e8 | 43 | if (cl->clname) { |
44 | free(cl->clname); | |
45 | cl->clname = 0; | |
90021a6f | 46 | cl->users_id = 0; |
23e476e8 | 47 | bzero(&cl->kname, sizeof(cl->kname)); |
48 | } | |
90021a6f | 49 | if (cl->entity && cl->entity != unknown) { |
50 | free(cl->entity); | |
51 | cl->entity = 0; | |
52 | } | |
23e476e8 | 53 | |
a3cf6921 | 54 | auth.length = cl->args->sms_argl[0]; |
55 | bcopy(cl->args->sms_argv[0], (char *)auth.dat, auth.length); | |
56 | auth.mbz = 0; | |
57 | ||
90021a6f | 58 | if ((status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr, |
40165bd0 | 59 | &ad, "")) != 0) { |
60 | status += ERROR_TABLE_BASE_krb; | |
a3cf6921 | 61 | cl->reply.sms_status = status; |
060e9c63 | 62 | if (log_flags & LOG_RES) |
63 | com_err(whoami, status, "(authentication failed)"); | |
a3cf6921 | 64 | return; |
65 | } | |
8a36ddfe | 66 | bcopy(ad.pname, cl->kname.name, ANAME_SZ); |
67 | bcopy(ad.pinst, cl->kname.inst, INST_SZ); | |
68 | bcopy(ad.prealm, cl->kname.realm, REALM_SZ); | |
69 | ||
a3cf6921 | 70 | (void) strcpy(buf, ad.pname); |
71 | if(ad.pinst[0]) { | |
72 | (void) strcat(buf, "."); | |
73 | (void) strcat(buf, ad.pinst); | |
74 | } | |
75 | (void) strcat(buf, "@"); | |
76 | (void) strcat(buf, ad.prealm); | |
77 | if (cl->clname) free((char *)cl->clname); | |
78 | ||
79 | cl->clname = (char *)malloc((unsigned)(strlen(buf)+1)); | |
80 | (void) strcpy(cl->clname, buf); | |
23e476e8 | 81 | bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */ |
90021a6f | 82 | |
83 | cl->users_id = get_users_id(cl->kname.name); | |
84 | ||
85 | if (cl->args->sms_version_no == SMS_VERSION_2) { | |
86 | unsigned len = strlen(cl->args->sms_argv[1]) + 1; | |
87 | ||
88 | cl->entity = (char *)malloc(len); | |
89 | bcopy(cl->args->sms_argv[1], cl->entity, len+1); | |
90 | } else { | |
91 | cl->entity = unknown; | |
060e9c63 | 92 | } |
90021a6f | 93 | |
94 | if (log_flags & LOG_RES) | |
95 | com_err(whoami, 0, "Authenticated to %s using %s, id %d", | |
96 | cl->clname, cl->entity, cl->users_id); | |
054523f7 | 97 | if (cl->users_id == 0) |
98 | cl->reply.sms_status = SMS_USER_AUTH; | |
a3cf6921 | 99 | } |