int main(int argc, char **argv) { const char optstr[] = ":admopstuxg:l:"; int i; #ifdef __GLIBC__ putenv("POSIXLY_CORRECT=1"); #endif progname = basename(argv[0]); while ((i = getopt(argc, argv, optstr)) != EOF) { switch (i) { case 'a': aflag = 1; break; case 'd': dflag = 1; break; case 'm': mflag = 1; break; case 'o': oflag = 1; break; case 'p': pflag = 1; break; case 's': sflag = 1; break; case 't': tflag = 1; break; case 'u': uflag = 1; break; case 'x': xflag = 1; break; case 'g': selectgrp(optarg); break; case 'l': selectuser(optarg); break; default: usage(); } } if (argv[optind]) usage(); if (sflag && uflag) sflag = uflag = 0; readpasswd(); readshadow(); readgroup(); userdel(); report(); return errcnt; }
int main(int argc, const char **argv) { int ret = EXIT_SUCCESS; struct tools_ctx *tctx = NULL; const char *pc_username = NULL; int pc_debug = SSSDBG_DEFAULT; int pc_remove = 0; int pc_force = 0; int pc_kick = 0; poptContext pc = NULL; struct poptOption long_options[] = { POPT_AUTOHELP { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL }, { "remove", 'r', POPT_ARG_NONE, NULL, 'r', _("Remove home directory and mail spool"), NULL }, { "no-remove", 'R', POPT_ARG_NONE, NULL, 'R', _("Do not remove home directory and mail spool"), NULL }, { "force", 'f', POPT_ARG_NONE, NULL, 'f', _("Force removal of files not owned by the user"), NULL }, { "kick", 'k', POPT_ARG_NONE, NULL, 'k', _("Kill users' processes before removing him"), NULL }, POPT_TABLEEND }; debug_prg_name = argv[0]; ret = set_locale(); if (ret != EOK) { DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret))); ERROR("Error setting the locale\n"); ret = EXIT_FAILURE; goto fini; } /* parse parameters */ pc = poptGetContext(NULL, argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "USERNAME"); while ((ret = poptGetNextOpt(pc)) > 0) { switch (ret) { case 'r': pc_remove = DO_REMOVE_HOME; break; case 'R': pc_remove = DO_NOT_REMOVE_HOME; break; case 'f': pc_force = DO_FORCE_REMOVAL; break; case 'k': pc_kick = 1; break; } } debug_level = debug_convert_old_level(pc_debug); if (ret != -1) { BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini); } pc_username = poptGetArg(pc); if (pc_username == NULL) { BAD_POPT_PARAMS(pc, _("Specify user to delete\n"), ret, fini); } CHECK_ROOT(ret, debug_prg_name); ret = init_sss_tools(&tctx); if (ret != EOK) { DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret))); if (ret == ENOENT) { ERROR("Error initializing the tools - no local domain\n"); } else { ERROR("Error initializing the tools\n"); } ret = EXIT_FAILURE; goto fini; } /* if the domain was not given as part of FQDN, default to local domain */ ret = parse_name_domain(tctx, pc_username); if (ret != EOK) { ERROR("Invalid domain specified in FQDN\n"); ret = EXIT_FAILURE; goto fini; } /* * Fills in defaults for ops_ctx user did not specify. */ ret = userdel_defaults(tctx, tctx->confdb, tctx->octx, pc_remove); if (ret != EOK) { ERROR("Cannot set default values\n"); ret = EXIT_FAILURE; goto fini; } ret = sysdb_getpwnam_sync(tctx, tctx->sysdb, tctx->octx->name, tctx->octx); if (ret != EOK) { /* Error message will be printed in the switch */ goto done; } if ((tctx->octx->uid < tctx->local->id_min) || (tctx->local->id_max && tctx->octx->uid > tctx->local->id_max)) { ERROR("User %1$s is outside the defined ID range for domain\n", tctx->octx->name); ret = EXIT_FAILURE; goto fini; } if (pc_kick) { ret = kick_user(tctx); if (ret != EOK) { tctx->error = ret; goto done; } } /* userdel */ ret = userdel(tctx, tctx->sysdb, tctx->octx); if (ret != EOK) { goto done; } /* Set SELinux login context - must be done after transaction is done * b/c libselinux calls getpwnam */ ret = del_seuser(tctx->octx->name); if (ret != EOK) { ERROR("Cannot reset SELinux login context\n"); ret = EXIT_FAILURE; goto fini; } if (!pc_kick) { ret = is_logged_in(tctx, tctx->octx->uid); switch(ret) { case ENOENT: break; case EOK: ERROR("WARNING: The user (uid %1$lu) was still logged in when " "deleted.\n", (unsigned long) tctx->octx->uid); break; case ENOSYS: ERROR("Cannot determine if the user was logged in on this " "platform"); break; default: ERROR("Error while checking if the user was logged in\n"); break; } } ret = run_userdel_cmd(tctx); if (ret != EOK) { ERROR("The post-delete command failed: %1$s\n", strerror(ret)); goto fini; } if (tctx->octx->remove_homedir) { ret = remove_homedir(tctx, tctx->octx->home, tctx->octx->maildir, tctx->octx->name, tctx->octx->uid, pc_force); if (ret == EPERM) { ERROR("Not removing home dir - not owned by user\n"); } else if (ret != EOK) { ERROR("Cannot remove homedir: %1$s\n", strerror(ret)); ret = EXIT_FAILURE; goto fini; } } done: if (ret) { DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret))); switch (ret) { case ENOENT: ERROR("No such user in local domain. " "Removing users only allowed in local domain.\n"); break; default: ERROR("Internal error. Could not remove user.\n"); break; } ret = EXIT_FAILURE; goto fini; } ret = EXIT_SUCCESS; fini: talloc_free(tctx); poptFreeContext(pc); exit(ret); }
mainWidget::mainWidget(const char *name) : KTMainWindow(name) { md = new mainDlg(this); md->init(); QPopupMenu *file = new QPopupMenu; CHECK_PTR( file ); file->insertItem(i18n("&Save"), md, SLOT(save()) ); file->insertSeparator(); file->insertItem(i18n("&Preferences..."), md, SLOT(properties()) ); file->insertSeparator(); file->insertItem(i18n("&Quit"), md, SLOT(quit()) ); QPopupMenu *user = new QPopupMenu; CHECK_PTR(user); user->insertItem(i18n("&Edit..."), md, SLOT(useredit()) ); user->insertItem(i18n("&Delete..."), md, SLOT(userdel()) ); user->insertItem(i18n("&Add..."), md, SLOT(useradd()) ); user->insertItem(i18n("&Set password..."), md, SLOT(setpwd()) ); QPopupMenu *group = new QPopupMenu; CHECK_PTR(group); group->insertItem(i18n("&Edit..."), md, SLOT(grpedit()) ); group->insertItem(i18n("&Delete..."), md, SLOT(grpdel()) ); group->insertItem(i18n("&Add..."), md, SLOT(grpadd()) ); QString tmp; tmp.sprintf(i18n("KUser version %s\n" "KDE project\n" "This program was created by\n" "Denis Pershin\n" "[email protected]\n" "Copyright 1997(c)"), _KU_VERSION); QPopupMenu *help = kapp->getHelpMenu(true, tmp); menubar = new KMenuBar( this ); CHECK_PTR( menubar ); menubar->insertItem(i18n("&File"), file ); menubar->insertItem(i18n("&User"), user ); menubar->insertItem(i18n("&Group"), group ); menubar->insertSeparator(); menubar->insertItem(i18n("&Help"), help ); setMenu(menubar); toolbar = new KToolBar(this, "toolbar"); QPixmap pix; pix = kapp->getIconLoader()->loadIcon("useradd.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(useradd()), TRUE, i18n("Add user")); pix = kapp->getIconLoader()->loadIcon("userdel.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(userdel()), TRUE, i18n("Delete user")); pix = kapp->getIconLoader()->loadIcon("useredit.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(useredit()), TRUE, i18n("Edit user")); toolbar->insertSeparator(); pix = kapp->getIconLoader()->loadIcon("grpadd.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(grpadd()), TRUE, i18n("Add group")); pix = kapp->getIconLoader()->loadIcon("grpdel.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(grpdel()), TRUE, i18n("Delete group")); pix = kapp->getIconLoader()->loadIcon("grpedit.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(grpedit()), TRUE, i18n("Edit group")); toolbar->setBarPos(KToolBar::Top); addToolBar(toolbar); sbar = new KStatusBar(this); sbar->insertItem("Reading config", 0); setStatusBar(sbar); setView(md); resize(500, 400); // restore geometry settings KConfig *config = KApplication::getKApplication()->getConfig(); config->setGroup( "Appearance" ); QString geom = config->readEntry( "Geometry" ); if (!geom.isEmpty()) { int width, height; sscanf( geom, "%dx%d", &width, &height ); resize( width, height ); } sbar->changeItem(i18n("Ready"), 0); }