w3:winbind: Convert WINBINDD_ALLOCATE_GID to the new API
[Samba/aatanasov.git] / source3 / winbindd / winbindd_sid.c
blob80d4677d7555eed2730c3af7cb2eeefb87add2db
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind daemon - sid related functions
6 Copyright (C) Tim Potter 2000
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "winbindd.h"
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_WINBIND
28 static void set_mapping_recv(void *private_data, bool success)
30 struct winbindd_cli_state *state =
31 talloc_get_type_abort(private_data, struct winbindd_cli_state);
33 if (!success) {
34 DEBUG(5, ("Could not set sid mapping\n"));
35 request_error(state);
36 return;
39 request_ok(state);
42 void winbindd_set_mapping(struct winbindd_cli_state *state)
44 struct id_map map;
45 DOM_SID sid;
47 DEBUG(3, ("[%5lu]: set id map\n", (unsigned long)state->pid));
49 if ( ! state->privileged) {
50 DEBUG(0, ("Only root is allowed to set mappings!\n"));
51 request_error(state);
52 return;
55 if (!string_to_sid(&sid, state->request->data.dual_idmapset.sid)) {
56 DEBUG(1, ("Could not get convert sid %s from string\n",
57 state->request->data.sid));
58 request_error(state);
59 return;
62 map.sid = &sid;
63 map.xid.id = state->request->data.dual_idmapset.id;
64 map.xid.type = state->request->data.dual_idmapset.type;
66 winbindd_set_mapping_async(state->mem_ctx, &map,
67 set_mapping_recv, state);
70 static void remove_mapping_recv(void *private_data, bool success)
72 struct winbindd_cli_state *state =
73 talloc_get_type_abort(private_data, struct winbindd_cli_state);
75 if (!success) {
76 DEBUG(5, ("Could not remove sid mapping\n"));
77 request_error(state);
78 return;
81 request_ok(state);
84 void winbindd_remove_mapping(struct winbindd_cli_state *state)
86 struct id_map map;
87 DOM_SID sid;
89 DEBUG(3, ("[%5lu]: remove id map\n", (unsigned long)state->pid));
91 if ( ! state->privileged) {
92 DEBUG(0, ("Only root is allowed to remove mappings!\n"));
93 request_error(state);
94 return;
97 if (!string_to_sid(&sid, state->request->data.dual_idmapset.sid)) {
98 DEBUG(1, ("Could not get convert sid %s from string\n",
99 state->request->data.sid));
100 request_error(state);
101 return;
104 map.sid = &sid;
105 map.xid.id = state->request->data.dual_idmapset.id;
106 map.xid.type = state->request->data.dual_idmapset.type;
108 winbindd_remove_mapping_async(state->mem_ctx, &map,
109 remove_mapping_recv, state);
112 static void set_hwm_recv(void *private_data, bool success)
114 struct winbindd_cli_state *state =
115 talloc_get_type_abort(private_data, struct winbindd_cli_state);
117 if (!success) {
118 DEBUG(5, ("Could not set sid mapping\n"));
119 request_error(state);
120 return;
123 request_ok(state);
126 void winbindd_set_hwm(struct winbindd_cli_state *state)
128 struct unixid xid;
130 DEBUG(3, ("[%5lu]: set hwm\n", (unsigned long)state->pid));
132 if ( ! state->privileged) {
133 DEBUG(0, ("Only root is allowed to set mappings!\n"));
134 request_error(state);
135 return;
138 xid.id = state->request->data.dual_idmapset.id;
139 xid.type = state->request->data.dual_idmapset.type;
141 winbindd_set_hwm_async(state->mem_ctx, &xid, set_hwm_recv, state);