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