=== modified file 'plugbasedclient.c' --- plugbasedclient.c 2008-07-22 05:26:44 +0000 +++ plugbasedclient.c 2008-07-31 16:20:47 +0000 @@ -56,6 +56,7 @@ char *name; /* can be "global" and any plugin name */ char **argv; int argc; + bool disable; struct plugin *next; } plugin; @@ -81,8 +82,9 @@ new_plugin->argv[0] = name; new_plugin->argv[1] = NULL; new_plugin->argc = 1; + new_plugin->disable = false; + new_plugin->next = *plugin_list; /* Append the new plugin to the list */ - new_plugin->next = *plugin_list; *plugin_list = new_plugin; return new_plugin; } @@ -110,15 +112,15 @@ static char args_doc[] = ""; int main(int argc, char *argv[]){ - char plugindir[] = "plugins.d"; - size_t d_name_len, plugindir_len = sizeof(plugindir)-1; + const char *plugindir = "plugins.d"; + size_t d_name_len; DIR *dir; struct dirent *dirst; struct stat st; fd_set rfds_orig; int ret, maxfd = 0; process *process_list = NULL; - + /* The options we understand. */ struct argp_option options[] = { { .name = "global-options", .key = 'g', @@ -127,6 +129,12 @@ { .name = "options-for", .key = 'o', .arg = "plugin:option[,option[,...]]", .flags = 0, .doc = "Options effecting only specified plugins" }, + { .name = "disable-plugin", .key = 'd', + .arg = "Plugin[,Plugin[,...]]", .flags = 0, + .doc = "Option to disable specififed plugins" }, + { .name = "plugin-dir", .key = 128, + .arg = "Directory", .flags = 0, + .doc = "Option to change directory to search for plugins" }, { .name = NULL } }; @@ -155,6 +163,18 @@ } while (p); } break; + case 'd': + if (arg != NULL){ + char *p = strtok(arg, ","); + do{ + getplugin(p, plugins)->disable = true; + p = strtok(NULL, ","); + } while (p); + } + break; + case 128: + plugindir = arg; + break; case ARGP_KEY_ARG: argp_usage (state); break; @@ -181,7 +201,7 @@ /* } */ /* return 0; */ - + dir = opendir(plugindir); if(dir == NULL){ @@ -207,17 +227,19 @@ continue; } - char *filename = malloc(d_name_len + plugindir_len + 2); + char *filename = malloc(d_name_len + strlen(plugindir) + 2); strcpy(filename, plugindir); strcat(filename, "/"); strcat(filename, dirst->d_name); stat(filename, &st); - if (S_ISREG(st.st_mode) and (access(filename, X_OK) == 0)){ + if (S_ISREG(st.st_mode) + and (access(filename, X_OK) == 0) + and not (getplugin(dirst->d_name, &plugin_list)->disable)){ // Starting a new process to be watched process *new_process = malloc(sizeof(process)); - int pipefd[2]; + int pipefd[2]; ret = pipe(pipefd); if (ret == -1){ perror(argv[0]); @@ -229,15 +251,8 @@ closedir(dir); close(pipefd[0]); /* close unused read end of pipe */ dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */ - char *basename; - basename = strrchr(filename, '/'); - if (basename == NULL){ - basename = filename; - } else { - basename++; - } - plugin *p = getplugin(basename, &plugin_list); + plugin *p = getplugin(dirst->d_name, &plugin_list); plugin *g = getplugin(NULL, &plugin_list); for(char **a = g->argv + 1; *a != NULL; a++){ addarguments(p, *a); === modified file 'plugins.d/mandosclient.c' --- plugins.d/mandosclient.c 2008-07-30 02:11:33 +0000 +++ plugins.d/mandosclient.c 2008-07-31 16:20:47 +0000 @@ -197,8 +197,10 @@ gpgme_data_release(dh_crypto); /* Seek back to the beginning of the GPGME plaintext data buffer */ - gpgme_data_seek(dh_plain, (off_t) 0, SEEK_SET); - + if (gpgme_data_seek(dh_plain, (off_t) 0, SEEK_SET) == -1){ + perror("pgpme_data_seek"); + } + *new_packet = 0; while(true){ if (new_packet_length + BUFFER_SIZE > new_packet_capacity){ @@ -619,15 +621,18 @@ } } -/* combinds two strings and returns the malloced new string. som sane checks could/should be added */ -const char *combinestrings(const char *first, const char *second){ +/* combinds file name and path and returns the malloced new string. som sane checks could/should be added */ +const char *combinepath(const char *first, const char *second){ char *tmp; - tmp = malloc(strlen(first) + strlen(second)); + tmp = malloc(strlen(first) + strlen(second) + 2); if (tmp == NULL){ perror("malloc"); return NULL; } strcpy(tmp, first); + if (first[0] != '\0' and first[strlen(first) - 1] != '/'){ + strcat(tmp, "/"); + } strcat(tmp, second); return tmp; } @@ -678,12 +683,12 @@ } } - certfile = combinestrings(certdir, certfile); + certfile = combinepath(certdir, certfile); if (certfile == NULL){ goto exit; } - certkey = combinestrings(certdir, certkey); + certkey = combinepath(certdir, certkey); if (certkey == NULL){ goto exit; } @@ -761,6 +766,8 @@ if (simple_poll) avahi_simple_poll_free(simple_poll); - + free(certfile); + free(certkey); + return returncode; }