6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <stdio.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <stdlib.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <string.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <talloc.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <popt.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <errno.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <unistd.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <limits.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <grp.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <pwd.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <sys/types.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <sys/stat.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <fcntl.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include <ctype.h>
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include "util/util.h"
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include "db/sysdb.h"
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include "tools/tools_util.h"
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include "tools/sss_sync_ops.h"
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#include "confdb/confdb.h"
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#ifndef BUFSIZE
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#define BUFSIZE 1024
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#endif
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#ifndef PASS_MAX
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#define PASS_MAX 64
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay#endif
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guayenum seed_pass_method {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay PASS_PROMPT,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay PASS_FILE
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay};
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystruct user_ctx {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *domain_name;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *name;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay uid_t uid;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay gid_t gid;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *gecos;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *home;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *shell;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *password;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay};
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystruct seed_ctx {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct confdb_ctx *confdb;
58fd3aa25c5292bc67432647ab7e5059439fcc6dSimo Sorce struct sss_domain_info *domain;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct sysdb_ctx *sysdb;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct user_ctx *uctx;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *password_file;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay enum seed_pass_method password_method;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay bool interact;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay bool user_cached;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay};
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_prompt(const char *req)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
8e44ddfccebe61728d8a2c1dafce36dfa944bc90Jakub Hrozek ssize_t len = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay size_t i = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *prompt = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay prompt = talloc_asprintf(NULL, _("Enter %s:"), req);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (prompt == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay while (prompt[i] != '\0') {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay errno = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay len = sss_atomic_write_s(STDOUT_FILENO, &prompt[i++], 1);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (len == -1) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = errno;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "write failed [%d][%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaydone:
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_free(prompt);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_str_input(TALLOC_CTX *mem_ctx,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char *req,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char **_input)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char buf[BUFSIZE+1];
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay size_t len = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay size_t bytes_read = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_prompt(req);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay errno = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay while ((bytes_read = sss_atomic_read_s(STDIN_FILENO, buf+len, 1)) != 0) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (bytes_read == -1) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = errno;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "read failed [%d][%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (buf[len] == '\n' || len == BUFSIZE) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay buf[len] = '\0';
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay break;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay len += bytes_read;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay *_input = talloc_strdup(mem_ctx, buf);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (*_input == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to allocate input\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_id_input(const char *req,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay uid_t *_id_input)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char buf[BUFSIZE+1];
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay size_t len = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay size_t bytes_read = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *endptr = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_prompt(req);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay errno = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay while ((bytes_read = sss_atomic_read_s(STDIN_FILENO, buf+len, 1)) != 0) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (bytes_read == -1) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = errno;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "read failed [%d][%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (buf[len] == '\n' || len == BUFSIZE) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay buf[len] = '\0';
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay break;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay len += bytes_read;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (isdigit(*buf)) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay errno = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay *_id_input = (uid_t)strtoll(buf, &endptr, 10);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (errno != 0) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = errno;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "strtoll failed on [%s]: [%d][%s].\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov (char *)buf, ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (*endptr != '\0') {
f2c346eaa486431ffa2a3adc05356159de834e2eLukas Slebodnik DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "extra characters [%s] after ID [%"SPRIuid"]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov endptr, *_id_input);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EINVAL;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to get %s input.\n", req);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_password_input_prompt(TALLOC_CTX *mem_ctx, char **_password)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay TALLOC_CTX *tmp_ctx = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *password = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *temp = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay tmp_ctx = talloc_new(NULL);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (tmp_ctx == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not allocate temp context\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay temp = getpass("Enter temporary password:");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (temp == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to get prompted password\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EINVAL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek /* Do not allow empty passwords */
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek if (strlen(temp) == 0) {
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek ERROR("Empty passwords are not allowed.\n");
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek ret = EINVAL;
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek goto done;
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek }
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay password = talloc_strdup(tmp_ctx, temp);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (password == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_set_destructor((TALLOC_CTX *)password, password_destructor);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay temp = getpass("Enter temporary password again:");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (temp == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to get prompted password\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EINVAL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (strncmp(temp,password,strlen(password)) != 0) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ERROR("Passwords do not match\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Provided passwords do not match\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EINVAL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay *_password = talloc_steal(mem_ctx, password);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaydone:
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_free(tmp_ctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_password_input_file(TALLOC_CTX *mem_ctx,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *filename,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char **_password)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay TALLOC_CTX *tmp_ctx = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *password = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int len = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay uint8_t buf[PASS_MAX+1];
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int fd = -1;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek int valid_i;
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek int i;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay tmp_ctx = talloc_new(NULL);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (tmp_ctx == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not allocate temp context\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay fd = open(filename, O_RDONLY);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (fd == -1) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to open password file "
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay "[%s] [%d][%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov filename, errno, strerror(errno));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EINVAL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay errno = 0;
f0f2ac9ee5a0b83806899cc3636941acb87bbccfMichal Zidek len = sss_atomic_read_s(fd, buf, PASS_MAX + 1);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (len == -1) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = errno;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Failed to read password from file "
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay "[%s] [%d][%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov filename, ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay close(fd);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay close(fd);
f0f2ac9ee5a0b83806899cc3636941acb87bbccfMichal Zidek
f0f2ac9ee5a0b83806899cc3636941acb87bbccfMichal Zidek if (len > PASS_MAX) {
f0f2ac9ee5a0b83806899cc3636941acb87bbccfMichal Zidek ERROR("Password file too big.\n");
f0f2ac9ee5a0b83806899cc3636941acb87bbccfMichal Zidek ret = EINVAL;
f0f2ac9ee5a0b83806899cc3636941acb87bbccfMichal Zidek goto done;
f0f2ac9ee5a0b83806899cc3636941acb87bbccfMichal Zidek }
f0f2ac9ee5a0b83806899cc3636941acb87bbccfMichal Zidek
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay buf[len] = '\0';
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek /* Only the first line is valid (without '\n'). */
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek for (valid_i = -1; valid_i + 1 < len; valid_i++) {
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek if (buf[valid_i + 1] == '\n') {
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek buf[valid_i + 1] = '\0';
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek break;
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek }
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek }
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek /* Do not allow empty passwords. */
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek if (valid_i < 0) {
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek ERROR("Empty passwords are not allowed.\n");
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek ret = EINVAL;
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek goto done;
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek }
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek
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 for (i = valid_i + 2; i < len; i++) {
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek if (buf[i] != '\n') {
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek ERROR("Multi-line passwords are not allowed.\n");
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek ret = EINVAL;
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek goto done;
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek }
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek }
2be3f0fb6f38042386975111a1e86e7b5850ac85Michal Zidek
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay password = talloc_strdup(tmp_ctx, (char *)buf);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (password == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay *_password = talloc_steal(mem_ctx, password);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaydone:
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_free(tmp_ctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_interactive_input(TALLOC_CTX *mem_ctx,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct user_ctx *uctx,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct user_ctx **_uctx)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct user_ctx *input_uctx = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx = talloc_zero(NULL, struct user_ctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (input_uctx == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (uctx->name == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_str_input(input_uctx, _("username"), &input_uctx->name);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Username interactive input failed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx->name = talloc_strdup(input_uctx, uctx->name);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (input_uctx->name == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (uctx->uid == 0) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_id_input(_("UID"), &input_uctx->uid);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "UID interactive input failed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx->uid = uctx->uid;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (uctx->gid == 0) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_id_input(_("GID"), &input_uctx->gid);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "GID interactive input failed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx->gid = uctx->gid;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (uctx->gecos == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_str_input(input_uctx, _("user comment (gecos)"),
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay &input_uctx->gecos);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Gecos interactive input failed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx->gecos = talloc_strdup(input_uctx, uctx->gecos);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (input_uctx->gecos == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (uctx->home == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_str_input(input_uctx, _("home directory"),
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay &input_uctx->home);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Home directory interactive input fialed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx->home = talloc_strdup(input_uctx, uctx->home);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (input_uctx->home == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (uctx->shell == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_str_input(input_uctx, _("user login shell"),
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay &input_uctx->shell);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Shell interactive input failed\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay input_uctx->shell = talloc_strdup(input_uctx, uctx->shell);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (input_uctx->shell == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaydone:
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret == EOK) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay *_uctx = talloc_steal(mem_ctx, input_uctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
799f04e2ccd434ea51e5c7f59c5d83210c220c90Michal Zidek ERROR("Interactive input failed.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_zfree(input_uctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_init(TALLOC_CTX *mem_ctx,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const int argc,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char **argv,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct seed_ctx **_sctx)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay TALLOC_CTX *tmp_ctx = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int pc_debug = SSSDBG_DEFAULT;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char *pc_domain = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char *pc_name = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay uid_t pc_uid = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay gid_t pc_gid = 0;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char *pc_gecos = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char *pc_home = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char *pc_shell = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char *pc_password_file = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct seed_ctx *sctx = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay poptContext pc = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct poptOption options[] = {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay POPT_AUTOHELP
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay _("The debug level to run with"), NULL },
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 { "gecos", 'c', POPT_ARG_STRING, &pc_gecos, 0,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay _("Comment string"), NULL},
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "home", 'h', POPT_ARG_STRING, &pc_home, 0,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay _("Home directory"), NULL },
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "shell", 's', POPT_ARG_STRING, &pc_shell, 0, _("Login Shell"), NULL },
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay { "interactive", 'i', POPT_ARG_NONE, NULL, 'i',
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 "(default is to prompt for password)"),NULL },
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay POPT_TABLEEND
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay };
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* init contexts */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay tmp_ctx = talloc_new(NULL);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (tmp_ctx == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto fini;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx = talloc_zero(tmp_ctx, struct seed_ctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not allocate tools context\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto fini;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx = talloc_zero(sctx, struct user_ctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->uctx == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not allocate user data context\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto fini;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay debug_prg_name = argv[0];
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = set_locale();
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "set_locale failed (%d): %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ERROR("Error setting the locale\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EINVAL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto fini;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* parse arguments */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay pc = poptGetContext(NULL, argc, argv, options, 0);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (argc < 2) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay poptPrintUsage(pc,stderr,0);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EINVAL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto fini;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay poptSetOtherOptionHelp(pc, "[OPTIONS] -D <domain> -n <username>");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay while ((ret = poptGetNextOpt(pc)) > 0) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay switch (ret) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay case 'i':
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Interactive mode selected\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->interact = true;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay break;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != -1) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(pc_debug);
a004873f367b026fd033d4aa0bfa4225555c346eMichal Zidek
a004873f367b026fd033d4aa0bfa4225555c346eMichal Zidek CHECK_ROOT(ret, argv[0]);
a004873f367b026fd033d4aa0bfa4225555c346eMichal Zidek
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* check username provided */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (pc_name == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay BAD_POPT_PARAMS(pc, _("Username must be specified\n"), ret, fini);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* check domain is provided */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (pc_domain == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay BAD_POPT_PARAMS(pc, _("Domain must be specified.\n"), ret, fini);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->domain_name = talloc_strdup(sctx->uctx, pc_domain);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->uctx->domain_name == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto fini;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6181113ea79806a414aadc580e6e241a6b317763Jakub Hrozek sctx->uctx->name = sss_create_internal_fqname(sctx->uctx,
6181113ea79806a414aadc580e6e241a6b317763Jakub Hrozek pc_name, pc_domain);
6181113ea79806a414aadc580e6e241a6b317763Jakub Hrozek if (sctx->uctx->name == NULL) {
6181113ea79806a414aadc580e6e241a6b317763Jakub Hrozek ret = ENOMEM;
6181113ea79806a414aadc580e6e241a6b317763Jakub Hrozek goto fini;
6181113ea79806a414aadc580e6e241a6b317763Jakub Hrozek }
6181113ea79806a414aadc580e6e241a6b317763Jakub Hrozek
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay poptFreeContext(pc);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EOK;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* copy all information provided from popt */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->uid = pc_uid;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->gid = pc_gid;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (pc_gecos != NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->gecos = talloc_strdup(sctx->uctx, pc_gecos);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->uctx->gecos == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto fini;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (pc_home != NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->home = talloc_strdup(sctx->uctx, pc_home);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->uctx->home == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto fini;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (pc_shell != NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->shell = talloc_strdup(sctx->uctx, pc_shell);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->uctx->shell == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto fini;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* check if password file provided */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (pc_password_file != NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->password_file = talloc_strdup(sctx, pc_password_file);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->password_file == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto fini;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->password_method = PASS_FILE;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->password_method = PASS_PROMPT;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay *_sctx = talloc_steal(mem_ctx, sctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guayfini:
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_free(tmp_ctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_init_db(TALLOC_CTX *mem_ctx,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char *domain_name,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct confdb_ctx **_confdb,
58fd3aa25c5292bc67432647ab7e5059439fcc6dSimo Sorce struct sss_domain_info **_domain,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct sysdb_ctx **_sysdb)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay TALLOC_CTX *tmp_ctx = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay char *confdb_path = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct confdb_ctx *confdb = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct sss_domain_info *domain = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay tmp_ctx = talloc_new(NULL);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (tmp_ctx == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* setup confdb */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay confdb_path = talloc_asprintf(tmp_ctx, "%s/%s", DB_PATH, CONFDB_FILE);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (confdb_path == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = confdb_init(tmp_ctx, &confdb, confdb_path);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not initialize connection to the confdb\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ERROR("Could not initialize connection to the confdb\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
234958be042980242fff6da936af674da877c5efSimo Sorce ret = sssd_domain_init(tmp_ctx, confdb, domain_name, DB_PATH, &domain);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
4c9a85ab708ec7debecad51e4240e04d8bc6ca4eOndrej Kos SYSDB_VERSION_ERROR(ret);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay DEBUG(SSSDBG_CRIT_FAILURE,
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." : "");
495571b649deec07e80a5b21e7081351dc623e7bMichal Zidek
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay *_confdb = talloc_steal(mem_ctx, confdb);
58fd3aa25c5292bc67432647ab7e5059439fcc6dSimo Sorce *_domain = domain;
234958be042980242fff6da936af674da877c5efSimo Sorce *_sysdb = domain->sysdb;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaydone:
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_free(tmp_ctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_domain_user_info(const char *name,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay const char *domain_name,
58fd3aa25c5292bc67432647ab7e5059439fcc6dSimo Sorce struct sss_domain_info *domain,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay bool *is_cached)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay TALLOC_CTX *tmp_ctx = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct passwd *passwd = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct ldb_result *res = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay tmp_ctx = talloc_new(NULL);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (tmp_ctx == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOMEM;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay errno = 0;
6181113ea79806a414aadc580e6e241a6b317763Jakub Hrozek passwd = getpwnam(name);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (passwd == NULL) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = errno;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "getpwnam failed [%d] [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* look for user in cache */
b3292840ebaa747a9fd596ff47cc5d18198361d0Michal Zidek ret = sysdb_getpwnam(tmp_ctx, domain, name, &res);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Couldn't lookup user (%s) in the cache\n", name);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (res->count == 0) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "User (%s) wasn't found in the cache\n", name);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay *is_cached = false;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = ENOENT;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else if (res->count > 1) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Multiple user (%s) entries were found in the cache\n", name);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EINVAL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "User found in cache\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay *is_cached = true;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay errno = 0;
6181113ea79806a414aadc580e6e241a6b317763Jakub Hrozek ret = initgroups(name, passwd->pw_gid);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = errno;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "initgroups failed [%d] [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaydone:
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret == ENOMEM) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to allocate user information\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_zfree(tmp_ctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaystatic int seed_cache_user(struct seed_ctx *sctx)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay bool in_transaction = false;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek errno_t sret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = sysdb_transaction_start(sctx->sysdb);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sysdb transaction start failure\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay in_transaction = true;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->user_cached == false) {
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_add_user(sctx->domain, sctx->uctx->name,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->uid, sctx->uctx->gid,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->gecos, sctx->uctx->home,
8455d5ab61184e0d126fc074a9ce6e98391eb909Jakub Hrozek sctx->uctx->shell, NULL, NULL, 0, 0);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to add user to the cache. (%d)[%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ERROR("Failed to create user cache entry\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_cache_password(sctx->domain, sctx->uctx->name,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->password);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to cache password. (%d)[%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ERROR("Failed to cache password\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = sysdb_transaction_commit(sctx->sysdb);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sysdb transaction commit failure\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay in_transaction = false;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaydone:
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (in_transaction == true) {
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek sret = sysdb_transaction_cancel(sctx->sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (sret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Failed to cancel transaction\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay return ret;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guayint main(int argc, const char **argv)
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay{
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct seed_ctx *sctx = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay struct user_ctx *input_uctx = NULL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay int ret = EOK;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* initialize seed context and parse options */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_init(sctx, argc, argv, &sctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE,"Seed init failed [%d][%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* set up confdb,sysdb and domain */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_init_db(sctx, sctx->uctx->domain_name, &sctx->confdb,
58fd3aa25c5292bc67432647ab7e5059439fcc6dSimo Sorce &sctx->domain, &sctx->sysdb);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to initialize db and domain\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* get user info from domain */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_domain_user_info(sctx->uctx->name, sctx->uctx->domain_name,
2e7fb99c9ff68ae89a79a5fc5d52039adb640410Lukas Slebodnik sctx->domain, &sctx->user_cached);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
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 }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* interactive mode to fill in user information */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->interact == true) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->user_cached == true) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ERROR(_("User entry already exists in the cache.\n"));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EEXIST;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_interactive_input(sctx, sctx->uctx, &input_uctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to get seed input.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EINVAL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_zfree(sctx->uctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx = input_uctx;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->user_cached == false) {
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 ERROR("UID and primary GID not provided.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EINVAL;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* password input */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->password_method == PASS_FILE) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_password_input_file(sctx->uctx, sctx->password_file,
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay &sctx->uctx->password);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Password input failure\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_password_input_prompt(sctx->uctx, &sctx->uctx->password);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Password input failure\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay /* Add user info and password to sysdb cache */
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = seed_cache_user(sctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Failed to modify cache.\n");
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay goto done;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (sctx->user_cached == false) {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay printf(_("User cache entry created for %1$s\n"), sctx->uctx->name);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay printf(_("Temporary password added to cache entry for %1$s\n"),
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay sctx->uctx->name);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guaydone:
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay talloc_zfree(sctx);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Exit error: [%d] [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EXIT_FAILURE;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay } else {
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay ret = EXIT_SUCCESS;
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay }
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay exit(ret);
6ea6ec5cb7d9985e2730fb9d4657624d10aed4d8Nick Guay}