2 * $Id: radacct.c,v 1.1 2002/01/22 16:03:04 dfs Exp $
4 * Copyright (C) 1995,1996 Lars Fenneberg
6 * See the file COPYRIGHT for the respective terms and conditions.
7 * If the file is missing contact me at lf@elemental.net
8 * and I'll send you a copy.
13 "$Id: radacct.c,v 1.1 2002/01/22 16:03:04 dfs Exp $";
17 #include <radiusclient.h>
19 #include <pathnames.h>
25 fprintf(stderr,"Usage: %s [-Vh] [-f <config_file>] [-i <client_port>]\n\n", pname);
26 fprintf(stderr," -V output version information\n");
27 fprintf(stderr," -h output this text\n");
28 fprintf(stderr," -f filename of alternate config file\n");
29 fprintf(stderr," -i ttyname to send to the server\n");
35 fprintf(stderr,"%s: %s\n", pname ,rcsid);
40 main (int argc, char **argv)
42 int result = ERROR_RC;
43 VALUE_PAIR *send = NULL;
48 char *username, *service, *fproto, *type;
49 char *path_radiusclient_conf = RC_CONFIG_FILE;
54 pname = (pname = strrchr(argv[0],'/'))?pname+1:argv[0];
58 while ((c = getopt(argc,argv,"f:i:hV")) > 0)
63 path_radiusclient_conf = optarg;
80 if (rc_read_config(path_radiusclient_conf) != 0)
83 if (rc_read_dictionary(rc_conf_str("dictionary")) != 0)
86 if (rc_read_mapfile(rc_conf_str("mapfile")) != 0)
91 client_port = rc_map2id(ttyn);
95 /* we take stdout here, because stdin is usually connected
98 if ((ttyn = ttyname(1)) != NULL)
100 client_port = rc_map2id(ttyn);
108 if ((send = rc_avpair_readin(stdin))) {
110 username = service = type = "(unknown)";
113 if ((vp = rc_avpair_get(send, PW_ACCT_STATUS_TYPE)) != NULL)
114 if ((dval = rc_dict_getval(vp->lvalue, vp->name)) != NULL) {
118 if ((vp = rc_avpair_get(send, PW_USER_NAME)) != NULL)
119 username = vp->strvalue;
121 if ((vp = rc_avpair_get(send, PW_SERVICE_TYPE)) != NULL)
122 if ((dval = rc_dict_getval(vp->lvalue, vp->name)) != NULL) {
123 service = dval->name;
126 if (vp && (vp->lvalue == PW_FRAMED) &&
127 ((vp = rc_avpair_get(send, PW_FRAMED_PROTOCOL)) != NULL))
128 if ((dval = rc_dict_getval(vp->lvalue, vp->name)) != NULL) {
132 result = rc_acct(client_port, send);
135 fprintf(stderr, SC_ACCT_OK);
136 rc_log(LOG_NOTICE, "accounting OK, type %s, username %s, service %s%s%s",
137 type, username, service,(fproto)?"/":"", (fproto)?fproto:"");
141 fprintf(stderr, SC_ACCT_FAILED, result);
142 rc_log(LOG_NOTICE, "accounting FAILED, type %s, username %s, service %s%s%s",
143 type, username, service,(fproto)?"/":"", (fproto)?fproto:"");
145 rc_avpair_free(send);