6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay prompt = talloc_asprintf(NULL, _("Enter %s:"), req);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay len = sss_atomic_write_s(STDOUT_FILENO, &prompt[i++], 1);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "write failed [%d][%s].\n",
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char *req,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay while ((bytes_read = sss_atomic_read_s(STDIN_FILENO, buf+len, 1)) != 0) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "read failed [%d][%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to allocate input\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay while ((bytes_read = sss_atomic_read_s(STDIN_FILENO, buf+len, 1)) != 0) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "read failed [%d][%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "strtoll failed on [%s]: [%d][%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "extra characters [%s] after ID [%"SPRIuid"]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to get %s input.\n", req);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_password_input_prompt(TALLOC_CTX *mem_ctx, char **_password)
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not allocate temp context\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to get prompted password\n");
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek /* Do not allow empty passwords */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_set_destructor((TALLOC_CTX *)password, password_destructor);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay temp = getpass("Enter temporary password again:");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to get prompted password\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (strncmp(temp,password,strlen(password)) != 0) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Provided passwords do not match\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_password_input_file(TALLOC_CTX *mem_ctx,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not allocate temp context\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to open password file "
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay "[%s] [%d][%s]\n",
f0f2ac9ee5a0b83806899cc3636941acb87bbccfMichal Zidek len = sss_atomic_read_s(fd, buf, PASS_MAX + 1);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Failed to read password from file "
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay "[%s] [%d][%s]\n",
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek /* Only the first line is valid (without '\n'). */
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek for (valid_i = -1; valid_i + 1 < len; valid_i++) {
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek /* Do not allow empty passwords. */
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek /* valid_i is the last valid index of the password followed by \0.
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek * If characters other than \n occur int the rest of the file, it
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek * is an error. */
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek ERROR("Multi-line passwords are not allowed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_interactive_input(TALLOC_CTX *mem_ctx,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_str_input(input_uctx, _("username"), &input_uctx->name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Username interactive input failed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx->name = talloc_strdup(input_uctx, uctx->name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "UID interactive input failed.\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "GID interactive input failed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_str_input(input_uctx, _("user comment (gecos)"),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Gecos interactive input failed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx->gecos = talloc_strdup(input_uctx, uctx->gecos);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_str_input(input_uctx, _("home directory"),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Home directory interactive input fialed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx->home = talloc_strdup(input_uctx, uctx->home);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_str_input(input_uctx, _("user login shell"),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Shell interactive input failed\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx->shell = talloc_strdup(input_uctx, uctx->shell);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char **argv,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "domain", 'D', POPT_ARG_STRING, &pc_domain, 0, _("Domain"), NULL },
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "username", 'n', POPT_ARG_STRING, &pc_name, 0, _("Username"), NULL},
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "uid", 'u', POPT_ARG_INT, &pc_uid, 0, _("User UID"), NULL },
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "gid", 'g', POPT_ARG_INT, &pc_gid, 0, _("User GID"), NULL },
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "shell", 's', POPT_ARG_STRING, &pc_shell, 0, _("Login Shell"), NULL },
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay _("Use interactive mode to enter user data"), NULL },
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "password-file", 'p', POPT_ARG_STRING, &pc_password_file, 0,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay _("File from which user's password is read "
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* init contexts */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not allocate tools context\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not allocate user data context\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "set_locale failed (%d): %s\n",
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* parse arguments */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay pc = poptGetContext(NULL, argc, argv, options, 0);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay poptSetOtherOptionHelp(pc, "[OPTIONS] -D <domain> -n <username>");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Interactive mode selected\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* check username provided */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay BAD_POPT_PARAMS(pc, _("Username must be specified\n"), ret, fini);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* check domain is provided */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay BAD_POPT_PARAMS(pc, _("Domain must be specified.\n"), ret, fini);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->domain_name = talloc_strdup(sctx->uctx, pc_domain);
6181113ea79806a414aadc580e6e241a6b317763Jakub Hrozek sctx->uctx->name = sss_create_internal_fqname(sctx->uctx,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* copy all information provided from popt */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->gecos = talloc_strdup(sctx->uctx, pc_gecos);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->home = talloc_strdup(sctx->uctx, pc_home);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->shell = talloc_strdup(sctx->uctx, pc_shell);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* check if password file provided */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->password_file = talloc_strdup(sctx, pc_password_file);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* setup confdb */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay confdb_path = talloc_asprintf(tmp_ctx, "%s/%s", DB_PATH, CONFDB_FILE);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not initialize connection to the confdb\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ERROR("Could not initialize connection to the confdb\n");
234958be042980242fff6da936af674da877c5efSimo Sorce ret = sssd_domain_init(tmp_ctx, confdb, domain_name, DB_PATH, &domain);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not initialize connection to domain '%s' in sysdb.%s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov domain_name, ret == ENOENT ? " Domain not found." : "");
495571b649deec07e80a5b21e7081351dc623e7bMichal Zidek ERROR("Could not initialize connection to domain '%1$s' in sysdb.%2$s\n",
495571b649deec07e80a5b21e7081351dc623e7bMichal Zidek domain_name, ret == ENOENT ? " Domain not found." : "");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "getpwnam failed [%d] [%s]\n",
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* look for user in cache */
b3292840ebaa747a9fd596ff47cc5d18198361d0Michal Zidek ret = sysdb_getpwnam(tmp_ctx, domain, name, &res);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Couldn't lookup user (%s) in the cache\n", name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "User (%s) wasn't found in the cache\n", name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Multiple user (%s) entries were found in the cache\n", name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "User found in cache\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "initgroups failed [%d] [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to allocate user information\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sysdb transaction start failure\n");
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_add_user(sctx->domain, sctx->uctx->name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to add user to the cache. (%d)[%s]\n",
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_cache_password(sctx->domain, sctx->uctx->name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to cache password. (%d)[%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sysdb transaction commit failure\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (in_transaction == true) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to cancel transaction\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* initialize seed context and parse options */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE,"Seed init failed [%d][%s]\n",
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* set up confdb,sysdb and domain */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_init_db(sctx, sctx->uctx->domain_name, &sctx->confdb,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to initialize db and domain\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* get user info from domain */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_domain_user_info(sctx->uctx->name, sctx->uctx->domain_name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed lookup of user [%s] in domain [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov sctx->uctx->name, sctx->uctx->domain_name);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* interactive mode to fill in user information */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ERROR(_("User entry already exists in the cache.\n"));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_interactive_input(sctx, sctx->uctx, &input_uctx);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to get seed input.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->uctx->uid == 0 || sctx->uctx->gid == 0) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* require username, UID, and GID to continue */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Not enough information provided\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* password input */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_password_input_file(sctx->uctx, sctx->password_file,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Password input failure\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_password_input_prompt(sctx->uctx, &sctx->uctx->password);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Password input failure\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* Add user info and password to sysdb cache */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Failed to modify cache.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay printf(_("User cache entry created for %1$s\n"), sctx->uctx->name);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay printf(_("Temporary password added to cache entry for %1$s\n"),
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Exit error: [%d] [%s]\n",