old patch from ove

This commit is contained in:
Olaf Rempel 2008-01-05 18:54:05 +01:00
parent 38dd7db600
commit f0134a602f
2 changed files with 25 additions and 7 deletions

View File

@ -23,6 +23,7 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include <pwd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
@ -37,7 +38,7 @@
#define DEFAULT_CONFIG "cachesyncd.conf" #define DEFAULT_CONFIG "cachesyncd.conf"
#define DEFAULT_LOGFILE "cachesyncd.log" #define DEFAULT_LOGFILE "cachesyncd.log"
#define DEFAULT_USER "httpd"
#define BUF_SIZE 256 #define BUF_SIZE 256
static struct option opts[] = { static struct option opts[] = {
@ -84,7 +85,8 @@ int msock_read_callback(int fd, void *privdata)
} else if (!strncmp(privdata, "DELETE ", 7)) { } else if (!strncmp(privdata, "DELETE ", 7)) {
log_print(LOG_DEBUG, "delete '%s'", privdata +7); log_print(LOG_DEBUG, "delete '%s'", privdata +7);
//delete_file(buf +7); if (unlink(privdata +7))
log_print(LOG_ERROR, "delete '%s' failed", privdata +7);
} else { } else {
log_print(LOG_DEBUG, "recv unknown cmd via multicast: '%s'", privdata); log_print(LOG_DEBUG, "recv unknown cmd via multicast: '%s'", privdata);
@ -99,6 +101,20 @@ int msock_keepalive_timeout(void *privdata)
return 0; return 0;
} }
void drop_privileges(char *user)
{
struct passwd *user_info;
user_info = getpwnam(user);
if (user_info == NULL) {
log_print(LOG_ERROR,"drop_privileges(): user '%s' not found", user);
} else {
if (setregid(user_info->pw_gid, user_info->pw_gid))
log_print(LOG_ERROR, "setgid() failed");
if (setreuid(user_info->pw_uid, user_info->pw_uid))
log_print(LOG_ERROR, "setuid() failed");
}
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *config = DEFAULT_CONFIG; char *config = DEFAULT_CONFIG;
@ -158,14 +174,16 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
usock = sock_init();
if (usock < 0)
return -1;
msock = mcast_init(); msock = mcast_init();
if (msock < 0) if (msock < 0)
return -1; return -1;
drop_privileges(config_get_string("global", "user", DEFAULT_USER));
usock = sock_init();
if (usock < 0)
return -1;
event_add_readfd(usock, usock_accept_callback, buf); event_add_readfd(usock, usock_accept_callback, buf);
event_add_readfd(msock, msock_read_callback, buf); event_add_readfd(msock, msock_read_callback, buf);

View File

@ -3,7 +3,7 @@
user httpd user httpd
# unix domain socket location # unix domain socket location
socket ./cachesync.sock socket /tmp/cachesync.sock
# bind to multicast interface # bind to multicast interface
mcastdev eth0 mcastdev eth0