]> git.ozlabs.org Git - ppp.git/blob - pppd/plugins/radius/radiusclient/src/radstatus.c
Add these files, used with TDB.
[ppp.git] / pppd / plugins / radius / radiusclient / src / radstatus.c
1 /*
2  * $Id: radstatus.c,v 1.1 2002/01/22 16:03:05 dfs Exp $
3  *
4  * Copyright (C) 1995,1996 Lars Fenneberg
5  *
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.
9  *
10  */
11
12 static char     rcsid[] =
13                 "$Id: radstatus.c,v 1.1 2002/01/22 16:03:05 dfs Exp $";
14
15 #include <config.h>
16 #include <includes.h>
17 #include <radiusclient.h>
18 #include <pathnames.h>
19 #include <messages.h>
20
21 static char *pname;
22
23 void usage(void)
24 {
25         fprintf(stderr,"Usage: %s [-Vh] [-f <config_file>] [server[: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         exit(ERROR_RC);
30 }
31
32 void version(void)
33 {
34         fprintf(stderr,"%s: %s\n", pname ,rcsid);
35         exit(ERROR_RC);
36 }
37
38 int main (int argc, char **argv)
39 {
40         int     result = ERROR_RC;
41         int     c,i;
42         char    *p, msg[4096];
43         SERVER  *srv;
44         char    *path_radiusclient_conf = RC_CONFIG_FILE;
45         
46         extern int optind;
47
48         pname = (pname = strrchr(argv[0],'/'))?pname+1:argv[0];
49
50         rc_openlog(pname);
51
52         while ((c = getopt(argc,argv,"hVf:")) > 0)
53         {
54                 switch(c) {
55                         case 'f':
56                                 path_radiusclient_conf = optarg;
57                                 break;
58                         case 'V':
59                                 version();
60                                 break;
61                         case 'h':
62                                 usage();
63                                 break;
64                         default:
65                                 exit(ERROR_RC);
66                                 break;
67                 }
68         }
69
70         argc -= optind;
71         argv += optind;
72
73         if (rc_read_config(path_radiusclient_conf) != 0)
74                 exit(ERROR_RC);
75         
76         if (rc_read_dictionary(rc_conf_str("dictionary")) != 0)
77                 exit (ERROR_RC);
78
79         if (argc > 0) {
80                 for (i = 0; i < argc; i++) {
81                         if ((p = strchr(argv[i], ':')) == NULL) {
82                                 result = rc_check(argv[i],rc_getport(AUTH), msg);
83                         } else if (!strcmp(p+1, "auth")) {
84                                 *p = '\0';
85                                 result = rc_check(argv[i],rc_getport(AUTH), msg);
86                         } else if (!strcmp(p+1, "acct")) {
87                                 *p = '\0';
88                                 result = rc_check(argv[i],rc_getport(ACCT), msg);
89                         } else {
90                                 *p = '\0';
91                                 result = rc_check(argv[i], atoi(p+1), msg);
92                         }
93                         if (result == OK_RC)
94                                 fputs(msg, stdout);
95                         else
96                                 printf(SC_STATUS_FAILED);
97                 }
98         } else {
99                 srv = rc_conf_srv("authserver");
100                 for(i=0; i<srv->max ; i++)
101                 {
102                         result = rc_check(srv->name[i], srv->port[i], msg);
103                         fputs(msg, stdout);
104                 }
105                 
106                 srv = rc_conf_srv("acctserver");
107                 for(i=0; i<srv->max ; i++)
108                 {
109                         result = rc_check(srv->name[i], srv->port[i], msg);
110                         fputs(msg, stdout);
111                 }
112         }
113         return 0;
114 }