char * _dico_ldap_expand_user(const char *query, const char *user) { struct wordsplit ws; const char *env[3]; char *res; env[0] = "user"; env[1] = user; env[2] = NULL; ws.ws_env = env; if (wordsplit(query, &ws, WRDSF_NOSPLIT | WRDSF_NOCMD | WRDSF_ENV | WRDSF_ENV_KV)) { dico_log(L_ERR, 0, _("cannot expand query `%s': %s"), query, wordsplit_strerror(&ws)); return NULL; } res = ws.ws_wordv[0]; ws.ws_wordv[0] = NULL; wordsplit_free(&ws); return res; }
static void run_decompress_program (void) { int i; const char *p, *prog = NULL; struct wordsplit ws; int wsflags = (WRDSF_DEFFLAGS | WRDSF_ENV | WRDSF_DOOFFS) & ~WRDSF_NOVAR; ws.ws_env = (const char **) environ; ws.ws_offs = 1; for (p = first_decompress_program (&i); p; p = next_decompress_program (&i)) { if (prog) { WARNOPT (WARN_DECOMPRESS_PROGRAM, (0, errno, _("cannot run %s"), prog)); WARNOPT (WARN_DECOMPRESS_PROGRAM, (0, 0, _("trying %s"), p)); } if (wordsplit (p, &ws, wsflags)) FATAL_ERROR ((0, 0, _("cannot split string '%s': %s"), p, wordsplit_strerror (&ws))); wsflags |= WRDSF_REUSE; memmove(ws.ws_wordv, ws.ws_wordv + ws.ws_offs, sizeof(ws.ws_wordv[0])*ws.ws_wordc); ws.ws_wordv[ws.ws_wordc] = (char *) "-d"; prog = p; execvp (ws.ws_wordv[0], ws.ws_wordv); ws.ws_wordv[ws.ws_wordc] = NULL; } if (!prog) FATAL_ERROR ((0, 0, _("unable to run decompression program"))); exec_fatal (prog); }
static int db_open(void **phandle, dico_url_t url, const char *options) { struct _dico_ldap_handle hstr, *handle; int rc; long debug = 0; struct dico_option option[] = { { DICO_OPTSTR(base), dico_opt_string, &hstr.base }, { DICO_OPTSTR(binddn), dico_opt_string, &hstr.binddn }, { DICO_OPTSTR(passwd), dico_opt_string, &hstr.passwd }, { DICO_OPTSTR(tls), dico_opt_bool, &hstr.tls }, { DICO_OPTSTR(debug), dico_opt_long, &debug }, { DICO_OPTSTR(user-filter), dico_opt_string, &hstr.user_filter }, { DICO_OPTSTR(group-filter), dico_opt_string, &hstr.group_filter }, { NULL } }; memset(&hstr, 0, sizeof(hstr)); if (options) { struct wordsplit ws; if (wordsplit(options, &ws, WRDSF_DEFFLAGS)) { dico_log(L_ERR, 0, _("cannot parse options `%s': %s"), options, wordsplit_strerror(&ws)); return 1; } rc = dico_parseopt(option, ws.ws_wordc, ws.ws_wordv, DICO_PARSEOPT_PARSE_ARGV0, NULL); wordsplit_free(&ws); if (rc) return 1; hstr.debug = debug; } hstr.url = url->string; handle = malloc(sizeof(*handle)); if (!handle) { dico_log(L_ERR, errno, _("cannot allocate handle")); return 1; } *handle = hstr; rc = _dico_conn_setup(handle) || _dico_ldap_bind(handle); if (rc) { free_ldap_handle(handle); } else { *phandle = handle; } return rc; }
static _Noreturn void xexec (const char *cmd) { struct wordsplit ws; ws.ws_env = (const char **) environ; if (wordsplit (cmd, &ws, (WRDSF_DEFFLAGS | WRDSF_ENV) & ~WRDSF_NOVAR)) FATAL_ERROR ((0, 0, _("cannot split string '%s': %s"), cmd, wordsplit_strerror (&ws))); execvp (ws.ws_wordv[0], ws.ws_wordv); exec_fatal (cmd); }
void wordsplit_perror (struct wordsplit *wsp) { switch (wsp->ws_errno) { case WRDSE_QUOTE: wsp->ws_error (_("missing closing %c (start near #%lu)"), wsp->ws_input[wsp->ws_endp], (unsigned long) wsp->ws_endp); break; default: wsp->ws_error (wordsplit_strerror (wsp)); } }
static int format_checkpoint_string (FILE *fp, size_t len, const char *input, bool do_write, unsigned cpn) { const char *opstr = do_write ? gettext ("write") : gettext ("read"); char uintbuf[UINTMAX_STRSIZE_BOUND]; char *cps = STRINGIFY_BIGINT (cpn, uintbuf); const char *ip; static char *argbuf = NULL; static size_t arglen = 0; char *arg = NULL; if (!input) { if (do_write) /* TRANSLATORS: This is a "checkpoint of write operation", *not* "Writing a checkpoint". E.g. in Spanish "Punto de comprobaci@'on de escritura", *not* "Escribiendo un punto de comprobaci@'on" */ input = gettext ("Write checkpoint %u"); else /* TRANSLATORS: This is a "checkpoint of read operation", *not* "Reading a checkpoint". E.g. in Spanish "Punto de comprobaci@'on de lectura", *not* "Leyendo un punto de comprobaci@'on" */ input = gettext ("Read checkpoint %u"); } for (ip = input; *ip; ip++) { if (*ip == '%') { if (*++ip == '{') { arg = getarg (ip, &ip, &argbuf, &arglen); if (!arg) { fputc ('%', fp); fputc (*ip, fp); len += 2; continue; } } switch (*ip) { case 'c': len += format_checkpoint_string (fp, len, def_format, do_write, cpn); break; case 'u': fputs (cps, fp); len += strlen (cps); break; case 's': fputs (opstr, fp); len += strlen (opstr); break; case 'd': len += fprintf (fp, "%.0f", compute_duration ()); break; case 'T': { const char **fmt = checkpoint_total_format, *fmtbuf[3]; struct wordsplit ws; compute_duration (); if (arg) { ws.ws_delim = ","; if (wordsplit (arg, &ws, WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_QUOTE | WRDSF_DELIM)) ERROR ((0, 0, _("cannot split string '%s': %s"), arg, wordsplit_strerror (&ws))); else { int i; for (i = 0; i < ws.ws_wordc; i++) fmtbuf[i] = ws.ws_wordv[i]; for (; i < 3; i++) fmtbuf[i] = NULL; fmt = fmtbuf; } } len += format_total_stats (fp, fmt, ',', 0); if (arg) wordsplit_free (&ws); } break; case 't': { struct timeval tv; struct tm *tm; const char *fmt = arg ? arg : "%c"; gettimeofday (&tv, NULL); tm = localtime (&tv.tv_sec); len += fprintftime (fp, fmt, tm, 0, tv.tv_usec * 1000); } break; case '*': { long w = arg ? strtol (arg, NULL, 10) : getwidth (fp); for (; w > len; len++) fputc (' ', fp); } break; default: fputc ('%', fp); fputc (*ip, fp); len += 2; break; } arg = NULL; } else { fputc (*ip, fp); if (*ip == '\r') { len = 0; tty_cleanup = 1; } else len++; } } fflush (fp); return len; }