summaryrefslogtreecommitdiffstats
path: root/src/responder/nss/nss_private.h
blob: e2f5a3e5a584c093d87e1b034af13bdb9607ae08 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
    Authors:
        Pavel Březina <pbrezina@redhat.com>

    Copyright (C) 2016 Red Hat

    This program is free software; you can redistribute it and/or modify
    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/>.
*/

#ifndef _NSS_PRIVATE_H_
#define _NSS_PRIVATE_H_

#include <talloc.h>
#include <tevent.h>
#include <dhash.h>
#include <ldb.h>

#include "util/util.h"
#include "db/sysdb.h"
#include "responder/common/responder.h"
#include "responder/common/cache_req/cache_req.h"
#include "responder/nss/nsssrv_mmap_cache.h"
#include "lib/idmap/sss_idmap.h"

struct sss_nss_enum_index {
    unsigned int domain;
    unsigned int result;
};

struct sss_nss_enum_ctx {
    struct cache_req_result **result;
    struct sysdb_netgroup_ctx **netgroup;
    size_t netgroup_count;

    /* Ongoing cache request that is constructing enumeration result. */
    struct tevent_req *ongoing;

    /* If true, the object is already constructed. */
    bool is_ready;

    /* List of setent requests awaiting the result. We finish
     * them when the ongoing cache request is completed. */
    struct setent_req_list *notify_list;
};

struct sss_nss_state_ctx {
    struct sss_nss_enum_index pwent;
    struct sss_nss_enum_index grent;
    struct sss_nss_enum_index svcent;
    struct sss_nss_enum_index netgrent;
    struct sss_nss_enum_index hostent;
    struct sss_nss_enum_index netent;

    const char *netgroup;
};

struct sss_nss_ctx {
    struct resp_ctx *rctx;
    struct sss_idmap_ctx *idmap_ctx;

    /* Options. */
    int cache_refresh_percent;
    int enum_cache_timeout;
    bool filter_users_in_groups;
    char *pwfield;
    char *override_homedir;
    char *fallback_homedir;
    char *homedir_substr;
    const char **extra_attributes;
    const char **full_attribute_list;

    /* Enumeration. */
    struct sss_nss_enum_ctx *pwent;
    struct sss_nss_enum_ctx *grent;
    struct sss_nss_enum_ctx *svcent;
    struct sss_nss_enum_ctx *hostent;
    struct sss_nss_enum_ctx *netent;
    hash_table_t *netgrent;

    /* Memory cache. */
    struct sss_mc_ctx *pwd_mc_ctx;
    struct sss_mc_ctx *grp_mc_ctx;
    struct sss_mc_ctx *initgr_mc_ctx;
    struct sss_mc_ctx *sid_mc_ctx;
    uid_t mc_uid;
    gid_t mc_gid;
};

struct sss_cmd_table *get_sss_nss_cmds(void);

int sss_nss_connection_setup(struct cli_ctx *cli_ctx);

errno_t
memcache_delete_entry(struct sss_nss_ctx *nss_ctx,
                      struct resp_ctx *rctx,
                      struct sss_domain_info *domain,
                      const char *name,
                      uint32_t id,
                      enum sss_mc_type type);

struct tevent_req *
sss_nss_get_object_send(TALLOC_CTX *mem_ctx,
                        struct tevent_context *ev,
                        struct cli_ctx *cli_ctx,
                        struct cache_req_data *data,
                        enum sss_mc_type memcache,
                        const char *input_name,
                        uint32_t input_id);

errno_t
sss_nss_get_object_recv(TALLOC_CTX *mem_ctx,
                        struct tevent_req *req,
                        struct cache_req_result **_result,
                        const char **_rawname);

struct tevent_req *
sss_nss_setent_send(TALLOC_CTX *mem_ctx,
                    struct tevent_context *ev,
                    struct cli_ctx *cli_ctx,
                    enum cache_req_type type,
                    struct sss_nss_enum_ctx *enum_ctx);

errno_t
sss_nss_setent_recv(struct tevent_req *req);

struct tevent_req *
sss_nss_setnetgrent_send(TALLOC_CTX *mem_ctx,
                         struct tevent_context *ev,
                         struct cli_ctx *cli_ctx,
                         enum cache_req_type type,
                         hash_table_t *table,
                         const char *netgroup);

/* Utils. */

const char *
sss_nss_get_name_from_msg(struct sss_domain_info *domain,
                          struct ldb_message *msg);

const char *
sss_nss_get_pwfield(struct sss_nss_ctx *nctx,
                    struct sss_domain_info *dom);

#endif /* _NSS_PRIVATE_H_ */