=== modified file 'plugbasedclient.c' --- plugbasedclient.c 2008-07-29 03:35:39 +0000 +++ plugbasedclient.c 2008-07-31 19:51:44 +0000 @@ -53,6 +53,7 @@ char *name; /* can be "global" and any plugin name */ char **argv; int argc; + bool disable; struct plugin *next; } plugin; @@ -78,8 +79,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; } @@ -107,15 +109,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', @@ -124,6 +126,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 } }; @@ -152,6 +160,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; @@ -178,7 +198,7 @@ /* } */ /* return 0; */ - + dir = opendir(plugindir); if(dir == NULL){ @@ -204,17 +224,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]); @@ -226,15 +248,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-31 19:48:05 +0000 +++ plugins.d/mandosclient.c 2008-07-31 19:51:44 +0000 @@ -67,14 +67,13 @@ // getopt long #include -#ifndef CERT_ROOT -#define CERT_ROOT "/conf/conf.d/cryptkeyreq/" -#endif -#define CERTFILE CERT_ROOT "openpgp-client.txt" -#define KEYFILE CERT_ROOT "openpgp-client-key.txt" #define BUFFER_SIZE 256 #define DH_BITS 1024 +const char *certdir = "/conf/conf.d/cryptkeyreq/"; +const char *certfile = "openpgp-client.txt"; +const char *certkey = "openpgp-client-key.txt"; + bool debug = false; typedef struct { @@ -100,7 +99,12 @@ /* Init GPGME */ gpgme_check_version(NULL); - gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); + rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP); + if (rc != GPG_ERR_NO_ERROR){ + fprintf(stderr, "bad gpgme_engine_check_version: %s: %s\n", + gpgme_strsource(rc), gpgme_strerror(rc)); + return -1; + } /* Set GPGME home directory */ rc = gpgme_get_engine_info (&engine_info); @@ -192,8 +196,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){ @@ -252,7 +258,7 @@ if(debug){ fprintf(stderr, "Initializing GnuTLS\n"); } - + if ((ret = gnutls_global_init ()) != GNUTLS_E_SUCCESS) { fprintf (stderr, "global_init: %s\n", safer_gnutls_strerror(ret)); @@ -274,17 +280,17 @@ if(debug){ fprintf(stderr, "Attempting to use OpenPGP certificate %s" - " and keyfile %s as GnuTLS credentials\n", CERTFILE, - KEYFILE); + " and keyfile %s as GnuTLS credentials\n", certfile, + certkey); } ret = gnutls_certificate_set_openpgp_key_file - (es->cred, CERTFILE, KEYFILE, GNUTLS_OPENPGP_FMT_BASE64); + (es->cred, certfile, certkey, GNUTLS_OPENPGP_FMT_BASE64); if (ret != GNUTLS_E_SUCCESS) { fprintf (stderr, "Error[%d] while reading the OpenPGP key pair ('%s'," " '%s')\n", - ret, CERTFILE, KEYFILE); + ret, certfile, certkey); fprintf(stdout, "The Error is: %s\n", safer_gnutls_strerror(ret)); return -1; @@ -487,7 +493,7 @@ decrypted_buffer_size = pgp_packet_decrypt(buffer, buffer_length, &decrypted_buffer, - CERT_ROOT); + certdir); if (decrypted_buffer_size >= 0){ while(written < (size_t) decrypted_buffer_size){ ret = (int)fwrite (decrypted_buffer + written, 1, @@ -622,6 +628,23 @@ } } +/* 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) + 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; +} + + int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char*argv[]) { AvahiServerConfig config; AvahiSServiceBrowser *sb = NULL; @@ -635,8 +658,11 @@ while (true){ static struct option long_options[] = { {"debug", no_argument, (int *)&debug, 1}, - {"connect", required_argument, 0, 'c'}, + {"connect", required_argument, 0, 'C'}, {"interface", required_argument, 0, 'i'}, + {"certdir", required_argument, 0, 'd'}, + {"certkey", required_argument, 0, 'c'}, + {"certfile", required_argument, 0, 'k'}, {0, 0, 0, 0} }; int option_index = 0; @@ -653,13 +679,27 @@ case 'i': interface = optarg; break; + case 'C': + connect_to = optarg; + break; + case 'd': + certdir = optarg; + break; case 'c': - connect_to = optarg; + certfile = optarg; + break; + case 'k': + certkey = optarg; break; default: exit(EXIT_FAILURE); } } + + certfile = combinepath(certdir, certfile); + if (certfile == NULL){ + goto exit; + } if(interface != NULL){ if_index = (AvahiIfIndex) if_nametoindex(interface); @@ -693,6 +733,11 @@ } } + certkey = combinepath(certdir, certkey); + if (certkey == NULL){ + goto exit; + } + if (not debug){ avahi_set_log_function(empty_log); } @@ -764,6 +809,8 @@ if (simple_poll) avahi_simple_poll_free(simple_poll); - + free(certfile); + free(certkey); + return returncode; }