+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;
+}
+