=== modified file 'plugbasedclient.c' --- plugbasedclient.c 2008-07-31 16:20:47 +0000 +++ plugbasedclient.c 2008-08-02 14:48:45 +0000 @@ -120,7 +120,8 @@ fd_set rfds_orig; int ret, maxfd = 0; process *process_list = NULL; - + uid_t uid = 65534; + gid_t gid = 65534; /* The options we understand. */ struct argp_option options[] = { { .name = "global-options", .key = 'g', @@ -135,6 +136,12 @@ { .name = "plugin-dir", .key = 128, .arg = "Directory", .flags = 0, .doc = "Option to change directory to search for plugins" }, + { .name = "userid", .key = 129, + .arg = "Id", .flags = 0, + .doc = "Option to change which user id the plugins will run as" }, + { .name = "groupid", .key = 130, + .arg = "Id", .flags = 0, + .doc = "Option to change which group id the plugins will run as" }, { .name = NULL } }; @@ -175,6 +182,12 @@ case 128: plugindir = arg; break; + case 129: + uid = (uid_t)strtol(arg, NULL, 10); + break; + case 130: + gid = (gid_t)strtol(arg, NULL, 10); + break; case ARGP_KEY_ARG: argp_usage (state); break; @@ -202,6 +215,16 @@ /* return 0; */ + ret = setuid(uid); + if (ret == -1){ + perror("setuid"); + } + + setgid(gid); + if (ret == -1){ + perror("setuid"); + } + dir = opendir(plugindir); if(dir == NULL){ === modified file 'plugins.d/mandosclient.c' --- plugins.d/mandosclient.c 2008-07-31 16:20:47 +0000 +++ plugins.d/mandosclient.c 2008-08-02 14:48:45 +0000 @@ -39,6 +39,8 @@ #include #include #include /* if_nametoindex */ +#include // ioctl, ifreq, SIOCGIFFLAGS, IFF_UP, SIOCSIFFLAGS +#include // ioctl, ifreq, SIOCGIFFLAGS, IFF_UP, SIOCSIFFLAGS #include #include @@ -372,15 +374,15 @@ perror("socket"); return -1; } - - if(if_indextoname(if_index, interface) == NULL){ - if(debug){ - perror("if_indextoname"); + + if(debug){ + if(if_indextoname(if_index, interface) == NULL){ + if(debug){ + perror("if_indextoname"); + } + return -1; } - return -1; - } - - if(debug){ + fprintf(stderr, "Binding to interface %s\n", interface); } @@ -487,7 +489,7 @@ &decrypted_buffer, certdir); if (decrypted_buffer_size >= 0){ - while(written < decrypted_buffer_size){ + while(written < (size_t)decrypted_buffer_size){ ret = (int)fwrite (decrypted_buffer + written, 1, (size_t)decrypted_buffer_size - written, stdout); @@ -645,6 +647,8 @@ int ret; int returncode = EXIT_SUCCESS; const char *interface = "eth0"; + struct ifreq network; + int sd; while (true){ static struct option long_options[] = { @@ -685,14 +689,41 @@ certfile = combinepath(certdir, certfile); if (certfile == NULL){ + returncode = EXIT_FAILURE; goto exit; } certkey = combinepath(certdir, certkey); if (certkey == NULL){ - goto exit; - } - + returncode = EXIT_FAILURE; + goto exit; + } + + sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP); + if(sd < 0) { + perror("socket"); + returncode = EXIT_FAILURE; + goto exit; + } + strcpy(network.ifr_name, interface); + ret = ioctl(sd, SIOCGIFFLAGS, &network); + if(ret == -1){ + + perror("ioctl SIOCGIFFLAGS"); + returncode = EXIT_FAILURE; + goto exit; + } + if((network.ifr_flags & IFF_UP) == 0){ + network.ifr_flags |= IFF_UP; + ret = ioctl(sd, SIOCSIFFLAGS, &network); + if(ret == -1){ + perror("ioctl SIOCSIFFLAGS"); + returncode = EXIT_FAILURE; + goto exit; + } + } + close(sd); + if (not debug){ avahi_set_log_function(empty_log); } @@ -703,7 +734,7 @@ /* Allocate main loop object */ if (!(simple_poll = avahi_simple_poll_new())) { fprintf(stderr, "Failed to create simple poll object.\n"); - + returncode = EXIT_FAILURE; goto exit; }