/* * * 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 main(void) { size_t max = 100; size_t n = 20; char buf[strsiz]; size_t i; st_t st = st_init(max); for (i = 0; i < n; i++) { item_t t = newitem(randkey(), randstr(buf, strsiz)); st_insert(st, t); } st_sort(st, print); printf("\nThe item with key 11 is: "); print(st_search(st, 11)); printf("\nThe 4th smallest key is: "); print(st_select(st, 4)); st_delete(st, st_search(st, 11)); printf("\n delete the item with key 11.\n"); st_sort(st, print); /* delete all item */ while (!st_empty(st)) { item_t x = st_select(st, 0); printf("delete item: "); print(x); st_delete(st, st_select(st, 0)); } st_finalize(&st); 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; }
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; }
/* * 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; }
int main(void) { int n = 10; int i; st_t st; st = st_init(n); for (i = 0; i < n; i++) { st_insert(st, i); } for (i = 0; i < n; i++) { if (st_search(st, i)) { printf("Found key %2d\n", i); } st_delete(st, i); } printf("The size of the table is: %u\n", st_size(st)); st_finalize(&st); return 0; }
// 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; }