sss_usermod.c revision 9c124af8868a7d3908c03ec369e28daef17d5f12
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens SSSD
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens sss_usermod
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock Copyright (C) Jakub Hrozek <jhrozek@redhat.com> 2009
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens This program is free software; you can redistribute it and/or modify
fa9e4066f08beec538e775443c5be79dd423fcabahrens it under the terms of the GNU General Public License as published by
fa9e4066f08beec538e775443c5be79dd423fcabahrens the Free Software Foundation; either version 3 of the License, or
fa9e4066f08beec538e775443c5be79dd423fcabahrens (at your option) any later version.
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens This program is distributed in the hope that it will be useful,
fa9e4066f08beec538e775443c5be79dd423fcabahrens but WITHOUT ANY WARRANTY; without even the implied warranty of
fa9e4066f08beec538e775443c5be79dd423fcabahrens MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa9e4066f08beec538e775443c5be79dd423fcabahrens GNU General Public License for more details.
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens You should have received a copy of the GNU General Public License
fa9e4066f08beec538e775443c5be79dd423fcabahrens along with this program. If not, see <http://www.gnu.org/licenses/>.
fa9e4066f08beec538e775443c5be79dd423fcabahrens*/
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ac05c741c43aa3e2f9b2f35878d03c299ff80d99Mark Maybee#include <stdio.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <stdlib.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <talloc.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <popt.h>
75c7619736838143dd41b3c5c9d7adec4683488fpeteh#include <errno.h>
75c7619736838143dd41b3c5c9d7adec4683488fpeteh#include <pwd.h>
55434c770c89aa1b84474f2559a106803511aba0ek#include <unistd.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include "util/util.h"
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include "db/sysdb.h"
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include "tools/tools_util.h"
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include "tools/sss_sync_ops.h"
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensint main(int argc, const char **argv)
72fc53bc90bd3b199d29d03ee68adb4a5a17d35bmarks{
de8267e0f723ed2c38ea9def92d465f69a300f56timh int pc_lock = 0;
ab04eb8ef60d9dc9614d6cccffc474f24ca1d162timh uid_t pc_uid = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens gid_t pc_gid = 0;
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsb char *pc_gecos = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens char *pc_home = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens char *pc_shell = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int pc_debug = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens const char *pc_selinux_user = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens struct poptOption long_options[] = {
fa9e4066f08beec538e775443c5be79dd423fcabahrens POPT_AUTOHELP
fa9e4066f08beec538e775443c5be79dd423fcabahrens { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL },
fa9e4066f08beec538e775443c5be79dd423fcabahrens { "uid", 'u', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_uid, 0, _("The UID of the user"), NULL },
fa9e4066f08beec538e775443c5be79dd423fcabahrens { "gid", 'g', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_gid, 0, _("The GID of the user"), NULL },
fa9e4066f08beec538e775443c5be79dd423fcabahrens { "gecos", 'c', POPT_ARG_STRING, &pc_gecos, 0, _("The comment string"), NULL },
fa9e4066f08beec538e775443c5be79dd423fcabahrens { "home", 'h', POPT_ARG_STRING, &pc_home, 0, _("Home directory"), NULL },
fa9e4066f08beec538e775443c5be79dd423fcabahrens { "shell", 's', POPT_ARG_STRING, &pc_shell, 0, _("Login shell"), NULL },
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin { "append-group", 'a', POPT_ARG_STRING, NULL, 'a', _("Groups to add this user to"), NULL },
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw { "remove-group", 'r', POPT_ARG_STRING, NULL, 'r', _("Groups to remove this user from"), NULL },
fa9e4066f08beec538e775443c5be79dd423fcabahrens { "lock", 'L', POPT_ARG_NONE, NULL, 'L', _("Lock the account"), NULL },
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw { "unlock", 'U', POPT_ARG_NONE, NULL, 'U', _("Unlock the account"), NULL },
55434c770c89aa1b84474f2559a106803511aba0ek { "selinux-user", 'Z', POPT_ARG_STRING, &pc_selinux_user, 0, _("The SELinux user for user's login"), NULL },
55434c770c89aa1b84474f2559a106803511aba0ek POPT_TABLEEND
55434c770c89aa1b84474f2559a106803511aba0ek };
55434c770c89aa1b84474f2559a106803511aba0ek poptContext pc = NULL;
55434c770c89aa1b84474f2559a106803511aba0ek char *addgroups = NULL, *rmgroups = NULL;
55434c770c89aa1b84474f2559a106803511aba0ek int ret;
55434c770c89aa1b84474f2559a106803511aba0ek const char *pc_username = NULL;
fa9e4066f08beec538e775443c5be79dd423fcabahrens struct tools_ctx *tctx = NULL;
de8267e0f723ed2c38ea9def92d465f69a300f56timh char *badgroup = NULL;
de8267e0f723ed2c38ea9def92d465f69a300f56timh
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee debug_prg_name = argv[0];
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = set_locale();
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (ret != EOK) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ERROR("Error setting the locale\n");
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = EXIT_FAILURE;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto fini;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* parse parameters */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee pc = poptGetContext(NULL, argc, argv, long_options, 0);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee poptSetOtherOptionHelp(pc, "USERNAME");
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee while ((ret = poptGetNextOpt(pc)) > 0) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee switch (ret) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee case 'a':
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee addgroups = poptGetOptArg(pc);
55434c770c89aa1b84474f2559a106803511aba0ek if (addgroups == NULL) {
55434c770c89aa1b84474f2559a106803511aba0ek ret = -1;
55434c770c89aa1b84474f2559a106803511aba0ek }
55434c770c89aa1b84474f2559a106803511aba0ek break;
55434c770c89aa1b84474f2559a106803511aba0ek
55434c770c89aa1b84474f2559a106803511aba0ek case 'r':
4e9583b23260dab68308b306795694143381ab0fTom Erickson rmgroups = poptGetOptArg(pc);
4e9583b23260dab68308b306795694143381ab0fTom Erickson if (rmgroups == NULL) {
4e9583b23260dab68308b306795694143381ab0fTom Erickson ret = -1;
4e9583b23260dab68308b306795694143381ab0fTom Erickson }
4e9583b23260dab68308b306795694143381ab0fTom Erickson break;
4e9583b23260dab68308b306795694143381ab0fTom Erickson
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee case 'L':
fa9e4066f08beec538e775443c5be79dd423fcabahrens pc_lock = DO_LOCK;
fa9e4066f08beec538e775443c5be79dd423fcabahrens break;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee case 'U':
fa9e4066f08beec538e775443c5be79dd423fcabahrens pc_lock = DO_UNLOCK;
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee break;
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee }
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee }
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee
874395d5f8cae2b9cd2d1fcbfcfe963a0c23966dmaybee if (ret != -1) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens usage(pc, poptStrerror(ret));
fa9e4066f08beec538e775443c5be79dd423fcabahrens ret = EXIT_FAILURE;
fa9e4066f08beec538e775443c5be79dd423fcabahrens goto fini;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
fa9e4066f08beec538e775443c5be79dd423fcabahrens debug_level = pc_debug;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* username is an argument without --option */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee pc_username = poptGetArg(pc);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (pc_username == NULL) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee usage(pc, _("Specify user to modify\n"));
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = EXIT_FAILURE;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto fini;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee CHECK_ROOT(ret, debug_prg_name);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = init_sss_tools(&tctx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ret != EOK) {
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
af2c4821c0a23e873f2a63bca4145080aa2183e3maybee if (ret == ENOENT) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens ERROR("Error initializing the tools - no local domain\n");
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin } else {
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin ERROR("Error initializing the tools\n");
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin }
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin ret = EXIT_FAILURE;
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin goto fini;
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* if the domain was not given as part of FQDN, default to local domain */
fa9e4066f08beec538e775443c5be79dd423fcabahrens ret = parse_name_domain(tctx, pc_username);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ret != EOK) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens ERROR("Invalid domain specified in FQDN\n");
fa9e4066f08beec538e775443c5be79dd423fcabahrens ret = EXIT_FAILURE;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto fini;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* check the username to be able to give sensible error message */
fa9e4066f08beec538e775443c5be79dd423fcabahrens ret = sysdb_getpwnam_sync(tctx, tctx->ev, tctx->sysdb,
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee tctx->octx->name, tctx->local,
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee &tctx->octx);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (ret != EOK) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ERROR("Cannot find user in local domain, "
fa9e4066f08beec538e775443c5be79dd423fcabahrens "modifying users is allowed only in local domain\n");
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin ret = EXIT_FAILURE;
af2c4821c0a23e873f2a63bca4145080aa2183e3maybee goto fini;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
104e2ed78d9ef0a0f89f320108b8ca29ca3850d5perrin
c25056de36a33f2a76f79dcf64593f731d258013gw if (id_in_range(tctx->octx->uid, tctx->octx->domain) != EOK) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens ERROR("The selected UID is outside the allowed range\n");
4ccbb6e737373468bb9dc1709618384cce4c9f92ahrens ret = EXIT_FAILURE;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto fini;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (addgroups) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = parse_groups(tctx, addgroups, &tctx->octx->addgroups);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (ret != EOK) {
4e9583b23260dab68308b306795694143381ab0fTom Erickson DEBUG(1, ("Cannot parse groups to add the user to\n"));
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ERROR("Internal error while parsing parameters\n");
4e9583b23260dab68308b306795694143381ab0fTom Erickson ret = EXIT_FAILURE;
a66b2b3504619207b55d222c87bdd9df52832f15Tom Erickson goto fini;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
a66b2b3504619207b55d222c87bdd9df52832f15Tom Erickson
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = parse_group_name_domain(tctx, tctx->octx->addgroups);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (ret != EOK) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee DEBUG(1, ("Cannot parse FQDN groups to add the user to\n"));
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ERROR("Groups must be in the same domain as user\n");
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = EXIT_FAILURE;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto fini;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* Check group names in the LOCAL domain */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = check_group_names(tctx, tctx->octx->addgroups, &badgroup);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (ret != EOK) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ERROR("Cannot find group %s in local domain, "
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee "only groups in local domain are allowed\n", badgroup);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = EXIT_FAILURE;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto fini;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (rmgroups) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = parse_groups(tctx, rmgroups, &tctx->octx->rmgroups);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (ret != EOK) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee DEBUG(1, ("Cannot parse groups to remove the user from\n"));
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ERROR("Internal error while parsing parameters\n");
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = EXIT_FAILURE;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto fini;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = parse_group_name_domain(tctx, tctx->octx->rmgroups);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (ret != EOK) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee DEBUG(1, ("Cannot parse FQDN groups to remove the user from\n"));
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ERROR("Groups must be in the same domain as user\n");
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = EXIT_FAILURE;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto fini;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* Check group names in the LOCAL domain */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = check_group_names(tctx, tctx->octx->rmgroups, &badgroup);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (ret != EOK) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ERROR("Cannot find group %s in local domain, "
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee "only groups in local domain are allowed\n", badgroup);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = EXIT_FAILURE;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto fini;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee tctx->octx->gecos = pc_gecos;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee tctx->octx->home = pc_home;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee tctx->octx->shell = pc_shell;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee tctx->octx->uid = pc_uid;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee tctx->octx->gid = pc_gid;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee tctx->octx->lock = pc_lock;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee start_transaction(tctx);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (tctx->error != EOK) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto done;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* usermod */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = usermod(tctx, tctx->ev, tctx->sysdb, tctx->handle, tctx->octx);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee if (ret != EOK) {
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee tctx->error = ret;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* cancel transaction */
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee talloc_zfree(tctx->handle);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto done;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee end_transaction(tctx);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee /* Set SELinux login context - must be done after transaction is done
4e9583b23260dab68308b306795694143381ab0fTom Erickson * b/c libselinux calls getpwnam */
4e9583b23260dab68308b306795694143381ab0fTom Erickson ret = set_seuser(tctx->octx->name, pc_selinux_user);
4e9583b23260dab68308b306795694143381ab0fTom Erickson if (ret != EOK) {
4e9583b23260dab68308b306795694143381ab0fTom Erickson ERROR("Cannot set SELinux login context\n");
4e9583b23260dab68308b306795694143381ab0fTom Erickson ret = EXIT_FAILURE;
4e9583b23260dab68308b306795694143381ab0fTom Erickson goto fini;
4e9583b23260dab68308b306795694143381ab0fTom Erickson }
4e9583b23260dab68308b306795694143381ab0fTom Erickson
4e9583b23260dab68308b306795694143381ab0fTom Ericksondone:
4e9583b23260dab68308b306795694143381ab0fTom Erickson if (tctx->error) {
4e9583b23260dab68308b306795694143381ab0fTom Erickson ret = tctx->error;
4e9583b23260dab68308b306795694143381ab0fTom Erickson switch (ret) {
4e9583b23260dab68308b306795694143381ab0fTom Erickson case ENOENT:
4e9583b23260dab68308b306795694143381ab0fTom Erickson ERROR("Could not modify user - check if group names are correct\n");
4e9583b23260dab68308b306795694143381ab0fTom Erickson break;
4e9583b23260dab68308b306795694143381ab0fTom Erickson
4e9583b23260dab68308b306795694143381ab0fTom Erickson case EFAULT:
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ERROR("Could not modify user - user already member of groups?\n");
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens break;
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens default:
4e9583b23260dab68308b306795694143381ab0fTom Erickson ERROR("Transaction error. Could not modify user.\n");
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee break;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
4e9583b23260dab68308b306795694143381ab0fTom Erickson ret = EXIT_FAILURE;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee goto fini;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee }
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee ret = EXIT_SUCCESS;
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee
b5fca8f855054d167d04d3b4de5210c83ed2083ctomeefini:
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee free(addgroups);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee free(rmgroups);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee poptFreeContext(pc);
4e9583b23260dab68308b306795694143381ab0fTom Erickson talloc_free(tctx);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee exit(ret);
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee}
b5fca8f855054d167d04d3b4de5210c83ed2083ctomee