int main(int argc, const char *const *argv) { struct dpkg_error err; int ret; setlocale(LC_NUMERIC, "POSIX"); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); dpkg_set_progname(BACKEND); standard_startup(); myopt(&argv, cmdinfos, printforhelp); if (!cipaction) badusage(_("need an action option")); if (!compressor_check_params(&compress_params, &err)) badusage(_("invalid compressor parameters: %s"), err.str); unsetenv("GZIP"); ret = cipaction->action(argv); standard_shutdown(); return ret; }
void do_split(const char *const *argv) { const char *sourcefile, *prefix; char *palloc; int l; size_t partsize; sourcefile = *argv++; if (!sourcefile) badusage(_("--split needs a source filename argument")); prefix = *argv++; if (prefix && *argv) badusage(_("--split takes at most a source filename and destination prefix")); if (!prefix) { l = strlen(sourcefile); palloc = nfmalloc(l + 1); strcpy(palloc, sourcefile); if (!strcmp(palloc + l - (sizeof(DEBEXT) - 1), DEBEXT)) { l -= (sizeof(DEBEXT) - 1); palloc[l] = '\0'; } prefix = palloc; } partsize = opt_maxpartsize - HEADERALLOWANCE; mksplit(sourcefile, prefix, partsize, opt_maxpartsize, opt_msdos); exit(0); }
int do_extract(const char *const *argv) { const char *debar, *dir; enum dpkg_tar_options options = DPKG_TAR_EXTRACT | DPKG_TAR_PERMS; if (opt_verbose) options |= DPKG_TAR_LIST; debar = *argv++; if (debar == NULL) badusage(_("--%s needs .deb filename and directory arguments"), cipaction->olong); dir = *argv++; if (dir == NULL) badusage(_("--%s needs a target directory.\n" "Perhaps you should be using dpkg --install ?"), cipaction->olong); else if (*argv) badusage(_("--%s takes at most two arguments (.deb and directory)"), cipaction->olong); extracthalf(debar, dir, options, 0); return 0; }
int packages(const char *const *argv) { trigproc_install_hooks(); modstatdb_open(f_noact ? msdbrw_readonly : in_force(FORCE_NON_ROOT) ? msdbrw_write : msdbrw_needsuperuser); checkpath(); pkg_infodb_upgrade(); log_message("startup packages %s", cipaction->olong); if (f_pending) { if (*argv) badusage(_("--%s --pending does not take any non-option arguments"),cipaction->olong); enqueue_pending(); } else { if (!*argv) badusage(_("--%s needs at least one package name argument"), cipaction->olong); enqueue_specified(argv); } ensure_diversions(); process_queue(); trigproc_run_deferred(); modstatdb_shutdown(); return 0; }
static void enqueue_specified(const char *const *argv) { const char *thisarg; while ((thisarg = *argv++) != NULL) { struct dpkg_error err; struct pkginfo *pkg; pkg = pkg_spec_parse_pkg(thisarg, &err); if (pkg == NULL) badusage(_("--%s needs a valid package name but '%.250s' is not: %s"), cipaction->olong, thisarg, err.str); if (pkg->status == stat_notinstalled) { size_t l = strlen(pkg->set->name); const char *extension = pkg->set->name + l - sizeof(DEBEXT) + 1; if (l >= sizeof(DEBEXT) && strcmp(extension, DEBEXT) == 0) badusage(_("you must specify packages by their own names," " not by quoting the names of the files they come in")); } enqueue_package(pkg); } }
static void diversion_check_filename(const char *filename) { if (filename[0] != '/') badusage(_("filename \"%s\" is not absolute"), filename); if (strchr(filename, '\n') != NULL) badusage(_("file may not contain newlines")); }
void do_fsystarfile(const char *const *argv) { const char *debar; if (!(debar= *argv++)) badusage(_("--%s needs a .deb filename argument"),cipaction->olong); if (*argv) badusage(_("--%s takes only one argument (.deb filename)"),cipaction->olong); extracthalf(debar, NULL, NULL, 0); }
int main(int argc, const char *const *argv) { int uf; const char *badname; enum trigdef_updateflags tduf; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); dpkg_set_progname("dpkg-trigger"); standard_startup(); myopt(&argv, cmdinfos, printforhelp); admindir = dpkg_db_set_dir(admindir); setvbuf(stdout, NULL, _IONBF, 0); if (f_check) { if (*argv) badusage(_("--%s takes no arguments"), "check-supported"); do_check(); } if (!*argv || argv[1]) badusage(_("takes one argument, the trigger name")); badname = parse_awaiter_package(); if (badname) ohshit(_("illegal awaited package name '%.250s': %.250s"), bypackage, badname); activate = argv[0]; badname = trig_name_is_illegal(activate); if (badname) badusage(_("invalid trigger name `%.250s': %.250s"), activate, badname); trigdef_set_methods(&tdm_add); tduf = tduf_nolockok; if (!f_noact) tduf |= tduf_write | tduf_writeifempty; uf = trigdef_update_start(tduf); if (uf >= 0) { trigdef_parse(); if (!done_trig) trigdef_update_printf("%s %s\n", activate, bypackage); trigdef_process_done(); } standard_shutdown(); return 0; }
static void set_divertto(const struct cmdinfo *cip, const char *value) { opt_divertto = value; if (opt_divertto[0] != '/') badusage(_("filename \"%s\" is not absolute"), opt_divertto); if (strchr(opt_divertto, '\n') != NULL) badusage(_("divert-to may not contain newlines")); }
int main(int argc, const char *const *argv) { const char *badname; enum trigdef_update_flags tduf; enum trigdef_update_status tdus; dpkg_locales_init(PACKAGE); dpkg_program_init("dpkg-trigger"); dpkg_options_parse(&argv, cmdinfos, printforhelp); admindir = dpkg_db_set_dir(admindir); if (f_check) { if (*argv) badusage(_("--%s takes no arguments"), "check-supported"); return do_check(); } if (!*argv || argv[1]) badusage(_("takes one argument, the trigger name")); badname = parse_awaiter_package(); if (badname) badusage(_("illegal awaited package name '%.250s': %.250s"), bypackage, badname); fsys_hash_init(); activate = argv[0]; badname = trig_name_is_illegal(activate); if (badname) badusage(_("invalid trigger name '%.250s': %.250s"), activate, badname); trigdef_set_methods(&tdm_add); tduf = TDUF_NO_LOCK_OK; if (!f_noact) tduf |= TDUF_WRITE | TDUF_WRITE_IF_EMPTY; tdus = trigdef_update_start(tduf); if (tdus >= 0) { trigdef_parse(); if (!done_trig) trigdef_update_printf("%s %s\n", activate, bypackage); trigdef_process_done(); } dpkg_program_done(); return 0; }
int do_fsystarfile(const char *const *argv) { const char *debar; debar = *argv++; if (debar == NULL) badusage(_("--%s needs a .deb filename argument"),cipaction->olong); if (*argv) badusage(_("--%s takes only one argument (.deb filename)"),cipaction->olong); extracthalf(debar, NULL, DPKG_TAR_PASSTHROUGH, 0); return 0; }
static int statoverride_add(const char *const *argv) { const char *user = argv[0]; const char *group = argv[1]; const char *mode = argv[2]; const char *path = argv[3]; char *filename; struct file_stat **filestat; if (!user || !group || !mode || !path || argv[4]) badusage(_("--%s needs four arguments"), cipaction->olong); if (strchr(path, '\n')) badusage(_("path may not contain newlines")); filename = path_cleanup(path); filestat = statdb_node_find(filename); if (*filestat != NULL) { if (opt_force) warning(_("an override for '%s' already exists, " "but --force specified so will be ignored"), filename); else ohshit(_("an override for '%s' already exists; " "aborting"), filename); } *filestat = statdb_node_new(user, group, mode); if (opt_update) { struct stat st; if (stat(filename, &st) == 0) { (*filestat)->mode |= st.st_mode & S_IFMT; statdb_node_apply(filename, *filestat); } else if (opt_verbose) { warning(_("--update given but %s does not exist"), filename); } } statdb_write(); free(filename); return 0; }
static void set_compress_level(const struct cmdinfo *cip, const char *value) { long level; char *end; level = strtol(value, &end, 0); if (value == end || *end || level > INT_MAX) badusage(_("invalid integer for -%c: '%.250s'"), cip->oshort, value); if (level < 0 || level > 9) badusage(_("invalid compression level for -%c: %ld'"), cip->oshort, level); compress_params.level = level; }
static void set_ignore_depends(const struct cmdinfo *cip, const char *value) { char *copy, *p; copy= m_malloc(strlen(value)+2); strcpy(copy,value); copy[strlen(value) + 1] = '\0'; for (p=copy; *p; p++) { if (*p != ',') continue; *p++ = '\0'; if (!*p || *p==',' || p==copy+1) badusage(_("null package name in --%s comma-separated list '%.250s'"), cip->olong, value); } p= copy; while (*p) { struct pkginfo *pkg; pkg = dpkg_options_parse_pkgname(cip, p); pkg_list_prepend(&ignoredependss, pkg); p+= strlen(p)+1; } free(copy); }
static void set_debug(const struct cmdinfo *cpi, const char *value) { char *endp; long mask; const struct debuginfo *dip; if (*value == 'h') { printf(_( "%s debugging option, --debug=<octal> or -D<octal>:\n" "\n" " Number Ref. in source Description\n"), DPKG); for (dip = debuginfos; dip->name; dip++) printf(" %6o %-16s %s\n", dip->flag, dip->name, gettext(dip->desc)); printf(_("\n" "Debugging options can be mixed using bitwise-or.\n" "Note that the meanings and values are subject to change.\n")); m_output(stdout, _("<standard output>")); exit(0); } errno = 0; mask = strtol(value, &endp, 8); if (value == endp || *endp || mask < 0 || errno == ERANGE) badusage(_("--%s requires a positive octal argument"), cpi->olong); debug_set_mask(mask); }
static void checkmanymodes(const char *curmode, const char *newmode) { if (!curmode) return; badusage(_("two commands specified: --%s and --%s"), newmode, curmode); }
static void assert_version_support(const char *const *argv, struct versionrevision *version, const char *feature_name) { struct pkginfo *pkg; if (*argv) badusage(_("--%s takes no arguments"), cipaction->olong); modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail); pkg = pkg_db_find("dpkg"); switch (pkg->status) { case stat_installed: case stat_triggerspending: break; case stat_unpacked: case stat_halfconfigured: case stat_halfinstalled: case stat_triggersawaited: if (versionsatisfied3(&pkg->configversion, version, dvr_laterequal)) break; printf(_("Version of dpkg with working %s support not yet configured.\n" " Please use 'dpkg --configure dpkg', and then try again.\n"), feature_name); exit(1); default: printf(_("dpkg not recorded as installed, cannot check for %s support!\n"), feature_name); exit(1); } }
int main(int argc, const char *const *argv) { jmp_buf ejbuf; void (*actionfunction)(const char *const *argv); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); standard_startup(&ejbuf); loadcfgfile(DPKG, cmdinfos); myopt(&argv, cmdinfos); if (!cipaction) badusage(_("need an action option")); if (!f_triggers) f_triggers = (cipaction->arg == act_triggers && *argv) ? -1 : 1; setvbuf(stdout, NULL, _IONBF, 0); if (is_invoke_action(cipaction->arg)) run_invoke_hooks(cipaction->olong, pre_invoke_hooks); filesdbinit(); actionfunction= (void (*)(const char* const*))cipaction->farg; actionfunction(argv); if (is_invoke_action(cipaction->arg)) run_invoke_hooks(cipaction->olong, post_invoke_hooks); standard_shutdown(); return reportbroken_retexitstatus(); }
static void ignoredepends(const struct cmdinfo *cip, const char *value) { char *copy, *p; const char *pnerr; copy= m_malloc(strlen(value)+2); strcpy(copy,value); copy[strlen(value) + 1] = '\0'; for (p=copy; *p; p++) { if (*p != ',') continue; *p++ = '\0'; if (!*p || *p==',' || p==copy+1) badusage(_("null package name in --ignore-depends comma-separated list `%.250s'"), value); } p= copy; while (*p) { pnerr = illegal_packagename(p, NULL); if (pnerr) ohshite(_("--ignore-depends requires a legal package name. " "`%.250s' is not; %s"), p, pnerr); pkg_list_prepend(&ignoredependss, findpackage(p)); p+= strlen(p)+1; } free(copy); }
static const char * parse_awaiter_package(void) { struct dpkg_error err = DPKG_ERROR_INIT; struct pkginfo *pkg; if (!f_await) bypackage = "-"; if (bypackage == NULL) { const char *pkgname, *archname; pkgname = getenv("DPKG_MAINTSCRIPT_PACKAGE"); archname = getenv("DPKG_MAINTSCRIPT_ARCH"); if (pkgname == NULL || archname == NULL) badusage(_("must be called from a maintainer script" " (or with a --by-package option)")); pkg = pkg_spec_find_pkg(pkgname, archname, &err); } else if (strcmp(bypackage, "-") == 0) { pkg = NULL; } else { pkg = pkg_spec_parse_pkg(bypackage, &err); } /* Normalize the bypackage name if there was no error. */ if (pkg) bypackage = pkg_name(pkg, pnaw_nonambig); return err.str; }
static int assert_version_support(const char *const *argv, struct versionrevision *version, const char *feature_name) { struct pkginfo *pkg; enum modstatdb_rw msdb_status; if (*argv) badusage(_("--%s takes no arguments"), cipaction->olong); msdb_status = modstatdb_open(msdbrw_readonly); pkg_infodb_init(msdb_status); pkg = pkg_db_find_pkg("dpkg", NULL); switch (pkg->status) { case stat_installed: case stat_triggerspending: return 0; case stat_unpacked: case stat_halfconfigured: case stat_halfinstalled: case stat_triggersawaited: if (versionsatisfied3(&pkg->configversion, version, dvr_laterequal)) return 0; printf(_("Version of dpkg with working %s support not yet configured.\n" " Please use 'dpkg --configure dpkg', and then try again.\n"), feature_name); return 1; default: printf(_("dpkg not recorded as installed, cannot check for %s support!\n"), feature_name); return 1; } }
static void controlextractvextract(int admin, const char *taroptions, const char *const *argv) { const char *debar, *directory; if (!(debar= *argv++)) badusage(_("--%s needs a .deb filename argument"),cipaction->olong); if (!(directory= *argv++)) { if (admin) directory= EXTRACTCONTROLDIR; else ohshit(_("--%s needs a target directory.\n" "Perhaps you should be using dpkg --install ?"),cipaction->olong); } else if (*argv) { badusage(_("--%s takes at most two arguments (.deb and directory)"),cipaction->olong); } extracthalf(debar, directory, taroptions, admin); }
static int statoverride_remove(const char *const *argv) { const char *path = argv[0]; char *filename; if (!path || argv[1]) badusage(_("--%s needs a single argument"), "remove"); filename = path_cleanup(path); if (!statdb_node_remove(filename)) { if (opt_verbose) warning(_("no override present")); if (opt_force) return 0; else return 2; } if (opt_update && opt_verbose) warning(_("--update is useless for --remove")); statdb_write(); free(filename); return 0; }
int do_info(const char *const *argv) { const char *thisarg; struct partinfo *pi, ps; struct dpkg_ar *part; if (!*argv) badusage(_("--%s requires one or more part file arguments"), cipaction->olong); while ((thisarg= *argv++)) { part = dpkg_ar_open(thisarg); if (!part) ohshite(_("cannot open archive part file '%.250s'"), thisarg); pi = read_info(part, &ps); dpkg_ar_close(part); if (pi) { print_info(pi); } else { printf(_("file '%s' is not an archive part\n"), thisarg); } m_output(stdout, _("<standard output>")); } return 0; }
int clearselections(const char *const *argv) { enum modstatdb_rw msdbflags; struct pkgiterator *it; struct pkginfo *pkg; if (*argv) badusage(_("--%s takes no arguments"), cipaction->olong); if (f_noact) msdbflags = msdbrw_readonly; else msdbflags = msdbrw_write; modstatdb_open(msdbflags); pkg_infodb_upgrade(); it = pkg_db_iter_new(); while ((pkg = pkg_db_iter_next_pkg(it))) { if (!pkg->installed.essential) pkg_set_want(pkg, PKG_WANT_DEINSTALL); } pkg_db_iter_free(it); modstatdb_shutdown(); return 0; }
int main(int argc, const char *const *argv) { int ret; dpkg_locales_init(PACKAGE); dpkg_program_init("dpkg"); dpkg_options_load(DPKG, cmdinfos); dpkg_options_parse(&argv, cmdinfos, printforhelp); if (!cipaction) badusage(_("need an action option")); admindir = dpkg_db_set_dir(admindir); /* Always set environment, to avoid possible security risks. */ if (setenv("DPKG_ADMINDIR", admindir, 1) < 0) ohshite(_("unable to setenv for subprocesses")); if (!f_triggers) f_triggers = (cipaction->arg_int == act_triggers && *argv) ? -1 : 1; if (is_invoke_action(cipaction->arg_int)) { run_invoke_hooks(cipaction->olong, pre_invoke_hooks); run_status_loggers(status_loggers); } filesdbinit(); ret = cipaction->action(argv); if (is_invoke_action(cipaction->arg_int)) run_invoke_hooks(cipaction->olong, post_invoke_hooks); dpkg_program_done(); return reportbroken_retexitstatus(ret); }
static int arch_add(const char *const *argv) { struct dpkg_arch *arch; const char *archname = *argv++; if (archname == NULL || *argv) badusage(_("--%s takes exactly one argument"), cipaction->olong); dpkg_arch_load_list(); arch = dpkg_arch_add(archname); switch (arch->type) { case DPKG_ARCH_NATIVE: case DPKG_ARCH_FOREIGN: break; case DPKG_ARCH_ILLEGAL: ohshit(_("architecture '%s' is illegal: %s"), archname, dpkg_arch_name_is_illegal(archname)); default: ohshit(_("architecture '%s' is reserved and cannot be added"), archname); } dpkg_arch_save_list(); return 0; }
static void setdebug(const struct cmdinfo *cpi, const char *value) { char *endp; if (*value == 'h') { printf(_( "%s debugging option, --debug=<octal> or -D<octal>:\n" "\n" " number ref. in source description\n" " 1 general Generally helpful progress information\n" " 2 scripts Invocation and status of maintainer scripts\n" " 10 eachfile Output for each file processed\n" " 100 eachfiledetail Lots of output for each file processed\n" " 20 conff Output for each configuration file\n" " 200 conffdetail Lots of output for each configuration file\n" " 40 depcon Dependencies and conflicts\n" " 400 depcondetail Lots of dependencies/conflicts output\n" " 10000 triggers Trigger activation and processing\n" " 20000 triggersdetail Lots of output regarding triggers\n" " 40000 triggersstupid Silly amounts of output regarding triggers\n" " 1000 veryverbose Lots of drivel about eg the dpkg/info directory\n" " 2000 stupidlyverbose Insane amounts of drivel\n" "\n" "Debugging options are be mixed using bitwise-or.\n" "Note that the meanings and values are subject to change.\n"), DPKG); m_output(stdout, _("<standard output>")); exit(0); } f_debug= strtoul(value,&endp,8); if (value == endp || *endp) badusage(_("--debug requires an octal argument")); }
static int assert_version_support(const char *const *argv, struct dpkg_version *version, const char *feature_name) { struct pkginfo *pkg; if (*argv) badusage(_("--%s takes no arguments"), cipaction->olong); modstatdb_open(msdbrw_readonly); pkg = pkg_db_find_singleton("dpkg"); switch (pkg->status) { case PKG_STAT_INSTALLED: case PKG_STAT_TRIGGERSPENDING: return 0; case PKG_STAT_UNPACKED: case PKG_STAT_HALFCONFIGURED: case PKG_STAT_HALFINSTALLED: case PKG_STAT_TRIGGERSAWAITED: if (dpkg_version_relate(&pkg->configversion, DPKG_RELATION_GE, version)) return 0; printf(_("Version of dpkg with working %s support not yet configured.\n" " Please use 'dpkg --configure dpkg', and then try again.\n"), feature_name); return 1; default: printf(_("dpkg not recorded as installed, cannot check for %s support!\n"), feature_name); return 1; } }
static int diversion_listpackage(const char *const *argv) { const char *filename = argv[0]; struct fsys_namenode *namenode; if (!filename || argv[1]) badusage(_("--%s needs a single argument"), cipaction->olong); diversion_check_filename(filename); namenode = fsys_hash_find_node(filename, FHFF_NONE); /* Print nothing if file is not diverted. */ if (namenode == NULL || namenode->divert == NULL) return 0; if (namenode->divert->pkgset == NULL) /* Indicate package is local using something not in package * namespace. */ printf("LOCAL\n"); else printf("%s\n", namenode->divert->pkgset->name); return 0; }