sss_useradd.c revision 7ffaa2afb9e03a6f0b9c602c0f03b2074ea33eac
/*
SSSD
sss_useradd
Copyright (C) Jakub Hrozek <jhrozek@redhat.com> 2009
Copyright (C) Simo Sorce <ssorce@redhat.com> 2009
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <talloc.h>
#include <popt.h>
#include <errno.h>
#include <unistd.h>
#include "tools/tools_util.h"
#include "tools/sss_sync_ops.h"
{
if (error) {
return;
}
case 0:
break;
case 1:
}
break;
default:
break;
}
}
/* Returns a gid for a given groupname. If a numerical gid
* is given, returns that as integer (rationale: shadow-utils)
* On error, returns -EINVAL
*/
{
char *end_ptr;
int ret;
errno = 0;
/* Does not look like a gid - find the group name */
goto done;
}
}
goto done;
}
}
done:
return ret;
}
{
int pc_debug = 0;
int pc_create_home = 0;
const char *pc_username = NULL;
const char *pc_skeldir = NULL;
const char *pc_selinux_user = NULL;
struct poptOption long_options[] = {
{ "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL },
{ "create-home", 'm', POPT_ARG_NONE, NULL, 'm', _("Create user's directory if it does not exist"), NULL },
{ "no-create-home", 'M', POPT_ARG_NONE, NULL, 'M', _("Never create user's directory, overrides config"), NULL },
{ "skel", 'k', POPT_ARG_STRING, &pc_skeldir, 0, _("Specify an alternative skeleton directory"), NULL },
{ "selinux-user", 'Z', POPT_ARG_STRING, &pc_selinux_user, 0, _("The SELinux user for user's login"), NULL },
};
int ret;
debug_prg_name = argv[0];
ret = set_locale();
ERROR("Error setting the locale\n");
ret = EXIT_FAILURE;
goto fini;
}
/* parse parameters */
switch (ret) {
case 'G':
case 'm':
break;
case 'M':
break;
}
}
if (ret != -1) {
ret = EXIT_FAILURE;
goto fini;
}
/* username is an argument without --option */
if (pc_username == NULL) {
ret = EXIT_FAILURE;
goto fini;
}
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 */
ERROR("Invalid domain specified in FQDN\n");
ret = EXIT_FAILURE;
goto fini;
}
if (groups) {
ERROR("Internal error while parsing parameters\n");
ret = EXIT_FAILURE;
goto fini;
}
ERROR("Groups must be in the same domain as user\n");
ret = EXIT_FAILURE;
goto fini;
}
/* Check group names in the LOCAL domain */
ret = EXIT_FAILURE;
goto fini;
}
}
/* Same as shadow-utils useradd, -g can specify gid or group name */
ERROR("Cannot get group information for the user\n");
ret = EXIT_FAILURE;
goto fini;
}
}
/*
* Fills in defaults for ops_ctx user did not specify.
*/
ERROR("Cannot set default values\n");
ret = EXIT_FAILURE;
goto fini;
}
/* arguments processed, go on to actual work */
ERROR("The selected UID is outside the allowed range\n");
ret = EXIT_FAILURE;
goto fini;
}
goto done;
}
/* useradd */
/* cancel transaction */
goto done;
}
goto done;
}
/* Set SELinux login context - must be done after transaction is done
* b/c libselinux calls getpwnam */
ERROR("Cannot set SELinux login context\n");
ret = EXIT_FAILURE;
goto fini;
}
/* We need to know the UID and GID of the user, if
* sysdb did assign it automatically, do a lookup */
ERROR("Cannot get info about the user\n");
ret = EXIT_FAILURE;
goto fini;
}
}
ERROR("User's home directory already exists, not copying "
"data from skeldir\n");
ret = EXIT_FAILURE;
goto fini;
}
ret = EXIT_FAILURE;
goto fini;
}
}
done:
case ERANGE:
ERROR("Could not allocate ID for the user - domain full?\n");
break;
case EEXIST:
ERROR("A user or group with the same name or ID already exists\n");
break;
default:
ERROR("Transaction error. Could not add user.\n");
break;
}
ret = EXIT_FAILURE;
goto fini;
}
ret = EXIT_SUCCESS;
fini:
}