2 Copyright (c) 1995-1998 by Cisco systems, Inc.
4 Permission to use, copy, modify, and distribute this software for
5 any purpose and without fee is hereby granted, provided that this
6 copyright and permission notice appear on all copies of the
7 software and supporting documentation, the name of Cisco Systems,
8 Inc. not be used in advertising or publicity pertaining to
9 distribution of the program without specific prior permission, and
10 notice be given in supporting documentation that modification,
11 copying and distribution is by permission of Cisco Systems, Inc.
13 Cisco Systems, Inc. makes no representations about the suitability
14 of this software for any purpose. THIS SOFTWARE IS PROVIDED ``AS
15 IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
16 WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS FOR A PARTICULAR PURPOSE.
31 /* internal state variables */
32 #define STATE_AUTHEN_START 0 /* no requests issued */
33 #define STATE_AUTHEN_GETUSER 1 /* username has been requested */
34 #define STATE_AUTHEN_GETPASS 2 /* password has been requested */
38 char password[MAX_PASSWD_LEN + 1];
42 /* Use s/key to verify a supplied password using state set up earlier
43 when the username was supplied */
45 static int skey_verify TAC_ARGS((char *passwd, struct authen_data *data));
48 skey_verify(passwd, data)
50 struct authen_data *data;
52 struct private_data *p = data->method_data;
53 struct skey *skeyp = &p->skey;
55 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
57 if (skeyverify(skeyp, passwd) == 0) {
58 /* S/Key authentication succeeded */
59 data->status = TAC_PLUS_AUTHEN_STATUS_PASS;
61 data->server_msg = tac_strdup("Password will expire soon");
69 * Skey tacacs login authentication function. Wants a username
70 * and a password, and tries to verify them via skey.
72 * Choose_authen will ensure that we already have a username before this
75 * We will query for a password and keep it in the method_data.
77 * Any strings returned via pointers in authen_data must come from the
78 * heap. They will get freed by the caller.
80 * Return 0 if data->status is valid, otherwise 1
83 int skey_fn TAC_ARGS((struct authen_data *data));
87 struct authen_data *data;
90 struct private_data *p;
94 p = (struct private_data *) data->method_data;
96 /* An abort has been received. Clean up and return */
97 if (data->flags & TAC_PLUS_CONTINUE_FLAG_ABORT) {
98 if (data->method_data)
99 free(data->method_data);
100 data->method_data = NULL;
103 /* Initialise method_data if first time through */
105 p = (struct private_data *) tac_malloc(sizeof(struct private_data));
106 bzero(p, sizeof(struct private_data));
107 data->method_data = p;
108 p->state = STATE_AUTHEN_START;
111 /* Unless we're enabling, we need a username */
112 if (data->service != TAC_PLUS_AUTHEN_SVC_ENABLE &&
113 !(char) data->NAS_id->username[0]) {
116 case STATE_AUTHEN_GETUSER:
117 /* we have previously asked for a username but none came back.
118 * This is a gross error */
119 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
120 report(LOG_ERR, "%s: No username supplied after GETUSER",
124 case STATE_AUTHEN_START:
125 /* No username. Try requesting one */
126 data->status = TAC_PLUS_AUTHEN_STATUS_GETUSER;
127 if (data->service == TAC_PLUS_AUTHEN_SVC_LOGIN) {
128 prompt = "\nUser Access Verification\n\nUsername: ";
130 prompt = "Username: ";
132 data->server_msg = tac_strdup(prompt);
133 p->state = STATE_AUTHEN_GETUSER;
137 /* something awful has happened. Give up and die */
138 report(LOG_ERR, "%s: skey_fn bad state %d",
139 session.peer, p->state);
144 /* we now have a username if we needed one */
145 name = data->NAS_id->username;
147 /* Do we have a password? */
148 passwd = p->password;
153 /* no password yet. Either we need to ask for one and expect to get
154 * called again, or we asked but nothing came back, which is fatal */
157 case STATE_AUTHEN_GETPASS:
158 /* We already asked for a password. This should be the reply */
159 if (data->client_msg) {
160 pwlen = MIN(strlen(data->client_msg), MAX_PASSWD_LEN);
164 strncpy(passwd, data->client_msg, pwlen);
165 passwd[pwlen] = '\0';
169 /* Request a password */
170 passwd = cfg_get_login_secret(name, TAC_PLUS_RECURSE);
171 if (!passwd && !STREQ(passwd, "skey")) {
172 report(LOG_ERR, "Cannot find skey password declaration for %s",
174 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
178 if (skeychallenge(&p->skey, name, skeyprompt) == 0) {
180 sprintf(buf, "%s\nPassword: ", skeyprompt);
181 data->server_msg = tac_strdup(buf);
182 data->status = TAC_PLUS_AUTHEN_STATUS_GETPASS;
183 p->state = STATE_AUTHEN_GETPASS;
187 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
188 report(LOG_ERR, "Cannot generate skey prompt for %s", name);
193 /* We have a username and password. Try validating */
195 /* Assume the worst */
196 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
198 switch (data->service) {
199 case TAC_PLUS_AUTHEN_SVC_LOGIN:
200 skey_verify(passwd, data);
202 report(LOG_INFO, "login query for '%s' %s from %s %s",
203 name && name[0] ? name : "unknown",
204 data->NAS_id->NAS_port && data->NAS_id->NAS_port[0] ?
205 data->NAS_id->NAS_port : "unknown",
207 (data->status == TAC_PLUS_AUTHEN_STATUS_PASS) ?
208 "accepted" : "rejected");
212 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
213 report(LOG_ERR, "%s: Bogus service value %d from packet",
214 session.peer, data->service);
218 if (data->method_data)
219 free(data->method_data);
220 data->method_data = NULL;
222 switch (data->status) {
223 case TAC_PLUS_AUTHEN_STATUS_ERROR:
224 case TAC_PLUS_AUTHEN_STATUS_FAIL:
225 case TAC_PLUS_AUTHEN_STATUS_PASS:
228 report(LOG_ERR, "%s: skey_fn couldn't set recognizable status %d",
229 session.peer, data->status);
230 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;