added more error messages to valuepair.c
authoraland <aland>
Mon, 16 Aug 1999 19:37:47 +0000 (19:37 +0000)
committeraland <aland>
Mon, 16 Aug 1999 19:37:47 +0000 (19:37 +0000)
fixed radclient to print out more messages, and take a '-d'
argument for 'radius directory', ala the server.  '-x' is now
debugging.

delete intermediate configuration files in rlm_unix

src/lib/valuepair.c
src/main/radclient.c
src/modules/rlm_unix/Makefile
src/modules/rlm_unix/config.h [deleted file]
src/modules/rlm_unix/config.mak [deleted file]

index ac5b589..c8bba74 100644 (file)
@@ -359,11 +359,15 @@ static VALUE_PAIR *pairmake(char *attribute, char *value, int operator)
        VALUE_PAIR      *vp;
        char            *p, *s;
 
-       if ((da = dict_attrbyname(attribute)) == NULL)
+       if ((da = dict_attrbyname(attribute)) == NULL) {
+               librad_log("unknown attribute %s", attribute);
                return NULL;
+       }
 
-       if ((vp = (VALUE_PAIR *)malloc(sizeof(VALUE_PAIR))) == NULL)
+       if ((vp = (VALUE_PAIR *)malloc(sizeof(VALUE_PAIR))) == NULL) {
+               librad_log("out of memory");
                return NULL;
+       }
 
        memset(vp, 0, sizeof(VALUE_PAIR));
        vp->attribute = da->attr;
@@ -429,12 +433,14 @@ static VALUE_PAIR *pairmake(char *attribute, char *value, int operator)
                case PW_TYPE_DATE:
                        if ((vp->lvalue = gettime(value)) == (time_t)-1) {
                                free(vp);
+                               librad_log("failed to get time");
                                return NULL;
                        }
                        vp->length = 4;
                        break;
                default:
                        free(vp);
+                       librad_log("unknown attribute type");
                        return NULL;
        }
        return vp;
@@ -456,26 +462,34 @@ VALUE_PAIR *pairread(char **ptr, int *eol)
 
        /* Get attribute. */
        gettoken(ptr, attr, sizeof(attr));
-       if (attr[0] == 0)
+       if (attr[0] == 0) {
+               librad_log("No token read");
                return NULL;
+       }
 
        /* Now we should have an '=' here. */
        token = gettoken(ptr, buf, sizeof(buf));
-       if (token < T_EQSTART || token > T_EQEND)
+       if (token < T_EQSTART || token > T_EQEND) {
+               librad_log("expecting '='");
                return NULL;
+       }
 
        /* Read value. */
        gettoken(ptr, value, sizeof(value));
-       if (value[0] == 0)
+       if (value[0] == 0) {
+               librad_log("failed to get value");
                return NULL;
+       }
 
        /*
         *      Peek at the next token. Must be T_EOL or T_COMMA.
         */
        p = *ptr;
        t = gettoken(&p, buf, sizeof(buf));
-       if (t != T_EOL && t != T_COMMA)
+       if (t != T_EOL && t != T_COMMA) {
+               librad_log("Expected end of line or comma");
                return NULL;
+       }
 
        if (t == T_COMMA) {
                *ptr = p;
@@ -484,8 +498,9 @@ VALUE_PAIR *pairread(char **ptr, int *eol)
                 */
                if (*p == 0)
                        *eol = 1;
-       } else
+       } else {
                *eol = 1;
+       }
 
        return pairmake(attr, value, token);
 }
index 097e106..ce3707a 100644 (file)
@@ -39,7 +39,7 @@ VALUE_PAIR *readvp(void)
                p = buf;
                do {
                        if ((vp = pairread(&p, &eol)) == NULL) {
-                               librad_perror("radclient");
+                               librad_perror("radclient:");
                                error = 1;
                                break;
                        }
@@ -51,7 +51,7 @@ VALUE_PAIR *readvp(void)
 
 void usage(void)
 {
-       fprintf(stderr, "Usage: radclient [-dn] server acct|auth <secret>\n");
+       fprintf(stderr, "Usage: radclient [-d raddb ] [-nx] server acct|auth <secret>\n");
        exit(1);
 }
 
@@ -66,19 +66,18 @@ int main(int argc, char **argv)
        int             c;
        int             port = 0;
        int             s;
+       char            *radius_dir = RADDBDIR;
 
-       if (dict_init(RADDBDIR, RADIUS_DICTIONARY) < 0) {
-               librad_perror("radclient");
-               return 1;
-       }
-
-       while ((c = getopt(argc, argv, "dn")) != EOF) switch(c) {
+       while ((c = getopt(argc, argv, "d:nx")) != EOF) switch(c) {
                case 'd':
-                       librad_debug = 1;
+                       radius_dir = optarg;
                        break;
                case 'n':
                        do_output = 0;
                        break;
+               case 'x':
+                       librad_debug = 1;
+                       break;
                default:
                        usage();
                        break;
@@ -86,8 +85,14 @@ int main(int argc, char **argv)
        argc -= (optind - 1);
        argv += (optind - 1);
 
-       if (argc < 4)
+       if (argc < 4) {
                usage();
+       }
+
+       if (dict_init(radius_dir, RADIUS_DICTIONARY) < 0) {
+               librad_perror("radclient");
+               return 1;
+       }
 
        if ((req = rad_alloc(1)) == NULL) {
                librad_perror("radclient");
@@ -115,8 +120,9 @@ int main(int argc, char **argv)
        } else if (isdigit(argv[2][0])) {
                if (port == 0) port = 1645;
                port = atoi(argv[2]);
-       } else
+       } else {
                usage();
+       }
 
        /*
         *      Resolve hostname.
@@ -136,8 +142,9 @@ int main(int argc, char **argv)
        /*
         *      Read valuepairs.
         */
-       if ((req->vps = readvp()) == NULL)
+       if ((req->vps = readvp()) == NULL) {
                exit(1);
+       }
 
        /*
         *      Find the password pair and encode it.
index 2128640..049122c 100644 (file)
@@ -3,14 +3,14 @@ SRCS  = rlm_unix.c cache.c
 
 include ../rules.mak
 
-CFLAGS         += -DLOGDIR=\"$(LOGDIR)\"
+CFLAGS += -DLOGDIR=\"$(LOGDIR)\"
+LIBS   = $(LIBSHADOW) $(LIBCRYPT)
+
 
 rlm_unix.c: config.h
 
 include config.mak
 
-LIBS += $(LIBSHADOW) $(LIBCRYPT)
-
 config: config.mak
 
 config.mak config.h:
diff --git a/src/modules/rlm_unix/config.h b/src/modules/rlm_unix/config.h
deleted file mode 100644 (file)
index c81be5a..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#define HAVE_CRYPT_H 1
-#define LIBCRYPT 1
-#define HAVE_GETSPNAM 1
-#define ETC_SHADOW "/etc/shadow"
-#define HAVE_SHADOW_H 1
-#define HAVE_GETUSERSHELL 1
diff --git a/src/modules/rlm_unix/config.mak b/src/modules/rlm_unix/config.mak
deleted file mode 100644 (file)
index 68a1429..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-HAVE_CRYPT_H=
-LIBCRYPT=-lcrypt
-HAVE_GETSPNAM=
-ETC_SHADOW=/etc/shadow
-HAVE_SHADOW_H=
-HAVE_GETUSERSHELL=