- patch from Dan Weber: Open the password file for SIP

accounts at startup, so we still have access after
  chroot()ing. PID filename can be given at command-line.
This commit is contained in:
Thomas Ries
2004-07-06 17:23:50 +00:00
parent 31f59d1870
commit 8e5abdc931
6 changed files with 57 additions and 27 deletions
+3
View File
@@ -1,5 +1,8 @@
0.5.8
=====
06-Jul-2004: - patch from Dan Weber: Open the password file for SIP
accounts at startup, so we still have access after
chroot()ing. PID filename can be given at command-line.
27-Jun-2004: - fix: in some configurations incoming requests could
be sent to a wrong port number.
+8 -6
View File
@@ -42,6 +42,9 @@ static char const ident[]="$Id$";
/* configuration storage */
extern struct siproxd_config configuration;
/* Global File instance on pw file */
extern FILE *siproxd_passwordfile;
/* local protorypes */
static char *auth_generate_nonce(void);
static int auth_check(osip_proxy_authorization_t *proxy_auth);
@@ -248,7 +251,6 @@ static char *auth_getpwd(char *username) {
char password[PASSWORD_SIZE];
} auth_cache_t;
FILE *pwdfile;
char buff[128];
int i;
static auth_cache_t *auth_cache=NULL;
@@ -258,14 +260,16 @@ static char *auth_getpwd(char *username) {
if (auth_cache==NULL) {
DEBUGC(DBCLASS_AUTH,"initialize password cache");
pwdfile=fopen(configuration.proxy_auth_pwfile,"r");
/* config file not found or unable to open for read */
if (pwdfile==NULL) {
if (siproxd_passwordfile==NULL) {
ERROR ("could not open password file: %s", strerror(errno));
return NULL;
}
while (fgets(buff,sizeof(buff),pwdfile) != NULL) {
rewind(siproxd_passwordfile);
while (fgets(buff,sizeof(buff),siproxd_passwordfile) != NULL) {
/* life insurance */
buff[sizeof(buff)-1]='\0';
@@ -302,8 +306,6 @@ static char *auth_getpwd(char *username) {
if (i == 2) auth_cache_count++;
}
fclose(pwdfile);
} /* initialize cache */
/* search cache for user */
+5 -2
View File
@@ -71,6 +71,7 @@ char *utils_inet_ntoa(struct in_addr in);
*/
int custom_fw_control(fw_ctl_t fwdata) {
static char tmp[256];
size_t pos;
tmp[0]='\0';
switch (fwdata.action) {
@@ -97,11 +98,13 @@ int custom_fw_control(fw_ctl_t fwdata) {
break;
}
sprintf(&tmp[strlen(tmp)],"[lcl %s:%i] ",
pos = strlen(tmp);
sprintf(&tmp[pos],"[lcl %s:%i] ",
utils_inet_ntoa(fwdata.local_ipaddr),
fwdata.local_port);
sprintf(&tmp[strlen(tmp)],"[rem %s:%i] ",
pos = strlen(tmp);
sprintf(&tmp[pos],"[rem %s:%i] ",
utils_inet_ntoa(fwdata.remote_ipaddr),
fwdata.remote_port);
+1 -2
View File
@@ -38,9 +38,8 @@
static char const ident[]="$Id$";
/* configuration storage */
extern struct siproxd_config configuration;
extern struct siproxd_config configuration; /* defined in siproxd.c */
extern int errno;
extern struct urlmap_s urlmap[]; /* URL mapping table */
extern struct lcl_if_s local_addresses;
+36 -15
View File
@@ -43,14 +43,18 @@ static char const ident[]="$Id$";
/* configuration storage */
struct siproxd_config configuration;
/* Global File instance on pw file */
FILE *siproxd_passwordfile;
/* -h help option text */
static const char str_helpmsg[] =
PACKAGE "-" VERSION "-" BUILDSTR " (c) 2002-2004 Thomas Ries\n"
"\nUsage: siproxd [options]\n\n"
"options:\n"
" --help (-h) help\n"
" --debug <pattern> (-d) set debug-pattern\n"
" --config <cfgfile> (-c) use the specified config file\n"
" --help (-h) help\n"
" --debug <pattern> (-d) set debug-pattern\n"
" --config <cfgfile> (-c) use the specified config file\n"
" --pid-file <pidfile> (-p) create pid file <pidfile>\n"
"";
@@ -75,13 +79,13 @@ int main (int argc, char *argv[])
char buff [BUFFER_SIZE];
sip_ticket_t ticket;
extern char *optarg;
extern char *optarg; /* Defined in libc getopt and unistd.h */
int ch1;
char configfile[64]="siproxd"; /* basename of configfile */
int config_search=1; /* search the config file */
int cmdline_debuglevel=0;
char *pidfilename=NULL;
struct sigaction act;
log_set_stdout(1);
@@ -111,6 +115,16 @@ int main (int argc, char *argv[])
log_set_pattern(configuration.debuglevel);
/*
* open a the pwfile instance, so we still have access after
* we possibly have chroot()ed to somewhere.
*/
if (configuration.proxy_auth_pwfile) {
siproxd_passwordfile = fopen(configuration.proxy_auth_pwfile, "r");
} else {
siproxd_passwordfile = NULL;
}
/*
* parse command line
*/
@@ -121,13 +135,14 @@ int main (int argc, char *argv[])
{"help", no_argument, NULL, 'h'},
{"config", required_argument, NULL, 'c'},
{"debug", required_argument, NULL, 'd'},
{"pid-file", required_argument, NULL,'p'},
{0,0,0,0}
};
while ((ch1 = getopt_long(argc, argv, "hc:d:n",
while ((ch1 = getopt_long(argc, argv, "hc:d:p:",
long_options, &option_index)) != -1) {
#else /* ! HAVE_GETOPT_LONG */
while ((ch1 = getopt(argc, argv, "hc:d:n:")) != -1) {
while ((ch1 = getopt(argc, argv, "hc:d:p:")) != -1) {
#endif
switch (ch1) {
case 'h': /* help */
@@ -138,8 +153,9 @@ int main (int argc, char *argv[])
case 'c': /* load config file */
DEBUGC(DBCLASS_CONFIG,"option: config file=%s",optarg);
strncpy(configfile,optarg,sizeof(configfile)-1);
configfile[sizeof(configfile)]='\0';
i=sizeof(configfile)-1;
strncpy(configfile,optarg,i-1);
configfile[i]='\0';
config_search=0;
break;
@@ -149,6 +165,10 @@ int main (int argc, char *argv[])
log_set_pattern(cmdline_debuglevel);
break;
case 'p':
pidfilename = optarg;
break;
default:
DEBUGC(DBCLASS_CONFIG,"no command line options");
break;
@@ -187,12 +207,13 @@ int main (int argc, char *argv[])
}
/* write PID file of main thread */
if (configuration.pid_file) {
if (pidfilename == NULL) pidfilename = configuration.pid_file;
if (pidfilename) {
FILE *pidfile;
DEBUGC(DBCLASS_CONFIG,"creating PID file [%s]", configuration.pid_file);
DEBUGC(DBCLASS_CONFIG,"creating PID file [%s]", pidfilename);
sts=unlink(configuration.pid_file);
if ((sts==0) ||(errno == ENOENT)) {
if ((pidfile=fopen(configuration.pid_file, "w"))) {
if ((pidfile=fopen(pidfilename, "w"))) {
fprintf(pidfile,"%i\n",(int)getpid());
fclose(pidfile);
} else {
@@ -473,9 +494,9 @@ int main (int argc, char *argv[])
INFO("properly terminating siproxd");
/* remove PID file */
if (configuration.pid_file) {
DEBUGC(DBCLASS_CONFIG,"deleting PID file [%s]", configuration.pid_file);
sts=unlink(configuration.pid_file);
if (pidfilename) {
DEBUGC(DBCLASS_CONFIG,"deleting PID file [%s]", pidfilename);
sts=unlink(pidfilename);
if (sts != 0) {
WARN("couldn't delete old PID file: %s", strerror(errno));
}
+4 -2
View File
@@ -104,8 +104,8 @@ typedef struct {
/* function returns STS_* status values vvv */
/* sock.c */
int sipsock_listen (void); /*X*/
int sipsock_wait();
int sipsock_listen(void); /*X*/
int sipsock_wait(void);
int sipsock_read(void *buf, size_t bufsize,
struct sockaddr_in *from, int *protocol);
int sipsock_send(struct in_addr addr, int port, int protocol, /*X*/
@@ -232,4 +232,6 @@ int fwapi_stop_rtp(int rtp_direction,
#define DIR_OUTGOING 2
/* various */
#ifndef satoi
#define satoi atoi /* used in libosips MSG_TEST_CODE macro ... */
#endif