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.
26 #include "default_v0_fn.h"
31 #include "choose_authen.h" /* for "struct authen_data" */
32 #include "do_author.h" /* for "struct identity" */
38 /* internal state variables */
39 #define STATE_AUTHEN_START 0 /* no requests issued */
40 #define STATE_AUTHEN_GETUSER 1 /* username has been requested */
41 #define STATE_AUTHEN_GETPASS 2 /* password has been requested */
44 char password[MAX_PASSWD_LEN + 1];
49 * Default tacacs login authentication function. Wants a username
50 * and a password, and tries to verify them.
52 * Choose_authen will ensure that we already have a username before this
55 * We will query for a password and keep it in the method_data.
57 * Any strings returned via pointers in authen_data must come from the
58 * heap. They will get freed by the caller.
60 * Return 0 if data->status is valid, otherwise 1
63 int default_v0_fn TAC_ARGS((struct authen_data *data));
67 struct authen_data *data;
70 struct private_data *p;
73 p = (struct private_data *) data->method_data;
75 /* An abort has been received. Clean up and return */
76 if (data->flags & TAC_PLUS_CONTINUE_FLAG_ABORT) {
77 if (data->method_data)
78 free(data->method_data);
79 data->method_data = NULL;
82 /* Initialise method_data if first time through */
84 p = (struct private_data *) tac_malloc(sizeof(struct private_data));
85 bzero(p, sizeof(struct private_data));
86 data->method_data = p;
87 p->state = STATE_AUTHEN_START;
90 /* Unless we're enabling, we need a username */
91 if (data->service != TAC_PLUS_AUTHEN_SVC_ENABLE &&
92 !(char) data->NAS_id->username[0]) {
95 case STATE_AUTHEN_GETUSER:
96 /* we have previously asked for a username but none came back.
97 * This is a gross error */
98 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
99 report(LOG_ERR, "%s: No username supplied after GETUSER",
103 case STATE_AUTHEN_START:
104 /* No username. Try requesting one */
105 data->status = TAC_PLUS_AUTHEN_STATUS_GETUSER;
106 if (data->service == TAC_PLUS_AUTHEN_SVC_LOGIN) {
107 prompt = "\nUser Access Verification\n\nUsername: ";
109 prompt = "Username: ";
111 data->server_msg = tac_strdup(prompt);
112 p->state = STATE_AUTHEN_GETUSER;
116 /* something awful has happened. Give up and die */
117 report(LOG_ERR, "%s: default_fn bad state %d",
118 session.peer, p->state);
123 /* we now have a username if we needed one */
124 name = data->NAS_id->username;
126 /* Do we have a password? */
127 passwd = p->password;
131 /* no password yet. Either we need to ask for one and expect to get
132 * called again, or we asked but nothing came back, which is fatal */
135 case STATE_AUTHEN_GETPASS:
136 /* We already asked for a password. This should be the reply */
137 strncpy(passwd, data->client_msg, MAX_PASSWD_LEN);
138 passwd[MAX_PASSWD_LEN + 1] = '\0';
142 data->flags = TAC_PLUS_AUTHEN_FLAG_NOECHO;
143 data->server_msg = tac_strdup("Password: ");
144 data->status = TAC_PLUS_AUTHEN_STATUS_GETPASS;
145 p->state = STATE_AUTHEN_GETPASS;
150 /* We have a username and password. Try validating */
152 if (STREQ(name, DEFAULT_USERNAME)) {
153 /* Never authenticate this user. It's for authorization only */
154 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
157 "authentication query for '%s' %s from %s rejected",
158 name && name[0] ? name : "unknown",
159 session.port, session.peer);
164 /* Assume the worst */
165 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
167 switch (data->service) {
168 case TAC_PLUS_AUTHEN_SVC_NASI:
169 case TAC_PLUS_AUTHEN_SVC_LOGIN:
170 case TAC_PLUS_AUTHEN_SVC_PPP:
171 verify(name, passwd, data, TAC_PLUS_RECURSE);
173 report(LOG_INFO, "login query for '%s' %s from %s %s",
174 name && name[0] ? name : "unknown",
175 data->NAS_id->NAS_port && data->NAS_id->NAS_port[0] ?
176 data->NAS_id->NAS_port : "unknown",
178 (data->status == TAC_PLUS_AUTHEN_STATUS_PASS) ?
179 "accepted" : "rejected");
183 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
184 report(LOG_ERR, "%s: Bogus service value %d from packet",
185 session.peer, data->service);
189 if (data->method_data)
190 free(data->method_data);
191 data->method_data = NULL;
193 switch (data->status) {
194 case TAC_PLUS_AUTHEN_STATUS_ERROR:
195 case TAC_PLUS_AUTHEN_STATUS_FAIL:
196 case TAC_PLUS_AUTHEN_STATUS_PASS:
199 report(LOG_ERR, "%s: default_v0_fn can't set status %d",
200 session.peer, data->status);
201 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;