/* * * Outputs info about a user's groups and the groupdirs. * */ int show_groupdirs(strlist_t *grps) { strlist_iterator_t *i; char *tmpgroup, *tmppredir, *tmpallowed, *sitedir; hashtable_t *cfg = get_config(); stringtokenizer dirst, allowst; char buf[300]; int found = 0; sitedir = ht_get(cfg, PROPERTY_SITEDIR); if (!sitedir) printf(" * WARNING: '%s' not defined in config file\n", PROPERTY_SITEDIR); printf("Group Predirs Allowed sections\n"); printf("--------------- ---------------------------------------- ----------------\n"); for (i = str_iterator(grps); str_iterator_hasnext(i); ) { tmpgroup = str_iterator_next(i); tmppredir = group_get_property(tmpgroup, PROPERTY_GROUP_DIR); tmpallowed = group_get_property(tmpgroup, PROPERTY_GROUP_ALLOW); if (!(tmppredir && tmpallowed)) continue; found++; st_initialize(&dirst, tmppredir, "|"); st_initialize(&allowst, tmpallowed, "|"); strcpy(buf, tmpgroup); while (st_hasnext(&dirst) || st_hasnext(&allowst)) { tmppredir = st_next(&dirst); tmpallowed = st_next(&allowst); printf("%-15.15s %-40.40s %-15.15s\n", buf, (tmppredir?tmppredir + strlen(sitedir):""), (tmpallowed?tmpallowed:"")); strcpy(buf, ""); } st_finalize(&dirst); st_finalize(&allowst); } if (!found) printf("Hm, you arent in any groups that can pre ! \n"); return found; }
int _xferlog_parse(char *buf, xferlog_t *log) { stringtokenizer st; char *tmp; if (strlen(buf) < 25) return 0; log->xfer_date = date_parse_unix(buf); if (!log->xfer_date) return 0; st_initialize(&st, buf + 25, " "); if (st_count(&st) < 12) { free(log->xfer_date); return 0; } log->xfer_duration = atoi(st_next(&st)); log->xfer_host = strdup(st_next(&st)); log->xfer_size = atol(st_next(&st)); log->xfer_file = strdup(st_next(&st)); st_next(&st); st_next(&st); tmp = st_next(&st); log->xfer_direction = *tmp; st_next(&st); log->xfer_user = strdup(st_next(&st)); log->xfer_group = strdup(st_next(&st)); st_next(&st); log->xfer_ident = strdup(st_next(&st)); return 1; }
int main (int argc, char *argv[]) { /* read input from stdin */ char buffer[BUF_SIZE]; char c; int i = 0; while ((c = getchar ()) != EOF && i < (BUF_SIZE - 1)) buffer[i++] = c; buffer[i] = '\0'; st_initialize (); st_lexer *lexer = st_lexer_new (buffer); st_compiler_error error; st_node *node = st_parser_parse (lexer, &error); if (!node) { fprintf (stderr, "test-parser:%i: %s\n", error.line, error.message); exit (1); } printf ("-------------------\n"); st_print_method_node (node); st_node_destroy (node); return 0; }
pwdfile *_pwd_reload() { struct stat stt; char buf[500], *t, idbuf[10]; pwdfile *tmp; linefilereader_t lfr; stringtokenizer st; int i; sprintf(buf, "%s/%s", _pwd_get_etcdir(), DEFAULT_PASSWD); if (stat(buf, &stt) == -1) return pwd_userlist; if (stt.st_mtime == pwd_lastupdate) return pwd_userlist; #ifdef DEBUG printf("Debug -> passwd file loading ..\n"); #endif _pwd_finalize(pwd_userlist); if (lfr_open(&lfr, buf) < 0) return pwd_userlist; while (lfr_getline(&lfr, buf, 300) > -1) { st_initialize(&st, buf, ":"); if (st_count(&st) != 7) { st_finalize(&st); continue; } tmp = (pwdfile*)malloc(sizeof(pwdfile)); strcpy(tmp->name, st_next(&st)); strcpy(tmp->pass, st_next(&st)); strcpy(idbuf, st_next(&st)); tmp->uid = atoi(idbuf); strcpy(idbuf, st_next(&st)); tmp->gid = atoi(idbuf); strcpy(tmp->longname, st_next(&st)); strcpy(tmp->homedir, st_next(&st)); strcpy(tmp->shell, st_next(&st)); tmp->next = pwd_userlist; pwd_userlist = tmp; } lfr_close(&lfr); pwd_lastupdate = stt.st_mtime; return pwd_userlist; }
/** * Allocates a new search_table_t. * Use st_free() to free it. */ search_table_t * st_create(void) { search_table_t *table; WALLOC0(table); table->magic = SEARCH_TABLE_MAGIC; st_initialize(table); st_recreate(table); return table; }
/* * Returns section name of a 'requested' section, if its allowed * for 'group'. */ char * section_find_by_name(char *group, char *requested) { char *tmpsecdir, *tmpallow, *tmpreq; stringtokenizer st; tmpreq = requested; // if no requested, then try to set it to the 'default' section. if (!tmpreq) { tmpreq = group_get_property(group, PROPERTY_GROUP_DEFSEC); if (!tmpreq) { printf(" * Hm, section not specified, and no default section for group '%s'\n", group); printf("%s\n", USAGE); return 0; } } st_initialize(&st, group_get_property(group, PROPERTY_GROUP_ALLOW), "|"); while (st_hasnext(&st)) { tmpallow = strdup(st_next(&st)); if (!strcasecmp(tmpreq, tmpallow)) break; free(tmpallow); tmpallow = 0; } st_finalize(&st); if (!tmpallow) return 0; // do basic check if section is in the config. tmpsecdir = section_get_property(tmpallow, PROPERTY_SECTION_DIR); if (!tmpsecdir) { printf(" * Hm, you are allowed to pre in section '%s' but the section is not.\n configured. Bug siteop to fix his pre configuration please! :)\n", tmpreq); return 0; } return tmpallow; }
/* * Gets configuration properties in the a|b|c|d format as a strlist. */ strlist_t * config_get_split_property(char *prop) { hashtable_t *cfg = get_config(); char *tmp; stringtokenizer st; strlist_t *l = 0; tmp = ht_get(cfg, prop); st_initialize(&st, tmp, "|"); while (st_hasnext(&st)) { tmp = st_next(&st); l = str_add(l, tmp); } return l; }
CAMLprim value caml_thread_initialize(value unit) /* ML */ { /* Protect against repeated initialization (PR#1325) */ if (curr_thread != NULL) return Val_unit; /* OS-specific initialization */ st_initialize(); /* Initialize and acquire the master lock */ st_masterlock_init(&caml_master_lock); /* Initialize the keys */ st_tls_newkey(&thread_descriptor_key); st_tls_newkey(&last_channel_locked_key); /* Set up a thread info block for the current thread */ curr_thread = (caml_thread_t) stat_alloc(sizeof(struct caml_thread_struct)); curr_thread->descr = caml_thread_new_descriptor(Val_unit); curr_thread->next = curr_thread; curr_thread->prev = curr_thread; all_threads = curr_thread; curr_thread->backtrace_last_exn = Val_unit; #ifdef NATIVE_CODE curr_thread->exit_buf = &caml_termination_jmpbuf; #endif /* The stack-related fields will be filled in at the next enter_blocking_section */ /* Associate the thread descriptor with the thread */ st_tls_set(thread_descriptor_key, (void *) curr_thread); /* Set up the hooks */ prev_scan_roots_hook = scan_roots_hook; scan_roots_hook = caml_thread_scan_roots; enter_blocking_section_hook = caml_thread_enter_blocking_section; leave_blocking_section_hook = caml_thread_leave_blocking_section; try_leave_blocking_section_hook = caml_thread_try_leave_blocking_section; #ifdef NATIVE_CODE caml_termination_hook = st_thread_exit; #endif caml_channel_mutex_free = caml_io_mutex_free; caml_channel_mutex_lock = caml_io_mutex_lock; caml_channel_mutex_unlock = caml_io_mutex_unlock; caml_channel_mutex_unlock_exn = caml_io_mutex_unlock_exn; prev_stack_usage_hook = caml_stack_usage_hook; caml_stack_usage_hook = caml_thread_stack_usage; /* Set up fork() to reinitialize the thread machinery in the child (PR#4577) */ st_atfork(caml_thread_reinitialize); return Val_unit; }
grpfile_t *_pwd_grpreload() { linefilereader_t lfr; char buf[300], gidbuf[30]; stringtokenizer st; grpfile_t *tmp = 0; if (pwd_grouplist) return pwd_grouplist; sprintf(buf, "%s/%s", _pwd_get_etcdir(), DEFAULT_GROUP); if (lfr_open(&lfr, buf) < 0) return 0; while (lfr_getline(&lfr, buf, 300) > 0) { st_initialize(&st, buf, ":"); if (st_count(&st) < 3) { st_finalize(&st); continue; } tmp = (grpfile_t*)malloc(sizeof(grpfile_t)); strcpy(tmp->group, st_next(&st)); strcpy(tmp->pass, st_next(&st)); strcpy(gidbuf, st_next(&st)); if (st_hasnext(&st)) tmp->users = strdup(st_next(&st)); else tmp->users = 0; tmp->gid = atoi(gidbuf); tmp->next = pwd_grouplist; pwd_grouplist = tmp; st_finalize(&st); } lfr_close(&lfr); return pwd_grouplist; }
void generate_statistics(RBTree *tree) { DictionaryStatistics stats; char path[80]; if ( tree == NULL ) { printf("No es pot generar les estadístiques d'un arbre buit.\n"); return; } printf("Nom de la imatge amb l'histograma: "); scanf("%s", path); flush(); st_initialize(&stats); st_extract_statistics(tree, &stats); st_dump_statistics(&stats, path); st_free(&stats); }
int pre_do_modules(filelist_t *files, char *path, char *argv[], struct subdir_list *subdirs) { hashtable_t *cfg, *env; stringtokenizer st; char *tmp; tmp = ht_get(get_config(), PROPERTY_MODULES); // no modules in config, return if (!tmp) return; st_initialize(&st, tmp, "|"); while (st_hasnext(&st)) { tmp = st_next(&st); pre_do_module(tmp, files, path, argv, subdirs); } }
// Tue Jan 1 16:06:20 2002 date_t * date_parse_unix(char *d) { stringtokenizer st, mst; char *buf, *tmp, *off; int i; date_t *da; // make string tokenizable buf = malloc(strlen(d) + 1); off = buf; *buf = 0; tmp = d; while (*tmp) { if (*tmp == ' ') { *(buf++) = ' '; tmp++; while (*tmp == ' ') tmp++; } else *(buf++) = *(tmp++); } *buf = 0; st_initialize(&st, off, " "); free(off); if (st_count(&st) < 5) { st_finalize(&st); return 0; } da = malloc(sizeof(date_t)); // wday. tmp = st_next(&st); da->wday = -1; for (i = 0; i < 7; i++) { if (!strcmp(tmp, DATE_MDAY[i])) da->wday = i; } // mon tmp = st_next(&st); da->mon = -1; for (i = 0; i < 12; i++) { if (!strcmp(tmp, DATE_MON[i])) da->mon = i; } // sanity check if ((da->mon == -1) || (da->wday == -1)) { free(da); st_finalize(&st); return 0; } // mday. tmp = st_next(&st); da->mday = atoi(tmp); // hour:min:sec tmp = st_next(&st); st_initialize(&mst, tmp, ":"); if (st_count(&mst) != 3) { st_finalize(&mst); st_finalize(&st); free(da); return 0; } da->hour = atoi(st_next(&mst)); da->min = atoi(st_next(&mst)); da->sec = atoi(st_next(&mst)); st_finalize(&mst); // year tmp = st_next(&st); da->year = atoi(tmp); st_finalize(&st); return da; }