summaryrefslogtreecommitdiffstats
path: root/server/tools/tools_util.h
blob: 772ba36b8c040829ee8b1ab6d352de3d37fcdc96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef __TOOLS_UTIL_H__
#define __TOOLS_UTIL_H__

#include "util/sssd-i18n.h"

#define UID_NOT_SET 0
#define GID_NOT_SET 0

#define APPEND_PARAM(str, param, val) do { \
    if (val) { \
        str = talloc_asprintf_append(str, param, val); \
        if (str == NULL) { \
            return ENOMEM; \
        } \
    } \
} while(0)

#define APPEND_STRING(str, val) do { \
    str = talloc_asprintf_append(str, "%s ", val); \
    if (str == NULL) { \
        return ENOMEM; \
    } \
} while(0)

#define CHECK_ROOT(val, prg_name) do { \
    val = getuid(); \
    if (val != 0) { \
        DEBUG(1, ("Running under %d, must be root\n", val)); \
        ERROR("%s must be run as root\n", prg_name); \
        val = EXIT_FAILURE; \
        goto fini; \
    } \
} while(0)

enum id_domain {
    ID_IN_LOCAL = 0,
    ID_IN_LEGACY_LOCAL,
    ID_IN_OTHER,
    ID_OUTSIDE,
    ID_ERROR
};

struct tools_ctx {
    struct tevent_context *ev;
    struct confdb_ctx *confdb;
    struct sysdb_ctx *sysdb;
    struct sss_names_ctx *snctx;

    struct sss_domain_info *domains;
};

struct ops_ctx {
    struct tools_ctx *ctx;
    struct tevent_context *ev;
    struct sss_domain_info *domain;

    char *name;
    uid_t uid;
    gid_t gid;
    char *gecos;
    char *home;
    char *shell;
    struct sysdb_attrs *attrs;

    char **addgroups;
    char **rmgroups;
    char **groups;
    int cur;

    struct sysdb_handle *handle;
    int error;
    bool done;
};

int init_sss_tools(struct tools_ctx **_ctx);

int setup_db(struct tools_ctx **ctx);

void usage(poptContext pc, const char *error);

int parse_groups(TALLOC_CTX *mem_ctx, const char *optstr, char ***_out);

enum id_domain get_domain_type(struct tools_ctx *ctx,
                               struct sss_domain_info *dom);

int get_domain_by_id(struct tools_ctx *ctx,
                     uint32_t id,
                     struct sss_domain_info **_dom);

int set_locale(void);

int parse_name_domain(struct ops_ctx *octx,
                      const char *fullname);

#endif  /* __TOOLS_UTIL_H__ */