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 #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];
48 static void enable TAC_ARGS((char *passwd, struct authen_data *data));
53 struct authen_data *data;
55 int level = data->NAS_id->priv_lvl;
58 if (level < TAC_PLUS_PRIV_LVL_MIN || level > TAC_PLUS_PRIV_LVL_MAX) {
59 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
60 data->server_msg = tac_strdup("Invalid privilege level in packet");
61 report(LOG_ERR, "%s level=%d %s", session.peer, level, data->server_msg);
64 /* 0 <= level <= 14: look for $enab<n>$ and verify */
65 if (level < TAC_PLUS_PRIV_LVL_MAX) {
68 sprintf(buf, "$enab%d$", level);
69 if (!verify(buf, passwd, data, TAC_PLUS_NORECURSE))
70 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
74 /* 2). level=15. Try $enab15$ or $enable$ (for backwards
75 compatibility) and verify */
77 if (verify("$enable$", passwd, data, TAC_PLUS_NORECURSE) ||
78 verify("$enab15$", passwd, data, TAC_PLUS_NORECURSE)) {
83 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
90 * Tacacs enable authentication function. Wants an enable
91 * password, and tries to verify it.
93 * Choose_authen will ensure that we already have a username before this
96 * We will query for a password and keep it in the method_data.
98 * Any strings returned via pointers in authen_data must come from the
99 * heap. They will get freed by the caller.
101 * Return 0 if data->status is valid, otherwise 1
104 int enable_fn TAC_ARGS((struct authen_data *data));
108 struct authen_data *data;
111 struct private_data *p;
114 p = (struct private_data *) data->method_data;
116 /* An abort has been received. Clean up and return */
117 if (data->flags & TAC_PLUS_CONTINUE_FLAG_ABORT) {
118 if (data->method_data)
119 free(data->method_data);
120 data->method_data = NULL;
123 /* Initialise method_data if first time through */
125 p = (struct private_data *) tac_malloc(sizeof(struct private_data));
126 bzero(p, sizeof(struct private_data));
127 data->method_data = p;
128 p->state = STATE_AUTHEN_START;
131 /* As we're enabling, we don't need a username, but do we have a
134 passwd = p->password;
138 /* No password. Either we need to ask for one and expect to get
139 * called again, or we asked but nothing came back, which is fatal */
142 case STATE_AUTHEN_GETPASS:
143 /* We already asked for a password. This should be the
145 if (data->client_msg) {
146 pwlen = MIN((int)strlen(data->client_msg), MAX_PASSWD_LEN);
150 strncpy(passwd, data->client_msg, pwlen);
151 passwd[pwlen] = '\0';
155 /* Request a password */
156 data->flags = TAC_PLUS_AUTHEN_FLAG_NOECHO;
157 data->server_msg = tac_strdup("Password: ");
158 data->status = TAC_PLUS_AUTHEN_STATUS_GETPASS;
159 p->state = STATE_AUTHEN_GETPASS;
164 /* We have a password. Try validating */
166 /* Assume the worst */
167 data->status = TAC_PLUS_AUTHEN_STATUS_FAIL;
169 switch (data->service) {
170 case TAC_PLUS_AUTHEN_SVC_ENABLE:
171 enable(passwd, data);
173 char *name = data->NAS_id->username;
175 report(LOG_INFO, "enable query for '%s' %s from %s %s",
176 name && name[0] ? name : "unknown",
177 data->NAS_id->NAS_port && data->NAS_id->NAS_port[0] ?
178 data->NAS_id->NAS_port : "unknown",
180 (data->status == TAC_PLUS_AUTHEN_STATUS_PASS) ?
181 "accepted" : "rejected");
185 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;
186 report(LOG_ERR, "%s: Bogus service value %d from packet",
187 session.peer, data->service);
191 if (data->method_data)
192 free(data->method_data);
193 data->method_data = NULL;
195 switch (data->status) {
196 case TAC_PLUS_AUTHEN_STATUS_ERROR:
197 case TAC_PLUS_AUTHEN_STATUS_FAIL:
198 case TAC_PLUS_AUTHEN_STATUS_PASS:
201 report(LOG_ERR, "%s: authenticate_fn can't set status %d",
202 session.peer, data->status);
203 data->status = TAC_PLUS_AUTHEN_STATUS_ERROR;