add winbindd_ndr_child_set_idmap() ...
authorStefan Metzmacher <metze@sernet.de>
Wed, 12 Dec 2007 16:05:09 +0000 (17:05 +0100)
committerStefan Metzmacher <metze@sernet.de>
Fri, 2 May 2008 14:12:44 +0000 (16:12 +0200)
source/winbindd/winbindd_idmap.c

index 2097781c1614e7a2d2a6e1bc0349230910c81d13..710a403b8b01e72bef404654aa953e538af761d0 100644 (file)
@@ -223,6 +223,140 @@ void winbindd_ndr_child_get_idmap(struct winbindd_domain *domain,
        return;
 }
 
+static void ndr_child_set_idmap_allocate_uid(struct winbindd_domain *domain,
+                                            struct winbindd_cli_state *state,
+                                            struct winbind_set_idmap *r)
+{
+       NTSTATUS result;
+       struct unixid xid;
+
+       DEBUG(3, ("allocate_uid\n"));
+
+       result = idmap_allocate_uid(&xid);
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(1,("Can't allocate uid: %s\n",
+                        nt_errstr(result)));
+               r->out.result = WINBIND_STATUS_FOOBAR;
+               return;
+       }
+
+       DEBUG(10, ("allocte_uid: %u\n",
+                  xid.id));
+
+       r->out.rep->uid = xid.id;
+
+       r->out.result = WINBIND_STATUS_OK;
+}
+
+static void ndr_child_set_idmap_allocate_gid(struct winbindd_domain *domain,
+                                            struct winbindd_cli_state *state,
+                                            struct winbind_set_idmap *r)
+{
+       NTSTATUS result;
+       struct unixid xid;
+
+       DEBUG(3, ("allocate_gid\n"));
+
+       result = idmap_allocate_gid(&xid);
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(1,("Can't allocate gid: %s\n",
+                        nt_errstr(result)));
+               r->out.result = WINBIND_STATUS_FOOBAR;
+               return;
+       }
+
+       DEBUG(10, ("allocte_gid: %u\n",
+                  xid.id));
+
+       r->out.rep->gid = xid.id;
+
+       r->out.result = WINBIND_STATUS_OK;
+}
+
+static void ndr_child_set_idmap_set_mapping(struct winbindd_domain *domain,
+                                           struct winbindd_cli_state *state,
+                                           struct winbind_set_idmap *r)
+{
+       NTSTATUS result;
+
+       DEBUG(3,("set_mapping: sid %s -> %u type:%u\n",
+                sid_string_tos(r->in.req.mapping.sid),
+                r->in.req.mapping.xid.id,
+                r->in.req.mapping.xid.type));
+
+       result = idmap_set_mapping(&r->in.req.mapping);
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(1,("Can't set mapping: %s\n",
+                        nt_errstr(result)));
+               r->out.result = WINBIND_STATUS_FOOBAR;
+               return;
+       }
+
+       r->out.result = WINBIND_STATUS_OK;
+}
+
+static void ndr_child_set_idmap_set_hwm(struct winbindd_domain *domain,
+                                       struct winbindd_cli_state *state,
+                                       struct winbind_set_idmap *r)
+{
+       NTSTATUS result;
+
+       DEBUG(3,("set_hwm: %u type:%u\n",
+                r->in.req.hwm.id,
+                r->in.req.hwm.type));
+
+       switch (r->in.req.hwm.type) {
+       case ID_TYPE_UID:
+               result = idmap_set_uid_hwm(&r->in.req.hwm);
+               break;
+       case ID_TYPE_GID:
+               result = idmap_set_gid_hwm(&r->in.req.hwm);
+               break;
+       default:
+               result = NT_STATUS_INVALID_PARAMETER;
+               break;
+       }
+
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(1,("Can't set hwm: %s\n",
+                        nt_errstr(result)));
+               r->out.result = WINBIND_STATUS_FOOBAR;
+               return;
+       }
+
+       r->out.result = WINBIND_STATUS_OK;
+}
+
+void winbindd_ndr_child_set_idmap(struct winbindd_domain *domain,
+                                 struct winbindd_cli_state *state)
+{
+       struct winbind_set_idmap *r;
+
+       r = talloc_get_type_abort(state->c.ndr.r,
+                                 struct winbind_set_idmap);
+
+       switch (*r->in.level) {
+       case WINBIND_SET_IDMAP_LEVEL_ALLOCATE_UID:
+               ndr_child_set_idmap_allocate_uid(domain, state, r);
+               return;
+
+       case WINBIND_SET_IDMAP_LEVEL_ALLOCATE_GID:
+               ndr_child_set_idmap_allocate_gid(domain, state, r);
+               return;
+
+       case WINBIND_SET_IDMAP_LEVEL_SET_MAPPING:
+               ndr_child_set_idmap_set_mapping(domain, state, r);
+               return;
+
+       case WINBIND_SET_IDMAP_LEVEL_SET_HWM:
+               ndr_child_set_idmap_set_hwm(domain, state, r);
+               return;
+       }
+
+       r->out.result = WINBIND_STATUS_UNKNOWN_LEVEL;
+       return;
+}
+
 static void winbindd_set_mapping_recv(TALLOC_CTX *mem_ctx, bool success,
                                   struct winbindd_response *response,
                                   void *c, void *private_data)
@@ -628,6 +762,10 @@ static const struct winbindd_child_dispatch_table idmap_dispatch_table[] = {
                .name           = "NDR_WINBIND_GET_IDMAP",
                .ndr_opnum      = NDR_WINBIND_GET_IDMAP,
                .ndr_fn         = winbindd_ndr_child_get_idmap,
+       },{
+               .name           = "NDR_WINBIND_SET_IDMAP",
+               .ndr_opnum      = NDR_WINBIND_SET_IDMAP,
+               .ndr_fn         = winbindd_ndr_child_set_idmap,
        },{
                .name           = NULL,
        }