/** * makewordlistfromkey - Takes a public key and splits it into a set of * unique words. * @wordlist: The current word list. * @key: The key to return the words from. * * We take words and split it on non alpha numeric characters. These get * added to the word list if they're not already present. If the wordlist * is NULL then we start a new list, otherwise it's search for already * added words. Note that words is modified in the process of scanning. * * Returns the new word list. */ struct ll *makewordlistfromkey(struct ll *wordlist, struct openpgp_publickey *key) { char **uids; int i; struct ll *words = NULL; struct ll *wl = NULL; uids = keyuids(key, NULL); for (i = 0; uids != NULL && uids[i] != NULL; ++i) { words = makewordlist(NULL, uids[i]); for (wl = words; wl != NULL; wl = wl->next) { if (llfind(wordlist, wl->object, (int (*)(const void *, const void *)) strcmp ) == NULL) { wordlist = lladd(wordlist, strdup(wl->object)); } } free(uids[i]); uids[i] = NULL; } free(uids); return wordlist; }
/** * duplicate the list * * @return the new list member, or NULL in failure */ linkedlist* lldup(const linkedlist*a) { if (a) return lladd (lldup(a->next), a->string); else return NULL; }
/** * Add hostname to machinelist if and only if * the host does not already exist in the machine list. * * @return linked list where machinename is added if it does not exist already */ static linkedlist * machinelist_lladd(linkedlist * machinelist, const char * machinename) { if (llmatch(machinelist, machinename)) /* if there is match, ignore */ return machinelist; else return lladd(machinelist, machinename); }
adt_status queue_insert(QUEUE queue, void *data) { adt_status status; if(NULL == queue) { status = ADT_INVALID_PARAM; goto end; } status=lladd(queue->list,data,NULL); if(ADT_OK == status) { queue->size++; } end: return status; }
void const* Sub(void(*cb)(Sensor*)) { if(!cb)return NULL; { SensorCB c= { .cb=cb, }, *p=malloc(sizeof*p); if(!p)return NULL; memcpy(p, &c, sizeof*p); if(!subs) { subs=lle(p); } else { lladd((LLNODE*)subs, p); } return p; }
/** * Option parsing routine. * * Remember to update other places, such as execute_rsh_multiple routine when changing here. * @return 1 on failure. * @return 0 on success. */ int parse_options ( int ac, char ** av) { int c; /* option */ linkedlist * machinelist = NULL; linkedlist * rshcommandline_r = NULL; /* command line for rsh in reverse order*/ #ifdef HAVE_GETOPT_LONG int index_point; static struct option long_options[]= { {"verbose", no_argument, 0, 'v'}, {"quiet", no_argument, 0, 'q'}, {"show-machine-names", no_argument, 0, 'M'}, {"hide-machine-names", no_argument, 0, 'H'}, {"duplicate-input", no_argument, 0, 'i'}, {"bufsize", required_argument, 0, 'b'}, /* machine-specification */ {"machine", required_argument, 0, 'm'}, {"num-topology", required_argument, 0, 'n'}, {"all", no_argument, 0, 'a' }, {"group", required_argument, 0, 'g'}, {"file", required_argument, 0, 'f'}, /* rsh/ssh specification */ {"remoteshell", required_argument, 0, 'r'}, {"remoteshellopt", required_argument, 0, 'o'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {"wait-shell", no_argument, 0, 'w'}, {"concurrent-shell", no_argument, 0, 'c'}, {"forklimit", required_argument, 0, 'F'}, {0,0,0,0} }; #else #define getopt_long(a,b,c,d,e) getopt(a,b,c) #endif #ifdef GETOPT_WITH_GNU_REORDERING_EXTENTION #define EXTRAVALUE "+" /* add this to get GNU getopt to work in POSIX manner */ #else #define EXTRAVALUE #endif while((c = getopt_long (ac, av, EXTRAVALUE "vqm:ar:f:g:hVcwo:MHn:ib:F:", long_options, &index_point)) != -1) { switch (c) { case 'a': if (verbose_flag) printf (_("Adding all machines to the list\n")); { char * buf; if (asprintf(&buf, "%s/.dsh/machines.list", getenv("HOME"))<0) { fprintf (stderr, _("%s: asprintf failed\n"), PACKAGE); return 1; } machinelist = read_machinelist(machinelist, buf, DSHCONFDIR"/machines.list"); free (buf); } break; case 'g': { if ('@' == *optarg) { /* using libc call for using netgroup. */ /* +1 to skip @ */ if (verbose_flag) printf (_("Adding netgroup %s to the list\n"), optarg + 1); machinelist = read_machinenetgroup(machinelist, optarg+1); } else { /* using dsh's own method. */ char * buf1, *buf2; if (verbose_flag) printf (_("Adding group %s to the list\n"), optarg); if (asprintf(&buf1, DSHCONFDIR"/group/%s", optarg) < 0) { fprintf (stderr, _("%s: asprintf failed\n"), PACKAGE); return 1; } if (asprintf(&buf2, "%s/.dsh/group/%s", getenv("HOME"), optarg)<0) { fprintf (stderr, _("%s: asprintf failed\n"), PACKAGE); return 1; } machinelist = read_machinelist (machinelist, buf2, buf1); free(buf1);free(buf2); } } break; case 'f': if (verbose_flag) printf (_("Adding file %s to the list\n"), optarg); machinelist = read_machinelist (machinelist, optarg, NULL); break; case 'F': forklimit = atoi (optarg); wait_shell = 0; if (verbose_flag) printf (_("Setting forklimit to %i and wait_shell to %i\n"), forklimit, wait_shell); break; case 'v': if (verbose_flag) printf (_("Verbose flag on\n")); verbose_flag=1; break; case 'q': if (verbose_flag) printf (_("Verbose flag off\n")); verbose_flag=0; break; case 'M': if (verbose_flag) printf (_("Show machine names on output\n")); pipe_option |= PIPE_OPTION_OUTPUT; break; case 'H': if (verbose_flag) printf (_("Dont show machine names on output\n")); pipe_option &= ~(PIPE_OPTION_OUTPUT); break; case 'i': if (verbose_flag) printf (_("Duplicate input to all processes\n")); pipe_option |= PIPE_OPTION_INPUT; break; case 'b': if (verbose_flag) printf (_("Buffer size used for dupliation\n")); buffer_size = atoi(optarg); if (buffer_size < 1) { fprintf (stderr, _("Buffer size needs to be greater than 1\n")); return 1; } break; case 'm': if (verbose_flag) printf (_("Adding machine %s to list\n"), optarg); machinelist = split_machines_list_and_add_machines (machinelist, optarg); break; case 'n': if (verbose_flag) printf (_("Topology number set to %s\n"), optarg); num_topology = atoi (optarg); break; case 'h': print_help(); exit(1); break; case 'V': print_version(); exit(1); break; case 'r': /* specify the shell command */ if (verbose_flag) printf(_("Using %s as the remote shell\n"), optarg); remoteshell_command = strdup (optarg); break; case 'o': /* specify the shell command options */ if (verbose_flag) printf(_("Adding [%s] to shell options\n"), optarg); remoteshell_command_opt_r = lladd (remoteshell_command_opt_r, optarg); break; case 'w': /* wait shell */ if (verbose_flag) printf (_("Wait for shell to finish executing\n")); wait_shell=1; break; case 'c': /* concurrent shell */ if (verbose_flag) printf (_("Do not wait for shell to finish\n")); wait_shell=0; break; case '?': #ifndef HAVE_GETOPT_LONG /* getopt-long handles this option properly. */ if (isprint (optopt)) fprintf (stderr, _("Unkown option -%c.\n"), optopt); else fprintf (stderr, _("Unkown option character 0x%x.\n"), optopt); #endif return 1; default: if (verbose_flag) printf (_("Unhandled option\n")); break; } } if (!machinelist) { fprintf (stderr, _("%s: no machine specified\n"), PACKAGE); return 1; } { /* generate the command line for remote. */ int i; for (i=optind; i < ac; ++i) { rshcommandline_r = lladd(rshcommandline_r, av[i]); } } /* do sanity checking, and exit if it fails. */ if (sanity_checking()) return 1; if (!(pipe_option & PIPE_OPTION_INPUT)) open_devnull(); /* open /dev/null if no input pipe is required */ /* reverse the list, which is in reverse order, to make the right order */ machinelist = llreverse (machinelist); /* actually execute the code. */ return do_shell(machinelist, rshcommandline_r); }
/** * load the configuration file. */ int load_configfile(const char * dsh_conf) { dshconfig * t; dshconfig_internal * line; FILE*f = fopen (dsh_conf, "r"); char * buf_a=NULL; char * buf_b=NULL; if(verbose_flag) printf(_("Loading config file %s\n"), dsh_conf); if (f && (t = open_dshconfig(f, '='))) { for (line = t->config; line; line=line->next) { buf_a = line -> title; buf_b = line -> data; if(verbose_flag) printf(_(" Parameter %s is %s\n"), buf_a, buf_b); if (!strcmp(buf_a, "remoteshell")) { if (verbose_flag) printf(_("Using %s as the remote shell\n"), buf_b); remoteshell_command = strdup (buf_b); } else if (!strcmp(buf_a, "remoteshellopt")) { if (verbose_flag) printf(_("Adding [%s] to shell options\n"), buf_b); remoteshell_command_opt_r = lladd (remoteshell_command_opt_r, buf_b); } else if (!strcmp(buf_a, "waitshell")) { wait_shell = atoi ( buf_b ); if (verbose_flag) printf(_("Setting wait-shell to [%i]\n"), wait_shell); } else if (!strcmp(buf_a, "showmachinenames")) { pipe_option |= (atoi ( buf_b ) != 0 ); if (verbose_flag) printf(_("Setting pipe option to [%i]\n"), pipe_option); } else if (!strcmp(buf_a, "forklimit")) { forklimit = atoi ( buf_b ); wait_shell = 0; if (verbose_flag) { printf(_("Setting fork limit to [%i] and wait_shell to [%i]\n"), forklimit, wait_shell); } } else if (!strcmp(buf_a, "verbose")) { verbose_flag = atoi ( buf_b ); if (verbose_flag) printf(_("Setting verbose to [%i]\n"), verbose_flag); } else { fprintf (stderr, _("%s: unparsed configuration file line %s found in %s\n"), PACKAGE, buf_a, dsh_conf); } } free_dshconfig(t); fclose(f); } return 0; }
/** * addtohash - Adds a key to the hash. * @key: The key to add. * * Takes a key and stores it in the hash. */ void addtohash(struct stats_key *key) { ++elements; hashtable[key->keyid & HASHMASK]= lladd(hashtable[key->keyid & HASHMASK], key); }