Mercurial > dnsbl
comparison src/dnsbl.cpp @ 48:5ef10dc14457
properly drop root privs
author | carl |
---|---|
date | Fri, 09 Jul 2004 13:57:59 -0700 |
parents | 66c66a6ee65f |
children | c2371bb6cf84 |
comparison
equal
deleted
inserted
replaced
47:71252053d258 | 48:5ef10dc14457 |
---|---|
1410 if (daemon(1,0) < 0) { | 1410 if (daemon(1,0) < 0) { |
1411 fprintf(stderr, "daemon() call failed\n"); | 1411 fprintf(stderr, "daemon() call failed\n"); |
1412 exit(EX_UNAVAILABLE); | 1412 exit(EX_UNAVAILABLE); |
1413 } | 1413 } |
1414 | 1414 |
1415 // initialize the thread sync objects | |
1416 pthread_mutex_init(&config_mutex, 0); | |
1417 pthread_mutex_init(&syslog_mutex, 0); | |
1418 pthread_mutex_init(&resolve_mutex, 0); | |
1419 | |
1420 // load the initial config | |
1421 config = new_conf(); | |
1422 | |
1423 // only create threads after the fork() in daemon | |
1424 pthread_t tid; | |
1425 if (pthread_create(&tid, 0, config_loader, 0)) | |
1426 my_syslog("failed to create config loader thread"); | |
1427 if (pthread_detach(tid)) | |
1428 my_syslog("failed to detach config loader thread"); | |
1429 | |
1430 // write the pid | 1415 // write the pid |
1431 const char *pidpath = "/var/run/dnsbl.pid"; | 1416 const char *pidpath = "/var/run/dnsbl.pid"; |
1432 unlink(pidpath); | 1417 unlink(pidpath); |
1433 FILE *f = fopen(pidpath, "w"); | 1418 FILE *f = fopen(pidpath, "w"); |
1434 if (f) { | 1419 if (f) { |
1446 fprintf(f, "%d\n", (u_int)getpid()); | 1431 fprintf(f, "%d\n", (u_int)getpid()); |
1447 #endif | 1432 #endif |
1448 fclose(f); | 1433 fclose(f); |
1449 } | 1434 } |
1450 | 1435 |
1451 | |
1452 // drop root privs | 1436 // drop root privs |
1453 struct passwd *pw = getpwnam("dnsbl"); | 1437 struct passwd *pw = getpwnam("dnsbl"); |
1454 if (pw) { | 1438 if (pw) { |
1439 if (setgid(pw->pw_gid) == -1) { | |
1440 my_syslog("failed to switch to group dnsbl"); | |
1441 } | |
1455 if (setuid(pw->pw_uid) == -1) { | 1442 if (setuid(pw->pw_uid) == -1) { |
1456 my_syslog("failed to switch to user dnsbl"); | 1443 my_syslog("failed to switch to user dnsbl"); |
1457 } | 1444 } |
1458 } | 1445 } |
1446 | |
1447 // initialize the thread sync objects | |
1448 pthread_mutex_init(&config_mutex, 0); | |
1449 pthread_mutex_init(&syslog_mutex, 0); | |
1450 pthread_mutex_init(&resolve_mutex, 0); | |
1451 | |
1452 // load the initial config | |
1453 config = new_conf(); | |
1454 | |
1455 // only create threads after the fork() in daemon | |
1456 pthread_t tid; | |
1457 if (pthread_create(&tid, 0, config_loader, 0)) | |
1458 my_syslog("failed to create config loader thread"); | |
1459 if (pthread_detach(tid)) | |
1460 my_syslog("failed to detach config loader thread"); | |
1459 | 1461 |
1460 time_t starting = time(NULL); | 1462 time_t starting = time(NULL); |
1461 int rc = smfi_main(); | 1463 int rc = smfi_main(); |
1462 if ((rc != MI_SUCCESS) && (time(NULL) > starting+5*60)) { | 1464 if ((rc != MI_SUCCESS) && (time(NULL) > starting+5*60)) { |
1463 my_syslog("trying to restart after smfi_main()"); | 1465 my_syslog("trying to restart after smfi_main()"); |