/** Get a sequence of attribute value pairs from the file input and make them into a list of value_pairs * * @param rh a handle to parsed configuration. * @param input a %FILE handle. * @return the array of value pairs. */ VALUE_PAIR *rc_avpair_readin(rc_handle const *rh, FILE *input) { VALUE_PAIR *vp = NULL; char buffer[1024], *q; while (fgets(buffer, sizeof(buffer), input) != NULL) { q = buffer; while(*q && isspace(*q)) q++; if ((*q == '\n') || (*q == '#') || (*q == '\0')) continue; if (rc_avpair_parse(rh, q, &vp) < 0) { rc_log(LOG_ERR, "rc_avpair_readin: malformed attribute: %s", buffer); rc_avpair_free(vp); return NULL; } } return vp; }
int main(int argc, char **argv) { int i, nas_port, ch, acct, server, ecount, firstline, theend; void *rh; size_t len; VALUE_PAIR *send; char *rc_conf, *cp; char lbuf[4096]; rc_conf = ""; nas_port = 5060; acct = 0; server = 0; while ((ch = getopt(argc, argv, "af:p:s")) != -1) { switch (ch) { case 'f': rc_conf = optarg; break; case 'p': nas_port = atoi(optarg); break; case 'a': acct = 1; break; case 's': server = 1; break; } } argc -= optind; argv += optind; if ((argc == 0 && server == 0) || (argc != 0 && server != 0)) exit(1); if ((rh = rc_read_config(rc_conf)) == NULL) { fprintf(stderr, "tls-restart: error opening radius configuration file\n"); exit(1); } if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) { fprintf(stderr, "tls-restart: error reading radius dictionary\n"); exit(2); } if (server == 0) { send = NULL; for (i = 0; i < argc; i++) { if (rc_avpair_parse(rh, argv[i], &send) < 0) { fprintf(stderr, "%s: can't parse AV pair\n", argv[i]); exit(3); } } exit(process(rh, send, acct, nas_port)); } while (1 == 1) { send = NULL; ecount = 0; firstline = 1; acct = 0; do { len = 0; cp = rc_fgetln(stdin, &len); theend = 1; if (cp != NULL && len > 0) { if (firstline != 0) { if (len >= 4 && memcmp(cp, "ACCT", 4) == 0) acct = 1; firstline = 0; theend = 0; continue; } for (i = 0; i < len; i++) { if (!isspace(cp[i])) { theend = 0; break; } } if (theend == 0) { memcpy(lbuf, cp, len); lbuf[len] = '\0'; if (rc_avpair_parse(rh, lbuf, &send) < 0) { fprintf(stderr, "%s: can't parse AV pair\n", lbuf); ecount++; } } } } while (theend == 0); if (send != NULL && ecount == 0) printf("%d\n\n", process(rh, send, acct, nas_port)); else printf("%d\n\n", -1); fflush(stdout); if (send != NULL) rc_avpair_free(send); if (cp == NULL || len == 0) break; } exit(0); }