Skip to content

Commit

Permalink
allow multiple source* configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Mauchle committed Oct 17, 2019
1 parent 84af44c commit ab15747
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
27 changes: 20 additions & 7 deletions hostport.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,27 @@ int resolvehostports(struct list *hostports, int af, int socktype) {
return 1;
}

struct addrinfo *resolvepassiveaddrinfo(char *hostport, int af, char *default_port, int socktype) {
struct addrinfo *ai = NULL;
struct hostportres *hp = newhostport(hostport, default_port, 0);
if (hp && resolvehostport(hp, af, socktype, 1)) {
ai = hp->addrinfo;
hp->addrinfo = NULL;
struct addrinfo *resolvepassiveaddrinfo(char **hostport, int af, char *default_port, int socktype) {
struct addrinfo *ai = NULL, *last_ai;
int i;
char *any[2] = {"*", NULL};

if(!hostport)
hostport = any;

for (i = 0; hostport[i]; i++) {
struct hostportres *hp = newhostport(hostport[i], default_port, 0);
if (hp && resolvehostport(hp, af, socktype, 1)) {
if (!ai) {
ai = last_ai = hp->addrinfo;
} else {
last_ai->ai_next = hp->addrinfo;
last_ai = last_ai->ai_next;
}
hp->addrinfo = NULL;
freehostport(hp);
}
}
freehostport(hp);
return ai;
}

Expand Down
2 changes: 1 addition & 1 deletion hostport.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void freehostport(struct hostportres *hp);
void freehostports(struct list *hostports);
int resolvehostport(struct hostportres *hp, int af, int socktype, uint8_t passive);
int resolvehostports(struct list *hostports, int af, int socktype);
struct addrinfo *resolvepassiveaddrinfo(char *hostport, int af, char *default_port, int socktype);
struct addrinfo *resolvepassiveaddrinfo(char **hostport, int af, char *default_port, int socktype);
int hostportmatches(struct list *hostports, struct list *matchhostports, uint8_t checkport);
int addressmatches(struct list *hostports, struct sockaddr *addr, uint8_t checkport);
int connecttcphostlist(struct list *hostports, struct addrinfo *src);
Expand Down
18 changes: 9 additions & 9 deletions radsecproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2724,7 +2724,7 @@ int confrealm_cb(struct gconffile **cf, void *arg, char *block, char *opt, char
return 1;
}

int setprotoopts(uint8_t type, char **listenargs, char *sourcearg) {
int setprotoopts(uint8_t type, char **listenargs, char **sourcearg) {
struct commonprotoopts *protoopts;

protoopts = malloc(sizeof(struct commonprotoopts));
Expand All @@ -2741,7 +2741,7 @@ void getmainconfig(const char *configfile) {
long int addttl = LONG_MIN, loglevel = LONG_MIN;
struct gconffile *cfs;
char **listenargs[RAD_PROTOCOUNT];
char *sourcearg[RAD_PROTOCOUNT];
char **sourceargs[RAD_PROTOCOUNT];
char *log_mac_str = NULL;
char *log_key_str = NULL;
uint8_t *fticks_reporting_str = NULL;
Expand All @@ -2752,7 +2752,7 @@ void getmainconfig(const char *configfile) {
cfs = openconfigfile(configfile);
memset(&options, 0, sizeof(options));
memset(&listenargs, 0, sizeof(listenargs));
memset(&sourcearg, 0, sizeof(sourcearg));
memset(&sourceargs, 0, sizeof(sourceargs));
options.logfullusername = 1;

clconfs = list_create();
Expand All @@ -2771,19 +2771,19 @@ void getmainconfig(const char *configfile) {
&cfs, NULL,
#ifdef RADPROT_UDP
"ListenUDP", CONF_MSTR, &listenargs[RAD_UDP],
"SourceUDP", CONF_STR, &sourcearg[RAD_UDP],
"SourceUDP", CONF_MSTR, &sourceargs[RAD_UDP],
#endif
#ifdef RADPROT_TCP
"ListenTCP", CONF_MSTR, &listenargs[RAD_TCP],
"SourceTCP", CONF_STR, &sourcearg[RAD_TCP],
"SourceTCP", CONF_MSTR, &sourceargs[RAD_TCP],
#endif
#ifdef RADPROT_TLS
"ListenTLS", CONF_MSTR, &listenargs[RAD_TLS],
"SourceTLS", CONF_STR, &sourcearg[RAD_TLS],
"SourceTLS", CONF_MSTR, &sourceargs[RAD_TLS],
#endif
#ifdef RADPROT_DTLS
"ListenDTLS", CONF_MSTR, &listenargs[RAD_DTLS],
"SourceDTLS", CONF_STR, &sourcearg[RAD_DTLS],
"SourceDTLS", CONF_MSTR, &sourceargs[RAD_DTLS],
#endif
"PidFile", CONF_STR, &options.pidfile,
"TTLAttribute", CONF_STR, &options.ttlattr,
Expand Down Expand Up @@ -2859,8 +2859,8 @@ void getmainconfig(const char *configfile) {
&fticks_key_str);

for (i = 0; i < RAD_PROTOCOUNT; i++)
if (listenargs[i] || sourcearg[i])
setprotoopts(i, listenargs[i], sourcearg[i]);
if (listenargs[i] || sourceargs[i])
setprotoopts(i, listenargs[i], sourceargs[i]);
}

void getargs(int argc, char **argv, uint8_t *foreground, uint8_t *pretend, uint8_t *loglevel, char **configfile, char **pidfile) {
Expand Down
2 changes: 1 addition & 1 deletion radsecproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct options {

struct commonprotoopts {
char **listenargs;
char *sourcearg;
char **sourcearg;
};

struct request {
Expand Down

0 comments on commit ab15747

Please sign in to comment.