void XkbSetRulesDflts(XkbRMLVOSet *rmlvo) { if (rmlvo->rules) { free(XkbRulesDflt); XkbRulesDflt= Xstrdup(rmlvo->rules); } if (rmlvo->model) { free(XkbModelDflt); XkbModelDflt= Xstrdup(rmlvo->model); } if (rmlvo->layout) { free(XkbLayoutDflt); XkbLayoutDflt= Xstrdup(rmlvo->layout); } if (rmlvo->variant) { free(XkbVariantDflt); XkbVariantDflt= Xstrdup(rmlvo->variant); } if (rmlvo->options) { free(XkbOptionsDflt); XkbOptionsDflt= Xstrdup(rmlvo->options); } return; }
static void Add_Stats (S_Type typ, char *name, char *fmt,...) { char buf[1024]; va_list args; va_start (args, fmt); vsprintf (buf, fmt, args); if (Stats) Stats = Xrealloc (Stats, (++NumStats) * sizeof (*Stats)); else Stats = Xmalloc ((++NumStats) * sizeof (*Stats)); Stats[NumStats - 1].typ = typ; Stats[NumStats - 1].name = Xstrdup (name); Stats[NumStats - 1].text = Xstrdup (buf); }
// 0: success, <0: failure int L_CreateState(L_State *estate, const char *name, void (*StateSetupFunc)(lua_State *)) { lua_State *L; estate->name = Xstrdup(name); L = estate->L = luaL_newstate(); if (!estate->L) { DO_FREE_AND_NULL(estate->name); return -2; } luaL_openlibs(L); L_SetupDebugTraceback(L); if (StateSetupFunc) StateSetupFunc(L); if (lua_gettop(L)==0) L_PushDebugTraceback(L); // Otherwise, it is assumed that StateSetupFunc pushed a custom traceback // function onto the stack. Bassert(lua_gettop(L)==1); return 0; }
static void LoadGameList(void) { for (size_t i = 0; i < ARRAY_SIZE(internalgrpfiles); i++) { grpinfo_t * const fg = (grpinfo_t *)Xcalloc(1, sizeof(grpinfo_t)); fg->name = Xstrdup(internalgrpfiles[i].name); fg->crcval = internalgrpfiles[i].crcval; fg->size = internalgrpfiles[i].size; fg->game = internalgrpfiles[i].game; fg->dependency = internalgrpfiles[i].dependency; if (internalgrpfiles[i].scriptname) fg->scriptname = dup_filename(internalgrpfiles[i].scriptname); if (internalgrpfiles[i].defname) fg->defname = dup_filename(internalgrpfiles[i].defname); fg->postprocessing = internalgrpfiles[i].postprocessing; fg->next = listgrps; listgrps = fg; } CACHE1D_FIND_REC * const srch = klistpath("/", "*.grpinfo", CACHE1D_FIND_FILE); for (CACHE1D_FIND_REC *sidx = srch; sidx; sidx = sidx->next) LoadList(sidx->name); klistfree(srch); }
static int mavis_init_in(mavis_ctx * mcx) { int i; DebugIn(DEBUG_MAVIS); mcx->lastdump = mcx->startup_time = time(NULL); if (!mcx->path) logmsg("Warning: %s: module lacks path definition", MAVIS_name); else if (!mcx->argv[0]) { mcx->argv[0] = Xstrdup(basename(mcx->path)); mcx->argv[1] = NULL; } if (mcx->child_min > mcx->child_max) mcx->child_min = mcx->child_max; if (!mcx->io_context_parent) mcx->io_context_local = mcx->io = io_init(); mcx->cx = Xcalloc(mcx->child_max, sizeof(struct context *)); mcx->cx_stat = Xcalloc(mcx->child_max, sizeof(struct context_stat)); for (i = 0; i < mcx->child_min; i++) fork_child(mcx, i); mcx->backlog_serial = RB_tree_new(compare_serial, NULL); mcx->backlog_app_ctx = RB_tree_new(compare_app_ctx, NULL); mcx->backlog_fifo = RB_tree_new(compare_fifo, free_payload); mcx->outgoing = RB_tree_new(compare_app_ctx, free_payload); mcx->junkcontexts = RB_tree_new(compare_ctx, free_context); DebugOut(DEBUG_MAVIS); return MAVIS_INIT_OK; }
void GetPostProc (char *line) { char *start, *finish; if (post_proc) { Xfree (post_proc); post_proc = NULL; } start = strchr (line, '\"'); finish = strrchr (line, '\"'); if (start != finish) { /* found a pattern */ *finish = '\0'; post_proc = Xstrdup (start + 1); strcpy (start, finish + 1); if (BooleanEnv (GetEnv ("verbatim"), 1) == 0) { char *s; s = re_comp (post_proc); if (s != NULL) /* no error msg returned */ { Xfree (post_proc); post_proc = NULL; } } } else if (start != NULL) { /* found a single speech mark. Delete It. */ strcpy (start, start + 1); } }
File * Fopen (char *name, char *mode, unsigned long magic) { FILE *f; File *F; unsigned long m; if (!(f = fopen (name, mode))) return (NULL); if (magic) switch (*mode) { case 'r': fread ((char *) &m, sizeof (m), 1, f); if (m != magic) { fclose (f); return (NULL); } break; case 'w': fwrite ((char *) &magic, sizeof (magic), 1, f); } if (!(F = Xmalloc (sizeof (File)))) { fclose (f); return (NULL); } F->pathname = Xstrdup (name); F->name = strrchr (F->pathname, '/'); F->name = F->name ? F->name + 1 : F->pathname; F->f = f; F->Current.NumSeeks = F->Current.NumReads = F->Current.NumBytes = 0; F->Cumulative = F->Current; return (F); }
static void XkbSetRulesUsed(XkbRMLVOSet *rmlvo) { free(XkbRulesUsed); XkbRulesUsed= (rmlvo->rules?Xstrdup(rmlvo->rules):NULL); free(XkbModelUsed); XkbModelUsed= (rmlvo->model?Xstrdup(rmlvo->model):NULL); free(XkbLayoutUsed); XkbLayoutUsed= (rmlvo->layout?Xstrdup(rmlvo->layout):NULL); free(XkbVariantUsed); XkbVariantUsed= (rmlvo->variant?Xstrdup(rmlvo->variant):NULL); free(XkbOptionsUsed); XkbOptionsUsed= (rmlvo->options?Xstrdup(rmlvo->options):NULL); if (XkbWantRulesProp) QueueWorkProc(XkbWriteRulesProp,NULL,NULL); return; }
void output_terminator (FILE * out) { char *terminator = Xstrdup (GetDefEnv ("terminator", "")); de_escape_string (terminator); fputs (terminator, out); Xfree (terminator); }
char *authgetpass(VOID_A) { char *cp; #ifdef FD cp = inputpass(); #else /* !FD */ # ifdef NOGETPASS VOID_C Xfputs("Password:"******"Password:"))) cp = vnullstr; cp = Xstrdup(cp); # endif #endif /* !FD */ return(cp); }
void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.cfg { int32_t i; BFILE *fp; char *ptr = Xstrdup(setupfilename); char tempbuf[128]; if (!Bstrcmp(setupfilename, SETUPFILENAME)) Bsprintf(tempbuf, "settings.cfg"); else Bsprintf(tempbuf, "%s_settings.cfg", strtok(ptr, ".")); fp = Bfopen(tempbuf, "wt"); if (fp) { Bfprintf(fp,"// this file is automatically generated by EDuke32\n"); Bfprintf(fp,"// these settings take precedence over your main cfg file\n"); Bfprintf(fp,"// do not modify if you lack common sense\n"); Bfprintf(fp,"unbindall\n"); for (i=0; i<MAXBOUNDKEYS; i++) if (CONTROL_KeyIsBound(i)) Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_KeyBinds[i].key, CONTROL_KeyBinds[i].repeat?"":" norepeat",CONTROL_KeyBinds[i].cmdstr); for (i=0; i<MAXMOUSEBUTTONS; i++) if (CONTROL_MouseIsBound(i)) Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_MouseBinds[i].key, CONTROL_MouseBinds[i].repeat?"":" norepeat",CONTROL_MouseBinds[i].cmdstr); OSD_WriteAliases(fp); if (g_crosshairSum && g_crosshairSum != DefaultCrosshairColors.r+(DefaultCrosshairColors.g<<1)+(DefaultCrosshairColors.b<<2)) Bfprintf(fp, "crosshaircolor %d %d %d\n", CrosshairColors.r, CrosshairColors.g, CrosshairColors.b); OSD_WriteCvars(fp); Bfclose(fp); if (!Bstrcmp(setupfilename, SETUPFILENAME)) OSD_Printf("Wrote settings.cfg\n"); else OSD_Printf("Wrote %s_settings.cfg\n",ptr); Bfree(ptr); return; } if (!Bstrcmp(setupfilename, SETUPFILENAME)) OSD_Printf("Error writing settings.cfg: %s\n", strerror(errno)); else OSD_Printf("Error writing %s_settings.cfg: %s\n",ptr,strerror(errno)); Bfree(ptr); }
static void Apply(char *src, char **dst) { if (src) { if (*src == '+' || *src == '!') { *dst = _Concat(*dst, src); } else { if (*dst == NULL) *dst = Xstrdup(src); } } }
static int mavis_init_in(mavis_ctx * mcx) { DebugIn(DEBUG_MAVIS); if (!mcx->initialized) { mcx->initialized++; if (!mcx->service) mcx->service = Xstrdup("mavis"); if (geteuid()) logmsg("Warning: PAM module may require root privileges"); } DebugOut(DEBUG_MAVIS); return MAVIS_INIT_OK; }
char *ostype() { if (!os) { char b[80], *t; struct utsname buf; uname(&buf); snprintf(b, sizeof(b), "%s-%s-%s", buf.sysname, buf.release, buf.machine); for (t = b; *t; t++) *t = tolower((int) *t); os = Xstrdup(b); } return os; }
void setup_sig_segv(char *coredump_dir, char *gcore_cmd, char *debug_cmd) { struct sigaction sa; if (coredump_dir) coredumpdir = Xstrdup(coredump_dir); if (gcore_cmd) gcorecmd = Xstrdup(gcore_cmd); if (debug_cmd) gdbcmd = Xstrdup(debug_cmd); sigaction(SIGSEGV, NULL, &sa); #ifdef SA_SIGINFO coredump_handler = sa.sa_sigaction; sa.sa_sigaction = catchsegv; sa.sa_flags |= SA_SIGINFO; #else coredump_handler = sa.sa_handler; sa.sa_handler = catchsegv; #endif if (!gcorecmd) { #ifdef SA_NOMASK sa.sa_flags |= SA_NOMASK; #endif /* SA_NOMASK */ #ifdef SA_NODEFER sa.sa_flags |= SA_NODEFER; #endif /* SA_NODEFER */ ; } #ifdef EXC_BAD_INSTRUCTION sigaction(EXC_BAD_INSTRUCTION, &sa, NULL); #endif #ifdef SIGBUS sigaction(SIGBUS, &sa, NULL); #endif sigaction(SIGSEGV, &sa, NULL); }
/* * The conversation function. Alas, OSF-RFC 86.0 doesn't go into * much detail, so this is largely based upon linux-pam documentation. */ static int pam_conv(int num_msg, PAM_CONV_ARG2_TYPE ** msg, struct pam_response **response, void *appdata_ptr) { int count; struct pam_response *reply = Xcalloc(num_msg, sizeof(struct pam_response)); for (count = 0; count < num_msg; count++) switch (msg[count]->msg_style) { case PAM_PROMPT_ECHO_ON: reply[count].resp = Xstrdup(((struct appdata *) appdata_ptr)->user); break; case PAM_PROMPT_ECHO_OFF: reply[count].resp = Xstrdup(((struct appdata *) appdata_ptr)->pass); case PAM_TEXT_INFO: break; default: while (--count > -1) Xfree(&reply[count].resp); Xfree(&reply); return PAM_CONV_ERR; /* won't happen */ } *response = reply; return PAM_SUCCESS; }
static int mavis_init_in(mavis_ctx * mcx) { DebugIn(DEBUG_MAVIS); if (!mcx->initialized) { mcx->initialized++; if (mcx->require_valid_shell && !mcx->shellpath) mcx->shellpath = Xstrdup("/etc/shells"); if (mcx->honour_ftpusers && !mcx->ftpuserspath) mcx->ftpuserspath = Xstrdup("/etc/ftpusers"); if (mcx->lookup_sslusers && !mcx->ssluserspath) mcx->ssluserspath = Xstrdup("/etc/ssl.users"); if (geteuid()) logmsg("Warning: SYSTEM module requires root privileges"); #ifdef NOTHING // WITH_LIBCRYPT /* We need to make sure to get crypt(3) from libcrypt.so, not from * the OpenSSL libcrypto.so library, which may be already loaded. * Reason for that is that the libcrypt version may support additional * encryption algorithms, e.g. MD5. */ mcx->libcrypt = dlopen("libcrypt.so", RTLD_LAZY); if (mcx->libcrypt) { mcx->crypt = (char *(*)(const char *, const char *)) dlsym(mcx->libcrypt, DLSYM_PREFIX "crypt"); if (!mcx->crypt) { dlclose(mcx->libcrypt); mcx->libcrypt = NULL; mcx->crypt = crypt; } } if (!mcx->crypt) #endif mcx->crypt = crypt; } DebugOut(DEBUG_MAVIS); return MAVIS_INIT_OK; }
int32_t CONFIG_FunctionNameToNum(const char *func) { int32_t i; if (!func) return -1; i = hash_find(&h_gamefuncs,func); if (i < 0) { char *str = Bstrtolower(Xstrdup(func)); i = hash_find(&h_gamefuncs,str); Bfree(str); return i; } return i; }
void G_AddClipMap(const char *buffer) { g_clipMapFiles = (char **) Xrealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *)); g_clipMapFiles[g_clipMapFilesNum] = Xstrdup(buffer); ++g_clipMapFilesNum; }
void G_AddDefModule(const char *buffer) { g_defModules = (char **) Xrealloc (g_defModules, (g_defModulesNum+1) * sizeof(char *)); g_defModules[g_defModulesNum] = Xstrdup(buffer); ++g_defModulesNum; }
static Bool CheckLine(InputLine * line, RemapSpec * remap, XkbRF_RulePtr rule, XkbRF_GroupPtr group) { char *str, *tok; register int nread, i; FileSpec tmp; _Xstrtokparams strtok_buf; Bool append = FALSE; if (line->line[0] == '!') { if (line->line[1] == '$' || (line->line[1] == ' ' && line->line[2] == '$')) { char *gname = strchr(line->line, '$'); char *words = strchr(gname, ' '); if (!words) return FALSE; *words++ = '\0'; for (; *words; words++) { if (*words != '=' && *words != ' ') break; } if (*words == '\0') return FALSE; group->name = Xstrdup(gname); group->words = Xstrdup(words); for (i = 1, words = group->words; *words; words++) { if (*words == ' ') { *words++ = '\0'; i++; } } group->number = i; return TRUE; } else { SetUpRemap(line, remap); return FALSE; } } if (remap->num_remap == 0) { DebugF("Must have a mapping before first line of data\n"); DebugF("Illegal line of data ignored\n"); return FALSE; } memset((char *) &tmp, 0, sizeof(FileSpec)); str = line->line; for (nread = 0; (tok = _XStrtok(str, " ", strtok_buf)) != NULL; nread++) { str = NULL; if (strcmp(tok, "=") == 0) { nread--; continue; } if (nread > remap->num_remap) { DebugF("Too many words on a line\n"); DebugF("Extra word \"%s\" ignored\n", tok); continue; } tmp.name[remap->remap[nread].word] = tok; if (*tok == '+' || *tok == '|') append = TRUE; } if (nread < remap->num_remap) { DebugF("Too few words on a line: %s\n", line->line); DebugF("line ignored\n"); return FALSE; } rule->flags = 0; rule->number = remap->number; if (tmp.name[OPTION]) rule->flags |= XkbRF_Option; else if (append) rule->flags |= XkbRF_Append; else rule->flags |= XkbRF_Normal; rule->model = Xstrdup(tmp.name[MODEL]); rule->layout = Xstrdup(tmp.name[LAYOUT]); rule->variant = Xstrdup(tmp.name[VARIANT]); rule->option = Xstrdup(tmp.name[OPTION]); rule->keycodes = Xstrdup(tmp.name[KEYCODES]); rule->symbols = Xstrdup(tmp.name[SYMBOLS]); rule->types = Xstrdup(tmp.name[TYPES]); rule->compat = Xstrdup(tmp.name[COMPAT]); rule->geometry = Xstrdup(tmp.name[GEOMETRY]); rule->layout_num = rule->variant_num = 0; for (i = 0; i < nread; i++) { if (remap->remap[i].index) { if (remap->remap[i].word == LAYOUT) rule->layout_num = remap->remap[i].index; if (remap->remap[i].word == VARIANT) rule->variant_num = remap->remap[i].index; } } return TRUE; }
static void LoadList(const char * filename) { scriptfile *script = scriptfile_fromfile(filename); if (!script) return; scriptfile_addsymbolvalue("GAMEFLAG_DUKE", GAMEFLAG_DUKE); scriptfile_addsymbolvalue("GAMEFLAG_ADDON", GAMEFLAG_DUKE|GAMEFLAG_ADDON); scriptfile_addsymbolvalue("GAMEFLAG_NAM", GAMEFLAG_NAM); scriptfile_addsymbolvalue("GAMEFLAG_NAPALM", GAMEFLAG_NAM|GAMEFLAG_NAPALM); scriptfile_addsymbolvalue("GAMEFLAG_WW2GI", GAMEFLAG_NAM|GAMEFLAG_WW2GI); scriptfile_addsymbolvalue("DUKE15_CRC", DUKE15_CRC); scriptfile_addsymbolvalue("DUKEPP_CRC", DUKEPP_CRC); scriptfile_addsymbolvalue("DUKE13_CRC", DUKE13_CRC); scriptfile_addsymbolvalue("DUKEDC13_CRC", DUKEDC13_CRC); scriptfile_addsymbolvalue("DUKEDCPP_CRC", DUKEDCPP_CRC); scriptfile_addsymbolvalue("DUKEDC_CRC", DUKEDC_CRC); scriptfile_addsymbolvalue("VACA13_CRC", VACA13_CRC); scriptfile_addsymbolvalue("VACAPP_CRC", VACAPP_CRC); scriptfile_addsymbolvalue("VACA15_CRC", VACA15_CRC); scriptfile_addsymbolvalue("DUKECB_CRC", DUKECB_CRC); scriptfile_addsymbolvalue("DUKENW_CRC", DUKENW_CRC); scriptfile_addsymbolvalue("DZ2_13_CRC", DZ2_13_CRC); scriptfile_addsymbolvalue("DZ2_PP_CRC", DZ2_PP_CRC); scriptfile_addsymbolvalue("NAM_CRC", NAM_CRC); scriptfile_addsymbolvalue("NAPALM_CRC", NAPALM_CRC); scriptfile_addsymbolvalue("WW2GI_CRC", WW2GI_CRC); while (!scriptfile_eof(script)) { enum { T_GRPINFO, T_GAMENAME, T_CRC, T_SIZE, T_DEPCRC, T_SCRIPTNAME, T_DEFNAME, T_FLAGS, }; static const tokenlist profiletokens[] = { { "grpinfo", T_GRPINFO }, }; int32_t token = getatoken(script,profiletokens,ARRAY_SIZE(profiletokens)); switch (token) { case T_GRPINFO: { int32_t gsize = 0, gcrcval = 0, gflags = GAMEFLAG_DUKE, gdepcrc = DUKE15_CRC; char *gname = NULL, *gscript = NULL, *gdef = NULL; char *grpend = NULL; static const tokenlist grpinfotokens[] = { { "name", T_GAMENAME }, { "scriptname", T_SCRIPTNAME }, { "defname", T_DEFNAME }, { "crc", T_CRC }, { "dependency", T_DEPCRC }, { "size", T_SIZE }, { "flags", T_FLAGS }, }; if (scriptfile_getbraces(script,&grpend)) break; while (script->textptr < grpend) { int32_t token = getatoken(script,grpinfotokens,ARRAY_SIZE(grpinfotokens)); switch (token) { case T_GAMENAME: scriptfile_getstring(script,&gname); break; case T_SCRIPTNAME: scriptfile_getstring(script,&gscript); break; case T_DEFNAME: scriptfile_getstring(script,&gdef); break; case T_FLAGS: scriptfile_getsymbol(script,&gflags); gflags &= GAMEFLAGMASK; break; case T_DEPCRC: scriptfile_getsymbol(script,&gdepcrc); break; case T_CRC: scriptfile_getsymbol(script,&gcrcval); break; case T_SIZE: scriptfile_getnumber(script,&gsize); break; default: break; } grpinfo_t * const fg = (grpinfo_t *)Xcalloc(1, sizeof(grpinfo_t)); fg->next = listgrps; listgrps = fg; if (gname) fg->name = Xstrdup(gname); fg->size = gsize; fg->crcval = gcrcval; fg->dependency = gdepcrc; fg->game = gflags; if (gscript) fg->scriptname = dup_filename(gscript); if (gdef) fg->defname = dup_filename(gdef); } break; } default: break; } } scriptfile_close(script); scriptfile_clearsymbols(); }
static Bool MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs) { memset((char *) mdefs, 0, sizeof(XkbRF_MultiDefsRec)); mdefs->model = defs->model; mdefs->options = Xstrdup(defs->options); if (mdefs->options) squeeze_spaces(mdefs->options); if (defs->layout) { if (!strchr(defs->layout, ',')) { mdefs->layout[0] = defs->layout; } else { char *p; int i; mdefs->layout[1] = Xstrdup(defs->layout); if (mdefs->layout[1] == NULL) return FALSE; squeeze_spaces(mdefs->layout[1]); p = mdefs->layout[1]; for (i = 2; i <= XkbNumKbdGroups; i++) { if ((p = strchr(p, ','))) { *p++ = '\0'; mdefs->layout[i] = p; } else { break; } } if (p && (p = strchr(p, ','))) *p = '\0'; } } if (defs->variant) { if (!strchr(defs->variant, ',')) { mdefs->variant[0] = defs->variant; } else { char *p; int i; mdefs->variant[1] = Xstrdup(defs->variant); if (mdefs->variant[1] == NULL) return FALSE; squeeze_spaces(mdefs->variant[1]); p = mdefs->variant[1]; for (i = 2; i <= XkbNumKbdGroups; i++) { if ((p = strchr(p, ','))) { *p++ = '\0'; mdefs->variant[i] = p; } else { break; } } if (p && (p = strchr(p, ','))) *p = '\0'; } } return TRUE; }
static void read_psffm(char *file) { int fd; static char msgfile[MAXPATHLEN]; wchar_t *linebufptr, *p; char *bufptr = 0; int quotefound; /* double quote was seen */ int inmsgid = 0; /* indicates "msgid" was seen */ int inmsgstr = 0; /* indicates "msgstr" was seen */ int indomain = 0; /* indicates "domain" was seen */ wchar_t wc; char mb; int n; char token_found; /* Boolean value */ unsigned int bufptr_index = 0; /* current index of bufptr */ char *mbuf, *addr; size_t fsize, ln_size, ll; wchar_t *linebufhead = NULL; struct stat64 statbuf; char *filename; /* * For each po file to be read, * 1) set domain to default and * 2) set linenumer to 0. */ (void) strcpy(gcurrent_domain, DEFAULT_DOMAIN); linenum = 0; if (!inputdir) { filename = Xstrdup(file); } else { size_t dirlen, filelen, len; dirlen = strlen(inputdir); filelen = strlen(file); len = dirlen + 1 + filelen + 1; filename = (char *)Xmalloc(len); (void) memcpy(filename, inputdir, dirlen); *(filename + dirlen) = '/'; (void) memcpy(filename + dirlen + 1, file, filelen); *(filename + dirlen + 1 + filelen) = '\0'; } fd = open(filename, O_RDONLY); if (fd == -1) { error(gettext(ERR_OPEN_FAILED), filename); /* NOTREACHED */ } if (fstat64(fd, &statbuf) == -1) { error(gettext(ERR_STAT_FAILED), filename); /* NOTREACHED */ } fsize = (size_t)statbuf.st_size; if (fsize == 0) { /* * The size of the specified po file is 0. * In Solaris 8 and earlier, msgfmt was silent * for the null po file. So, just returns * without generating an error message. */ (void) close(fd); free(filename); return; } addr = mmap(NULL, fsize, PROT_READ, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { error(gettext(ERR_MMAP_FAILED), filename); /* NOTREACHED */ } (void) close(fd); if (!sun_p) check_gnu(addr, fsize); mbuf = addr; for (;;) { if (linebufhead) { free(linebufhead); linebufhead = NULL; } ln_size = _mbsntowcs(&linebufhead, &mbuf, &fsize); if (ln_size == (size_t)-1) { error(gettext(ERR_READ_FAILED), filename); /* NOTREACHED */ } else if (ln_size == 0) { break; /* End of File. */ } linenum++; linebufptr = linebufhead; quotefound = 0; switch (*linebufptr) { case L'#': /* comment */ case L'\n': /* empty line */ continue; case L'\"': /* multiple lines of msgid and msgstr */ quotefound = 1; break; } /* * Process MSGID Tokens. */ token_found = (wcsncmp(MSGID_TOKEN, linebufptr, MSGID_LEN) == 0) ? 1 : 0; if (token_found || (quotefound && inmsgid)) { if (token_found) { if (!CK_NXT_CH(linebufptr, MSGID_LEN+1)) { diag(gettext(ERR_NOSPC), linenum); error(gettext(ERR_EXITING)); /* NOTREACHED */ } } if (inmsgid && !quotefound) { warning(gettext(WARN_NO_MSGSTR), msgid_linenum); continue; } if (inmsgstr) { sortit(gmsgid, gmsgstr); (void) memset(gmsgid, 0, gmsgid_size); (void) memset(gmsgstr, 0, gmsgstr_size); } if (inmsgid) { /* multiple lines of msgid */ /* cancel the previous null termination */ bufptr_index--; } else { /* * The first line of msgid. * Save linenum of msgid to be used when * printing warning or error message. */ msgid_linenum = linenum; p = linebufptr; linebufptr = consume_whitespace( linebufptr + MSGID_LEN); ln_size -= linebufptr - p; bufptr = gmsgid; bufptr_index = 0; } inmsgid = 1; inmsgstr = 0; indomain = 0; goto load_buffer; } /* * Process MSGSTR Tokens. */ token_found = (wcsncmp(MSGSTR_TOKEN, linebufptr, MSGSTR_LEN) == 0) ? 1 : 0; if (token_found || (quotefound && inmsgstr)) { if (token_found) { if (!CK_NXT_CH(linebufptr, MSGSTR_LEN+1)) { diag(gettext(ERR_NOSPC), linenum); error(gettext(ERR_EXITING)); /* NOTREACHED */ } } if (inmsgstr && !quotefound) { warning(gettext(WARN_NO_MSGID), msgstr_linenum); continue; } if (inmsgstr) { /* multiple lines of msgstr */ /* cancel the previous null termination */ bufptr_index--; } else { /* * The first line of msgstr. * Save linenum of msgid to be used when * printing warning or error message. */ msgstr_linenum = linenum; p = linebufptr; linebufptr = consume_whitespace( linebufptr + MSGSTR_LEN); ln_size -= linebufptr - p; bufptr = gmsgstr; bufptr_index = 0; } inmsgstr = 1; inmsgid = 0; indomain = 0; goto load_buffer; } /* * Process DOMAIN Tokens. * Add message id and message string to sorted list * if msgstr was processed last time. */ token_found = (wcsncmp(DOMAIN_TOKEN, linebufptr, DOMAIN_LEN) == 0) ? 1 : 0; if ((token_found) || (quotefound && indomain)) { if (token_found) { if (!CK_NXT_CH(linebufptr, DOMAIN_LEN+1)) { diag(gettext(ERR_NOSPC), linenum); error(gettext(ERR_EXITING)); /* NOTREACHED */ } } /* * process msgid and msgstr pair for previous domain */ if (inmsgstr) { sortit(gmsgid, gmsgstr); } /* refresh msgid and msgstr buffer */ if (inmsgstr || inmsgid) { (void) memset(gmsgid, 0, gmsgid_size); (void) memset(gmsgstr, 0, gmsgstr_size); } if (indomain) { /* multiple lines of domain */ /* cancel the previous null termination */ bufptr_index--; } else { p = linebufptr; linebufptr = consume_whitespace( linebufptr + DOMAIN_LEN); (void) memset(gcurrent_domain, 0, sizeof (gcurrent_domain)); ln_size -= linebufptr - p; bufptr = gcurrent_domain; bufptr_index = 0; } indomain = 1; inmsgid = 0; inmsgstr = 0; } /* if */ load_buffer: /* * Now, fill up the buffer pointed by bufptr. * At this point bufptr should point to one of * msgid, msgptr, or current_domain. * Otherwise, the entire line is ignored. */ if (!bufptr) { warning(gettext(WARN_SYNTAX_ERR), linenum); continue; } if (*linebufptr++ != L'\"') { warning(gettext(WARN_MISSING_QUOTE), linenum); --linebufptr; } quotefound = 0; /* * If there is not enough space in the buffer, * increase buffer by ln_size by realloc. */ ll = ln_size * mbcurmax; if (bufptr == gmsgid) { if (gmsgid_size < (bufptr_index + ll)) { gmsgid = (char *)Xrealloc(gmsgid, bufptr_index + ll); bufptr = gmsgid; gmsgid_size = bufptr_index + ll; } } else if (bufptr == gmsgstr) { if (gmsgstr_size < (bufptr_index + ll)) { gmsgstr = (char *)Xrealloc(gmsgstr, bufptr_index + ll); bufptr = gmsgstr; gmsgstr_size = bufptr_index + ll; } } while (wc = *linebufptr++) { switch (wc) { case L'\n': if (!quotefound) { warning(gettext(WARN_MISSING_QUOTE_AT_EOL), linenum); } break; case L'\"': quotefound = 1; break; case L'\\': if ((mb = expand_meta(&linebufptr)) != NULL) bufptr[bufptr_index++] = mb; break; default: if ((n = wctomb(&bufptr[bufptr_index], wc)) > 0) bufptr_index += n; } /* switch */ if (quotefound) { /* * Check if any remaining characters * after closing quote. */ linebufptr = consume_whitespace(linebufptr); if (*linebufptr != L'\n') { warning(gettext(WARN_INVALID_STRING), linenum); } break; } } /* while */ bufptr[bufptr_index++] = '\0'; (void) strcpy(msgfile, gcurrent_domain); (void) strcat(msgfile, ".mo"); } /* for(;;) */ if (inmsgstr) { sortit(gmsgid, gmsgstr); } if (linebufhead) free(linebufhead); if (munmap(addr, statbuf.st_size) == -1) { error(gettext(ERR_MUNMAP_FAILED), filename); /* NOTREACHED */ } free(filename); return; } /* read_psffm */
int main(int argc, char *argv[]) { int ch, i; printf("dnsheader size: %lu\n", sizeof(struct dnsheader)); while ((ch = getopt(argc, argv, "d:s:p:q:t:l:46eDrvh")) != -1) { switch (ch) { case 'q': nQueries = atoi(optarg); if (nQueries < 1) err(1, "-q requires natural number"); break; case 'p': ServerPort = Xstrdup(optarg); break; case 's': ServerName = Xstrdup(optarg); break; case 'd': datafile = Xstrdup(optarg); if ((fp = fopen(datafile, "r")) == NULL) err(1, "cannot open %s", optarg); break; case 't': i = atoi(optarg); if (i < 1) err(1, "-t timeout > 0"); Timeout = (timediff_t)i * 1000000LL; break; case 'l': TimeLimit = atoi(optarg); break; case '4': family = AF_INET; break; case '6': family = AF_INET6; break; case 'e': EDNS0 = 1; break; case 'D': DNSSEC = 1; break; case 'r': recursion = 1; break; case 'v': verbose = 1; break; case 'c': printrcode = 1; break; case 'h': default: usage(); } } argc -= optind; argv += optind; query(); output(); return 0; }
/* * This routine inserts message in the current domain message list. * It is inserted in ascending order. */ static void insert_message(struct domain_struct *dom, char *msgid, char *msgstr) { struct msg_chain *p1; struct msg_chain *node, *prev_node; int b; /* * Find the optimal starting search position. * The starting search position is either the first node * or the current_elem of domain. * The current_elem is the pointer to the node which * is most recently accessed in domain. */ if (dom->current_elem != NULL) { b = strcmp(msgid, dom->current_elem->msgid); if (b == 0) { if (verbose) warning(gettext(WARN_DUP_MSG), msgid, msgid_linenum); return; } else if (b > 0) { /* to implement descending order */ p1 = dom->first_elem; } else { p1 = dom->current_elem; } } else { p1 = dom->first_elem; } /* * search msgid insert position in the list * Search starts from the node pointed by p1. */ prev_node = NULL; while (p1) { b = strcmp(msgid, p1->msgid); if (b == 0) { if (verbose) warning(gettext(WARN_DUP_MSG), msgid, msgid_linenum); return; } else if (b < 0) { /* to implement descending order */ /* move to the next node */ prev_node = p1; p1 = p1->next; } else { /* insert a new msg node */ node = (struct msg_chain *) Xmalloc(sizeof (struct msg_chain)); node->next = p1; node->msgid = Xstrdup(msgid); node->msgstr = Xstrdup(msgstr); if (prev_node) { prev_node->next = node; } else { dom->first_elem = node; } dom->current_elem = node; return; } } /* while */ /* * msgid is smaller than any of msgid in the list or * list is empty. * Therefore, append it. */ node = (struct msg_chain *) Xmalloc(sizeof (struct msg_chain)); node->next = NULL; node->msgid = Xstrdup(msgid); node->msgstr = Xstrdup(msgstr); if (prev_node) { prev_node->next = node; } else { dom->first_elem = node; } dom->current_elem = node; return; } /* insert_message */
static void ProcessGroups(CACHE1D_FIND_REC *srch) { CACHE1D_FIND_REC *sidx; struct grpcache *fg, *fgg; char *fn; struct Bstat st; #define BUFFER_SIZE (1024 * 1024 * 8) uint8_t *buf = (uint8_t *)Xmalloc(BUFFER_SIZE); for (sidx = srch; sidx; sidx = sidx->next) { for (fg = grpcache; fg; fg = fg->next) { if (!Bstrcmp(fg->name, sidx->name)) break; } if (fg) { if (findfrompath(sidx->name, &fn)) continue; // failed to resolve the filename if (Bstat(fn, &st)) { Bfree(fn); continue; } // failed to stat the file Bfree(fn); if (fg->size == (int32_t)st.st_size && fg->mtime == (int32_t)st.st_mtime) { grpinfo_t const * const grptype = FindGrpInfo(fg->crcval, fg->size); if (grptype) { grpfile_t * const grp = (grpfile_t *)Xcalloc(1, sizeof(grpfile_t)); grp->filename = Xstrdup(sidx->name); grp->type = grptype; grp->next = foundgrps; foundgrps = grp; } fgg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache)); strcpy(fgg->name, fg->name); fgg->size = fg->size; fgg->mtime = fg->mtime; fgg->crcval = fg->crcval; fgg->next = usedgrpcache; usedgrpcache = fgg; continue; } } { int32_t b, fh; int32_t crcval = 0; fh = openfrompath(sidx->name, BO_RDONLY|BO_BINARY, BS_IREAD); if (fh < 0) continue; if (Bfstat(fh, &st)) continue; initprintf(" Checksumming %s...", sidx->name); do { b = read(fh, buf, BUFFER_SIZE); if (b > 0) crcval = Bcrc32((uint8_t *)buf, b, crcval); } while (b == BUFFER_SIZE); close(fh); initprintf(" Done\n"); grpinfo_t const * const grptype = FindGrpInfo(crcval, st.st_size); if (grptype) { grpfile_t * const grp = (grpfile_t *)Xcalloc(1, sizeof(grpfile_t)); grp->filename = Xstrdup(sidx->name); grp->type = grptype; grp->next = foundgrps; foundgrps = grp; } fgg = (struct grpcache *)Xcalloc(1, sizeof(struct grpcache)); Bstrncpy(fgg->name, sidx->name, BMAX_PATH); fgg->size = st.st_size; fgg->mtime = st.st_mtime; fgg->crcval = crcval; fgg->next = usedgrpcache; usedgrpcache = fgg; } } Bfree(buf); }
/* * This routine will find head of the linked list for the given * domain_name. This looks up cache entry first and if cache misses, * scans the list. * If not found, then create a new node. */ static struct domain_struct * find_domain_node(char *domain_name) { struct domain_struct *p1; struct domain_struct *node; struct domain_struct *prev_node; int b; /* for perfomance, check cache 'last_used_domain' */ if (last_used_domain) { b = strcmp(domain_name, last_used_domain->domain); if (b == 0) { return (last_used_domain); } else if (b < 0) { p1 = first_domain; } else { p1 = last_used_domain; } } else { p1 = first_domain; } prev_node = NULL; while (p1) { b = strcmp(domain_name, p1->domain); if (b == 0) { /* node found */ last_used_domain = p1; return (p1); } else if (b > 0) { /* move to the next node */ prev_node = p1; p1 = p1->next; } else { /* insert a new domain node */ node = (struct domain_struct *) Xmalloc(sizeof (struct domain_struct)); node->next = p1; node->domain = Xstrdup(domain_name); node->first_elem = NULL; node->current_elem = NULL; if (prev_node) { /* insert the node in the middle */ prev_node->next = node; } else { /* node inserted is the smallest */ first_domain = node; } last_used_domain = node; return (node); } } /* while */ /* * domain_name is larger than any of domain name in the list or * list is empty. */ node = (struct domain_struct *) Xmalloc(sizeof (struct domain_struct)); node->next = NULL; node->domain = Xstrdup(domain_name); node->first_elem = NULL; node->current_elem = NULL; if (prev_node) { /* domain list is not empty */ prev_node->next = node; } else { /* domain list is empty */ first_domain = node; } last_used_domain = node; return (node); } /* find_domain_node */
/* * Attempts to connect to server, given display name. Returns file descriptor * (network socket) or -1 if connection fails. Display names may be of the * following format: * * [protocol/] [hostname] : [:] displaynumber [.screennumber] * * A string with exactly two colons seperating hostname from the display * indicates a DECnet style name. Colons in the hostname may occur if an * IPv6 numeric address is used as the hostname. An IPv6 numeric address * may also end in a double colon, so three colons in a row indicates an * IPv6 address ending in :: followed by :display. To make it easier for * people to read, an IPv6 numeric address hostname may be surrounded by * [ ] in a similar fashion to the IPv6 numeric address URL syntax defined * by IETF RFC 2732. * * If no hostname and no protocol is specified, the string is interpreted * as the most efficient local connection to a server on the same machine. * This is usually: * * o shared memory * o local stream * o UNIX domain socket * o TCP to local host * * This function will eventually call the X Transport Interface functions * which expects the hostname in the format: * * [protocol/] [hostname] : [:] displaynumber * */ XtransConnInfo _X11TransConnectDisplay ( char *display_name, char **fullnamep, /* RETURN */ int *dpynump, /* RETURN */ int *screenp, /* RETURN */ char **auth_namep, /* RETURN */ int *auth_namelenp, /* RETURN */ char **auth_datap, /* RETURN */ int *auth_datalenp) /* RETURN */ { int family; int saddrlen; Xtransaddr *saddr; char *lastp, *lastc, *p; /* char pointers */ char *pprotocol = NULL; /* start of protocol name */ char *phostname = NULL; /* start of host of display */ char *pdpynum = NULL; /* start of dpynum of display */ char *pscrnum = NULL; /* start of screen of display */ Bool dnet = False; /* if true, then DECnet format */ int idisplay = 0; /* required display number */ int iscreen = 0; /* optional screen number */ /* int (*connfunc)(); */ /* method to create connection */ int len, hostlen; /* length tmp variable */ int retry; /* retry counter */ char addrbuf[128]; /* final address passed to X Transport Interface */ char* address = addrbuf; XtransConnInfo trans_conn = NULL; /* transport connection object */ int connect_stat; #if defined(LOCALCONN) || defined(UNIXCONN) || defined(TCPCONN) Bool reset_hostname = False; /* Reset hostname? */ char *original_hostname = NULL; int local_transport_index = -1; const char *local_transport[] = { LOCAL_TRANSPORT_LIST, NULL }; #endif p = display_name; saddrlen = 0; /* set so that we can clear later */ saddr = NULL; /* * Step 0, find the protocol. This is delimited by the optional * slash ('/'). */ for (lastp = p; *p && *p != ':' && *p != '/'; p++) ; if (!*p) return NULL; /* must have a colon */ if (p != lastp && *p != ':') { /* protocol given? */ pprotocol = copystring (lastp, p - lastp); if (!pprotocol) goto bad; /* no memory */ p++; /* skip the '/' */ } else p = display_name; /* reset the pointer in case no protocol was given */ /* * Step 1, find the hostname. This is delimited by either one colon, * or two colons in the case of DECnet (DECnet Phase V allows a single * colon in the hostname). (See note above regarding IPv6 numeric * addresses with triple colons or [] brackets.) */ lastp = p; lastc = NULL; for (; *p; p++) if (*p == ':') lastc = p; if (!lastc) return NULL; /* must have a colon */ if ((lastp != lastc) && (*(lastc - 1) == ':') #if defined(IPv6) && defined(AF_INET6) && ( ((lastc - 1) == lastp) || (*(lastc - 2) != ':')) #endif ) { /* DECnet display specified */ #ifndef DNETCONN goto bad; #else dnet = True; /* override the protocol specified */ if (pprotocol) Xfree (pprotocol); pprotocol = copystring ("dnet", 4); hostlen = lastc - 1 - lastp; #endif } else hostlen = lastc - lastp; if (hostlen > 0) { /* hostname given? */ phostname = copystring (lastp, hostlen); if (!phostname) goto bad; /* no memory */ } p = lastc; #if defined(LOCALCONN) || defined(UNIXCONN) || defined(TCPCONN) /* check if phostname == localnodename AND protocol not specified */ if (!pprotocol && phostname) { char localhostname[256]; if ((_XGetHostname (localhostname, sizeof localhostname) > 0) && (strcmp(phostname, localhostname) == 0)) { original_hostname = phostname; phostname = NULL; reset_hostname = True; } } #endif /* * Step 2, find the display number. This field is required and is * delimited either by a nul or a period, depending on whether or not * a screen number is present. */ for (lastp = ++p; *p && isascii(*p) && isdigit(*p); p++) ; if ((p == lastp) || /* required field */ (*p != '\0' && *p != '.') || /* invalid non-digit terminator */ !(pdpynum = copystring (lastp, p - lastp))) /* no memory */ goto bad; idisplay = atoi (pdpynum); /* * Step 3, find the screen number. This field is optional. It is * present only if the display number was followed by a period (which * we've already verified is the only non-nul character). */ if (*p) { for (lastp = ++p; *p && isascii(*p) && isdigit (*p); p++) ; if (p != lastp) { if (*p || /* non-digits */ !(pscrnum = copystring (lastp, p - lastp))) /* no memory */ goto bad; iscreen = atoi (lastp); } } /* * At this point, we know the following information: * * pprotocol protocol string or NULL * phostname hostname string or NULL * idisplay display number * iscreen screen number * dnet DECnet boolean * * We can now decide which transport to use based on the defined * connection types and the hostname string. * If phostname & pprotocol are NULL, then choose the best transport. * If phostname is "unix" & pprotocol is NULL, then choose UNIX domain * sockets (if configured). */ #if defined(TCPCONN) || defined(UNIXCONN) || defined(LOCALCONN) || defined(MNX_TCPCONN) || defined(OS2PIPECONN) if (!pprotocol) { #if defined(UNIXCONN) if (phostname && (strcmp (phostname, "unix") == 0)) { Xfree(pprotocol); pprotocol = copystring ("unix", 4); } else #endif #ifdef HAVE_LAUNCHD if (phostname && phostname[0]=='/') { pprotocol = copystring ("local", 5); } #endif if (!phostname) { if (local_transport[0] != NULL) { pprotocol = Xstrdup(local_transport[0]); local_transport_index = 0; } } if (!pprotocol) { /* if still not found one, tcp is our last resort */ pprotocol = copystring ("tcp", 3); } } #endif connect: /* * This seems kind of backwards, but we need to put the protocol, * host, and port back together to pass to _X11TransOpenCOTSClient(). */ { int olen = 3 + (pprotocol ? strlen(pprotocol) : 0) + (phostname ? strlen(phostname) : 0) + (pdpynum ? strlen(pdpynum) : 0); if (olen > sizeof addrbuf) address = Xmalloc (olen); } if (!address) goto bad; sprintf(address,"%s/%s:%d", pprotocol ? pprotocol : "", phostname ? phostname : "", idisplay ); /* * Make the connection, also need to get the auth address info for * the connection. Do retries in case server host has hit its * backlog (which, unfortunately, isn't distinguishable from there not * being a server listening at all, which is why we have to not retry * too many times). */ for(retry=X_CONNECTION_RETRIES; retry>=0; retry-- ) { if ( (trans_conn = _X11TransOpenCOTSClient(address)) == NULL ) { break; } if ((connect_stat = _X11TransConnect(trans_conn,address)) < 0 ) { _X11TransClose(trans_conn); trans_conn = NULL; if (connect_stat == TRANS_TRY_CONNECT_AGAIN) continue; else break; } _X11TransGetPeerAddr(trans_conn, &family, &saddrlen, &saddr); /* * The family is given in a socket format (ie AF_INET). This * will convert it to the format used by the authorization and * X protocol (ie FamilyInternet). */ if( _X11TransConvertAddress(&family, &saddrlen, &saddr) < 0 ) { _X11TransClose(trans_conn); trans_conn = NULL; if (saddr) { free ((char *) saddr); saddr = NULL; } continue; } break; } if (address != addrbuf) Xfree (address); address = addrbuf; if( trans_conn == NULL ) goto bad; /* * Set close-on-exec so that programs that fork() doesn't get confused. */ _X11TransSetOption(trans_conn,TRANS_CLOSEONEXEC,1); /* * Build the expanded display name: * * [host] : [:] dpy . scr \0 */ #if defined(LOCALCONN) || defined(TCPCONN) || defined(UNIXCONN) /* * If we computed the host name, get rid of it so that * XDisplayString() and XDisplayName() agree. */ if (reset_hostname && (phostname != original_hostname)) { Xfree (phostname); phostname = original_hostname; original_hostname = NULL; } #endif len = ((phostname ? strlen(phostname) : 0) + 1 + (dnet ? 1 : 0) + strlen(pdpynum) + 1 + (pscrnum ? strlen(pscrnum) : 1) + 1); *fullnamep = (char *) Xmalloc (len); if (!*fullnamep) goto bad; #ifdef HAVE_LAUNCHD if (phostname && strlen(phostname) > 11 && !strncmp(phostname, "/tmp/launch", 11)) sprintf (*fullnamep, "%s%s%d", (phostname ? phostname : ""), (dnet ? "::" : ":"), idisplay); else #endif sprintf (*fullnamep, "%s%s%d.%d", (phostname ? phostname : ""), (dnet ? "::" : ":"), idisplay, iscreen); *dpynump = idisplay; *screenp = iscreen; if (pprotocol) Xfree (pprotocol); if (phostname) Xfree (phostname); if (pdpynum) Xfree (pdpynum); if (pscrnum) Xfree (pscrnum); #if defined(LOCALCONN) || defined(UNIXCONN) || defined(TCPCONN) if (original_hostname) Xfree (original_hostname); #endif GetAuthorization(trans_conn, family, (char *) saddr, saddrlen, idisplay, auth_namep, auth_namelenp, auth_datap, auth_datalenp); return trans_conn; /* * error return; make sure everything is cleaned up. */ bad: if (trans_conn) (void)_X11TransClose(trans_conn); if (saddr) free ((char *) saddr); if (pprotocol) Xfree (pprotocol); if (phostname) Xfree (phostname); if (address && address != addrbuf) { Xfree(address); address = addrbuf; } #if defined(LOCALCONN) || defined(UNIXCONN) || defined(TCPCONN) /* If connecting to the local machine, and we failed, try again with * the next transport type available, if there is one. */ if (local_transport_index >= 0) { if (local_transport[++local_transport_index] != NULL) { pprotocol = Xstrdup(local_transport[local_transport_index]); #ifdef TCPCONN if (strcmp(pprotocol, "tcp") == 0) { if (original_hostname != NULL) { phostname = original_hostname; original_hostname = NULL; } else { phostname = copystring("localhost", 9); } } else #endif /* TCPCONN */ { if ((phostname != NULL) && (original_hostname == NULL)) { original_hostname = phostname; } phostname = NULL; } goto connect; } } /* No more to try, we've failed all available local transports */ if (original_hostname) Xfree(original_hostname); #endif /* LOCALCONN || UNIXCONN || TCPCONN */ if (pdpynum) Xfree (pdpynum); if (pscrnum) Xfree (pscrnum); return NULL; }
static int mavis_parse_in(mavis_ctx * mcx, struct sym *sym) { while (1) { switch (sym->code) { case S_script: mavis_script_parse(mcx, sym); continue; case S_userid: parse_userid(sym, &mcx->uid, &mcx->gid); continue; case S_groupid: parse_groupid(sym, &mcx->gid); continue; case S_home: sym_get(sym); parse(sym, S_equal); strset(&mcx->home, sym->buf); sym_get(sym); continue; case S_root: sym_get(sym); parse(sym, S_equal); strset(&mcx->root, sym->buf); sym_get(sym); continue; case S_upload: sym_get(sym); parse(sym, S_equal); strset(&mcx->incoming, sym->buf); sym_get(sym); continue; case S_eof: case S_closebra: { int bye = 0; if (!mcx->uid || !mcx->gid || !mcx->root) { struct passwd *pw; pw = getpwnam("ftp"); if (pw) { if (!mcx->uid) mcx->uid = pw->pw_uid; if (!mcx->gid) mcx->gid = pw->pw_gid; if (!mcx->root) mcx->root = Xstrdup(pw->pw_dir); } } if (!mcx->uid) { logmsg("%s: Fatal: anonymous ftp uid not set!", MAVIS_name); bye++; } if (!mcx->gid) { logmsg("%s: Fatal: anonymous ftp gid not set!", MAVIS_name); bye++; } if (!mcx->root) { logmsg("%s: Fatal: anonymous ftp root not set!", MAVIS_name); bye++; } if (bye) return -1; if (!mcx->home) mcx->home = Xstrdup("/"); return MAVIS_CONF_OK; } default: parse_error_expect(sym, S_script, S_userid, S_groupid, S_path, S_mode, S_closebra, S_unknown); } } }