comparison src/sm-archive.cpp @ 2:32b57406b656

initial version
author carl
date Fri, 10 Mar 2006 10:47:12 -0800
parents 616666e2f34c
children 01268466f0dc
comparison
equal deleted inserted replaced
1:45c8592d5d13 2:32b57406b656
53 #include <sys/wait.h> /* header for waitpid() and various macros */ 53 #include <sys/wait.h> /* header for waitpid() and various macros */
54 #include <signal.h> /* header for signal functions */ 54 #include <signal.h> /* header for signal functions */
55 55
56 #include "includes.h" 56 #include "includes.h"
57 57
58 static char* dnsbl_version="$Id$"; 58 static char* smarchive_version="$Id$";
59 59
60 60
61 extern "C" { 61 extern "C" {
62 #include "libmilter/mfapi.h" 62 #include "libmilter/mfapi.h"
63 sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr); 63 sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr);
121 text = buf; 121 text = buf;
122 } 122 }
123 if (use_syslog) { 123 if (use_syslog) {
124 pthread_mutex_lock(&syslog_mutex); 124 pthread_mutex_lock(&syslog_mutex);
125 if (!syslog_opened) { 125 if (!syslog_opened) {
126 openlog("dnsbl", LOG_PID, LOG_MAIL); 126 openlog("sm-archive", LOG_PID, LOG_MAIL);
127 syslog_opened = true; 127 syslog_opened = true;
128 } 128 }
129 syslog(LOG_NOTICE, "%s", text); 129 syslog(LOG_NOTICE, "%s", text);
130 pthread_mutex_unlock(&syslog_mutex); 130 pthread_mutex_unlock(&syslog_mutex);
131 } 131 }
252 if (debug_syslog) { 252 if (debug_syslog) {
253 char buf[maxlen]; 253 char buf[maxlen];
254 snprintf(buf, sizeof(buf), "loading configuration generation %d", newc->generation); 254 snprintf(buf, sizeof(buf), "loading configuration generation %d", newc->generation);
255 my_syslog(buf); 255 my_syslog(buf);
256 } 256 }
257 if (load_conf(*newc, "dnsbl.conf")) { 257 if (load_conf(*newc, "sm-archive.conf")) {
258 newc->load_time = time(NULL); 258 newc->load_time = time(NULL);
259 return newc; 259 return newc;
260 } 260 }
261 delete newc; 261 delete newc;
262 return NULL; 262 return NULL;
296 if (old) old_configs.insert(old); 296 if (old) old_configs.insert(old);
297 } 297 }
298 else { 298 else {
299 // failed to load new config 299 // failed to load new config
300 my_syslog("failed to load new configuration"); 300 my_syslog("failed to load new configuration");
301 system("echo 'failed to load new dnsbl configuration from /etc/dnsbl' | mail -s 'error in /etc/dnsbl configuration' root"); 301 system("echo 'failed to load new sm-archive configuration from /etc/sm-archive' | mail -s 'error in /etc/sm-archive configuration' root");
302 // update the load time on the current config to prevent complaining every 3 minutes 302 // update the load time on the current config to prevent complaining every 3 minutes
303 dc.load_time = time(NULL); 303 dc.load_time = time(NULL);
304 } 304 }
305 } 305 }
306 // now look for old configs with zero ref counts 306 // now look for old configs with zero ref counts
446 fprintf(stderr, "daemon() call failed\n"); 446 fprintf(stderr, "daemon() call failed\n");
447 exit(EX_UNAVAILABLE); 447 exit(EX_UNAVAILABLE);
448 } 448 }
449 449
450 // write the pid 450 // write the pid
451 const char *pidpath = "/var/run/dnsbl.pid"; 451 const char *pidpath = "/var/run/sm-archive.pid";
452 unlink(pidpath); 452 unlink(pidpath);
453 FILE *f = fopen(pidpath, "w"); 453 FILE *f = fopen(pidpath, "w");
454 if (f) { 454 if (f) {
455 #ifdef linux 455 #ifdef linux
456 // from a comment in the DCC source code: 456 // from a comment in the DCC source code:
474 474
475 // drop root privs 475 // drop root privs
476 struct passwd *pw = getpwnam("sm-archive"); 476 struct passwd *pw = getpwnam("sm-archive");
477 if (pw) { 477 if (pw) {
478 if (setgid(pw->pw_gid) == -1) { 478 if (setgid(pw->pw_gid) == -1) {
479 my_syslog("failed to switch to group dnsbl"); 479 my_syslog("failed to switch to group sm-archive");
480 } 480 }
481 if (setuid(pw->pw_uid) == -1) { 481 if (setuid(pw->pw_uid) == -1) {
482 my_syslog("failed to switch to user dnsbl"); 482 my_syslog("failed to switch to user sm-archive");
483 } 483 }
484 } 484 }
485 485
486 // load the initial config 486 // load the initial config
487 config = new_conf(); 487 config = new_conf();