2 * $Id: radexample.c,v 1.2 2002/04/02 14:09:35 dfs Exp $
4 * Copyright (C) 1995,1996,1997 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.
14 "$Id: radexample.c,v 1.2 2002/04/02 14:09:35 dfs Exp $";
18 #include <radiusclient.h>
19 #include <pathnames.h>
21 static char *pname = NULL;
24 main (int argc, char **argv)
28 char passwd[AUTH_PASS_LEN + 1];
29 VALUE_PAIR *send, *received;
31 char msg[4096], username_realm[256];
32 char *default_realm = rc_conf_str("default_realm");
34 char value[2048]; /* more than enough */
37 pname = (pname = strrchr(argv[0],'/'))?pname+1:argv[0];
45 cfile = RC_CONFIG_FILE;
47 if (rc_read_config(cfile) != 0)
50 if (rc_read_dictionary(rc_conf_str("dictionary")) != 0)
53 strncpy(username, rc_getstr ("login: ",1), sizeof(username));
54 strncpy (passwd, rc_getstr("Password: ",0), sizeof (passwd));
62 strncpy(username_realm, username, sizeof(username_realm));
64 /* Append default realm */
65 if ((strchr(username_realm, '@') == NULL) && default_realm &&
66 (*default_realm != '\0'))
68 strncat(username_realm, "@", sizeof(username_realm));
69 strncat(username_realm, default_realm, sizeof(username_realm));
72 if (rc_avpair_add(&send, PW_USER_NAME, username_realm, 0, VENDOR_NONE) == NULL)
76 * Fill in User-Password
79 if (rc_avpair_add(&send, PW_USER_PASSWORD, passwd, 0, VENDOR_NONE) == NULL)
83 * Fill in Service-Type
86 service = PW_AUTHENTICATE_ONLY;
87 if (rc_avpair_add(&send, PW_SERVICE_TYPE, &service, 0, VENDOR_NONE) == NULL)
90 result = rc_auth(0, send, &received, msg, NULL);
94 fprintf(stderr, "\"%s\" RADIUS Authentication OK\n", username);
98 fprintf(stderr, "\"%s\" RADIUS Authentication failure (RC=%i)\n", username, result);
101 /* Print returned attributes */
102 for( ; received ; received = received->next) {
103 if (rc_avpair_tostr(received, name, sizeof(name), value,
104 sizeof(value)) < 0) {
107 printf("Attr '%s' ==> Val '%s'\n",