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.
23 /* internal state variables */
24 #define STATE_AUTHEN_START 0 /* no requests issued */
25 #define STATE_AUTHEN_GETUSER 1 /* username has been requested */
26 #define STATE_AUTHEN_GETPASS 2 /* password has been requested */
29 char password[MAX_PASSWD_LEN + 1];
34 * Default tacacs login authentication function. Wants a username
35 * and a password, and tries to verify them.
37 * Choose_authen will ensure that we already have a username before this
40 * We will query for a password and keep it in the method_data.
42 * Any strings returned via pointers in authen_data must come from the
43 * heap. They will get freed by the caller.
45 * Return 0 if data->status is valid, otherwise 1
50 struct authen_data *data;
53 struct private_data *p;
56 p = (struct private_data *) data->method_data;
58 /* An abort has been received. Clean up and return */
59 if (data->flags & TAC_PLUS_CONTINUE_FLAG_ABORT) {
60 if (data->method_data)
61 free(data->method_data);
62 data->method_data = NULL;
65 /* Initialise method_data if first time through */
67 p = (struct private_data *) tac_malloc(sizeof(struct private_data));
68 bzero(p, sizeof(struct private_data));
69 data->method_data = p;
70 p->state = STATE_AUTHEN_START;
73 /* Unless we're enabling, we need a username */
74 if (data->service != TAC_PLUS_AUTHEN_SVC_ENABLE &&
75 !(char) data->NAS_id->username[0]) {
78 case STATE_AUTHEN_GETUSER:
79 /* we have previously asked for a username but none came back.
80 * This is a gross error */
81 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
82 report(LOG_ERR, "%s: No username supplied after GETUSER",
86 case STATE_AUTHEN_START:
87 /* No username. Try requesting one */
88 data->status = TAC_PLUS_AUTHEN_STATUS_GETUSER;
89 if (data->service == TAC_PLUS_AUTHEN_SVC_LOGIN) {
90 prompt = "\nUser Access Verification\n\nUsername: ";
92 prompt = "Username: ";
94 data->server_msg = tac_strdup(prompt);
95 p->state = STATE_AUTHEN_GETUSER;
99 /* something awful has happened. Give up and die */
100 report(LOG_ERR, "%s: default_fn bad state %d",
101 session.peer, p->state);
106 /* we now have a username if we needed one */
107 name = data->NAS_id->username;
109 /* Do we have a password? */
110 passwd = p->password;
114 /* no password yet. Either we need to ask for one and expect to get
115 * called again, or we asked but nothing came back, which is fatal */
118 case STATE_AUTHEN_GETPASS:
119 /* We already asked for a password. This should be the reply */
120 strncpy(passwd, data->client_msg, MAX_PASSWD_LEN);
121 passwd[MAX_PASSWD_LEN + 1] = '\0';
125 data->flags = TAC_PLUS_AUTHEN_FLAG_NOECHO;
126 data->server_msg = tac_strdup("Password: ");
127 data->status = TAC_PLUS_AUTHEN_STATUS_GETPASS;
128 p->state = STATE_AUTHEN_GETPASS;
133 /* We have a username and password. Try validating */
135 if (STREQ(name, DEFAULT_USERNAME)) {
136 /* Never authenticate this user. It's for authorization only */
137 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
140 "authentication query for '%s' %s from %s rejected",
141 name && name[0] ? name : "unknown",
142 session.port, session.peer);
147 /* Assume the worst */
148 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
150 switch (data->service) {
151 case TAC_PLUS_AUTHEN_SVC_NASI:
152 case TAC_PLUS_AUTHEN_SVC_LOGIN:
153 case TAC_PLUS_AUTHEN_SVC_PPP:
154 verify(name, passwd, data, TAC_PLUS_RECURSE);
156 report(LOG_INFO, "login query for '%s' %s from %s %s",
157 name && name[0] ? name : "unknown",
158 data->NAS_id->NAS_port && data->NAS_id->NAS_port[0] ?
159 data->NAS_id->NAS_port : "unknown",
161 (data->status == TAC_PLUS_AUTHEN_STATUS_PASS) ?
162 "accepted" : "rejected");
166 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
167 report(LOG_ERR, "%s: Bogus service value %d from packet",
168 session.peer, data->service);
172 if (data->method_data)
173 free(data->method_data);
174 data->method_data = NULL;
176 switch (data->status) {
177 case TAC_PLUS_AUTHEN_STATUS_ERROR:
178 case TAC_PLUS_AUTHEN_STATUS_FAIL:
179 case TAC_PLUS_AUTHEN_STATUS_PASS:
182 report(LOG_ERR, "%s: default_v0_fn can't set status %d",
183 session.peer, data->status);
184 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;