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.
24 #include <netinet/in.h> /* for ntohl() */
32 #include "do_author.h" /* for "struct identity" */
43 static void account TAC_ARGS((u_char *pak));
47 * Come here when we receive an Start Accounting packet
50 void accounting TAC_ARGS((u_char *pak));
56 struct acct *acct_pak;
62 if (debug & DEBUG_ACCT_FLAG)
63 report(LOG_DEBUG, "Start accounting request");
66 acct_pak = (struct acct *) (pak + TAC_PLUS_HDR_SIZE);
68 /* Do some sanity checking on the packet */
70 /* arg counts start here */
71 p = pak + TAC_PLUS_HDR_SIZE + TAC_ACCT_REQ_FIXED_FIELDS_SIZE;
74 len = TAC_ACCT_REQ_FIXED_FIELDS_SIZE;
75 len += acct_pak->user_len + acct_pak->port_len +
76 acct_pak->rem_addr_len + acct_pak->arg_cnt;
77 for (i = 0; i < (int)acct_pak->arg_cnt; i++) {
81 if (len != (unsigned long) ntohl(hdr->datalength)) {
82 send_error_reply(TAC_PLUS_ACCT, NULL);
91 static void account TAC_ARGS((u_char *pak));
97 struct acct *acct_pak;
100 struct identity identity;
102 int i, errors, status;
104 acct_pak = (struct acct *) (pak + TAC_PLUS_HDR_SIZE);
106 /* Fill out accounting record structure */
107 bzero(&rec, sizeof(struct acct_rec));
109 if (acct_pak->flags & TAC_PLUS_ACCT_FLAG_WATCHDOG)
110 rec.acct_type = ACCT_TYPE_UPDATE;
111 if (acct_pak->flags & TAC_PLUS_ACCT_FLAG_START)
112 rec.acct_type = ACCT_TYPE_START;
113 if (acct_pak->flags & TAC_PLUS_ACCT_FLAG_STOP)
114 rec.acct_type = ACCT_TYPE_STOP;
116 rec.authen_method = acct_pak->authen_method;
117 rec.authen_type = acct_pak->authen_type;
118 rec.authen_service = acct_pak->authen_service;
120 /* start of variable length data is here */
121 p = pak + TAC_PLUS_HDR_SIZE + TAC_ACCT_REQ_FIXED_FIELDS_SIZE;
124 p += acct_pak->arg_cnt;
126 /* zero out identity struct */
127 bzero(&identity, sizeof(struct identity));
129 identity.username = tac_make_string(p, (int)acct_pak->user_len);
130 p += acct_pak->user_len;
132 identity.NAS_name = tac_strdup(session.peer);
134 identity.NAS_port = tac_make_string(p, (int)acct_pak->port_len);
135 p += acct_pak->port_len;
136 if (acct_pak->port_len <= 0) {
137 strcpy(session.port, "unknown-port");
139 strcpy(session.port, identity.NAS_port);
142 identity.NAC_address = tac_make_string(p, (int)acct_pak->rem_addr_len);
143 p += acct_pak->rem_addr_len;
145 identity.priv_lvl = acct_pak->priv_lvl;
147 cfg_request_identity(&identity);
149 rec.identity = &identity;
151 /* Now process cmd args */
152 argsizep = pak + TAC_PLUS_HDR_SIZE + TAC_ACCT_REQ_FIXED_FIELDS_SIZE;
154 cmd_argp = (char **) tac_malloc(acct_pak->arg_cnt * sizeof(char *));
156 for (i = 0; i < (int)acct_pak->arg_cnt; i++) {
157 cmd_argp[i] = tac_make_string(p, *argsizep);
162 rec.num_args = acct_pak->arg_cnt;
166 * Tally for MAXSESS counting
175 errors = do_wtmp(&rec);
177 errors = do_acct(&rec);
179 if (session.db_acct && rec.acct_type==ACCT_TYPE_STOP )
185 status = TAC_PLUS_ACCT_STATUS_ERROR;
187 status = TAC_PLUS_ACCT_STATUS_SUCCESS;
189 send_acct_reply(status, rec.msg, rec.admin_msg);
191 free(identity.username);
192 free(identity.NAS_name);
193 free(identity.NAS_port);
194 free(identity.NAC_address);
196 for (i = 0; i < (int)acct_pak->arg_cnt; i++) {