]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * | |
8 | */ | |
9 | ||
10 | #ifndef lint | |
11 | static char *rcsid_sms_sauth_c = "$Header$"; | |
12 | #endif lint | |
13 | ||
14 | extern int krb_err_base; | |
15 | #include <strings.h> | |
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; | |
39 | static char *unknown = "???"; | |
40 | ||
41 | if (cl->clname) { | |
42 | free(cl->clname); | |
43 | cl->clname = 0; | |
44 | cl->users_id = 0; | |
45 | bzero(&cl->kname, sizeof(cl->kname)); | |
46 | } | |
47 | if (cl->entity && cl->entity != unknown) { | |
48 | free(cl->entity); | |
49 | cl->entity = 0; | |
50 | } | |
51 | ||
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 | ||
56 | if ((status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr, | |
57 | &ad, "")) != KSUCCESS) { | |
58 | status += krb_err_base; | |
59 | cl->reply.sms_status = status; | |
60 | if (log_flags & LOG_RES) | |
61 | com_err(whoami, status, "(authentication failed)"); | |
62 | return; | |
63 | } | |
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 | ||
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); | |
79 | bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */ | |
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; | |
90 | } | |
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); | |
95 | if (cl->users_id == 0) | |
96 | cl->reply.sms_status = SMS_USER_AUTH; | |
97 | } |