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];
36 struct authen_data *data;
38 int level = data->NAS_id->priv_lvl;
41 if (level < TAC_PLUS_PRIV_LVL_MIN || level > TAC_PLUS_PRIV_LVL_MAX) {
42 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
43 data->server_msg = tac_strdup("Invalid privilege level in packet");
44 report(LOG_ERR, "%s level=%d %s", session.peer, level, data->server_msg);
47 /* 0 <= level <= 14: look for $enab<n>$ and verify */
48 if (level < TAC_PLUS_PRIV_LVL_MAX) {
51 sprintf(buf, "$enab%d$", level);
52 if (!verify(buf, passwd, data, TAC_PLUS_NORECURSE))
53 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
57 /* 2). level=15. Try $enab15$ or $enable$ (for backwards
58 compatibility) and verify */
60 if (verify("$enable$", passwd, data, TAC_PLUS_NORECURSE) ||
61 verify("$enab15$", passwd, data, TAC_PLUS_NORECURSE)) {
66 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
73 * Tacacs enable authentication function. Wants an enable
74 * password, and tries to verify it.
76 * Choose_authen will ensure that we already have a username before this
79 * We will query for a password and keep it in the method_data.
81 * Any strings returned via pointers in authen_data must come from the
82 * heap. They will get freed by the caller.
84 * Return 0 if data->status is valid, otherwise 1
89 struct authen_data *data;
92 struct private_data *p;
95 p = (struct private_data *) data->method_data;
97 /* An abort has been received. Clean up and return */
98 if (data->flags & TAC_PLUS_CONTINUE_FLAG_ABORT) {
99 if (data->method_data)
100 free(data->method_data);
101 data->method_data = NULL;
104 /* Initialise method_data if first time through */
106 p = (struct private_data *) tac_malloc(sizeof(struct private_data));
107 bzero(p, sizeof(struct private_data));
108 data->method_data = p;
109 p->state = STATE_AUTHEN_START;
112 /* As we're enabling, we don't need a username, but do we have a
115 passwd = p->password;
119 /* No password. Either we need to ask for one and expect to get
120 * called again, or we asked but nothing came back, which is fatal */
123 case STATE_AUTHEN_GETPASS:
124 /* We already asked for a password. This should be the
126 if (data->client_msg) {
127 pwlen = MIN((int)strlen(data->client_msg), MAX_PASSWD_LEN);
131 strncpy(passwd, data->client_msg, pwlen);
132 passwd[pwlen] = '\0';
136 /* Request a password */
137 data->flags = TAC_PLUS_AUTHEN_FLAG_NOECHO;
138 data->server_msg = tac_strdup("Password: ");
139 data->status = TAC_PLUS_AUTHEN_STATUS_GETPASS;
140 p->state = STATE_AUTHEN_GETPASS;
145 /* We have a password. Try validating */
147 /* Assume the worst */
148 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
150 switch (data->service) {
151 case TAC_PLUS_AUTHEN_SVC_ENABLE:
152 enable(passwd, data);
154 char *name = data->NAS_id->username;
156 report(LOG_INFO, "enable 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: authenticate_fn can't set status %d",
183 session.peer, data->status);
184 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;