s3:winbind: Convert WINBINDD_GETGRNAM to the new API
[metze/samba/wip.git] / source3 / winbindd / winbindd_group.c
index f33b52f83fe15115622b1a056db9585463d9eb65..6520c43f2f76073e4e1638aed6b2c526a168a2a8 100644 (file)
@@ -755,258 +755,6 @@ done:
        return result;
 }
 
-static void winbindd_getgrsid(struct winbindd_cli_state *state, DOM_SID group_sid);
-
-static void getgrnam_recv( void *private_data, bool success, const DOM_SID *sid,
-                          enum lsa_SidType type )
-{
-       struct winbindd_cli_state *state = (struct winbindd_cli_state*)private_data;
-
-       if (!success) {
-               DEBUG(5,("getgrnam_recv: lookupname failed!\n"));
-               request_error(state);
-               return;
-       }
-
-       if ( (type != SID_NAME_DOM_GRP) && (type != SID_NAME_ALIAS) ) {
-               DEBUG(5,("getgrnam_recv: not a group!\n"));
-               request_error(state);
-               return;
-       }
-
-       winbindd_getgrsid( state, *sid );
-}
-
-
-/* Return a group structure from a group name */
-
-void winbindd_getgrnam(struct winbindd_cli_state *state)
-{
-       struct winbindd_domain *domain;
-       fstring name_domain, name_group;
-       char *tmp;
-       NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
-
-       /* Ensure null termination */
-       state->request->data.groupname[sizeof(state->request->data.groupname)-1]='\0';
-
-       DEBUG(3, ("[%5lu]: getgrnam %s\n", (unsigned long)state->pid,
-                 state->request->data.groupname));
-
-       nt_status = normalize_name_unmap(state->mem_ctx,
-                                        state->request->data.groupname,
-                                        &tmp);
-       /* If we didn't map anything in the above call, just reset the
-          tmp pointer to the original string */
-       if (!NT_STATUS_IS_OK(nt_status) &&
-           !NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_RENAMED))
-       {
-               tmp = state->request->data.groupname;
-       }
-
-       /* Parse domain and groupname */
-
-       memset(name_group, 0, sizeof(name_group));
-
-       name_domain[0] = '\0';
-       name_group[0] = '\0';
-
-       parse_domain_user(tmp, name_domain, name_group);
-
-       /* if no domain or our local domain and no local tdb group, default to
-        * our local domain for aliases */
-
-       if ( !*name_domain || strequal(name_domain, get_global_sam_name()) ) {
-               fstrcpy(name_domain, get_global_sam_name());
-       }
-
-       /* Get info for the domain */
-
-       if ((domain = find_domain_from_name_noinit(name_domain)) == NULL) {
-               DEBUG(3, ("could not get domain sid for domain %s\n",
-                         name_domain));
-               request_error(state);
-               return;
-       }
-       /* should we deal with users for our domain? */
-
-       if ( lp_winbind_trusted_domains_only() && domain->primary) {
-               DEBUG(7,("winbindd_getgrnam: My domain -- rejecting "
-                        "getgrnam() for %s\\%s.\n", name_domain, name_group));
-               request_error(state);
-               return;
-       }
-
-       /* Get rid and name type from name */
-
-       fstrcpy( name_group, tmp );
-
-       winbindd_lookupname_async( state->mem_ctx, domain->name, name_group,
-                                  getgrnam_recv, WINBINDD_GETGRNAM, state );
-}
-
-struct getgrsid_state {
-       struct winbindd_cli_state *state;
-       struct winbindd_domain *domain;
-       char *group_name;
-       enum lsa_SidType group_type;
-       uid_t gid;
-       DOM_SID group_sid;
-};
-
-static void getgrsid_sid2gid_recv(void *private_data, bool success, gid_t gid)
-{
-       struct getgrsid_state *s =
-               (struct getgrsid_state *)private_data;
-       struct winbindd_domain *domain;
-       size_t gr_mem_len;
-       size_t num_gr_mem;
-       char *gr_mem;
-       fstring dom_name, group_name;
-
-       if (!success) {
-               DEBUG(5,("getgrsid_sid2gid_recv: sid2gid failed!\n"));
-               request_error(s->state);
-               return;
-       }
-
-       s->gid = gid;
-
-       if ( !parse_domain_user( s->group_name, dom_name, group_name ) ) {
-               DEBUG(5,("getgrsid_sid2gid_recv: parse_domain_user() failed!\n"));
-               request_error(s->state);
-               return;
-       }
-
-
-       /* Fill in group structure */
-
-       if ( (domain = find_domain_from_name_noinit(dom_name)) == NULL ) {
-               DEBUG(1,("Can't find domain from name (%s)\n", dom_name));
-               request_error(s->state);
-               return;
-       }
-
-       if (!fill_grent(s->state->mem_ctx, &s->state->response->data.gr,
-                       dom_name, group_name, gid) ||
-           !fill_grent_mem(domain, s->state, &s->group_sid, s->group_type,
-                           &num_gr_mem, &gr_mem, &gr_mem_len))
-       {
-               request_error(s->state);
-               return;
-       }
-
-       s->state->response->data.gr.num_gr_mem = (uint32)num_gr_mem;
-
-       /* Group membership lives at start of extra data */
-
-       s->state->response->data.gr.gr_mem_ofs = 0;
-
-       s->state->response->length += gr_mem_len;
-       s->state->response->extra_data.data = talloc_memdup(
-               s->state->mem_ctx, gr_mem, gr_mem_len);
-       if (s->state->response->extra_data.data == NULL) {
-               request_error(s->state);
-               return;
-       }
-
-       request_ok(s->state);
-}
-
-static void getgrsid_lookupsid_recv( void *private_data, bool success,
-                                    const char *dom_name, const char *name,
-                                    enum lsa_SidType name_type )
-{
-       struct getgrsid_state *s = (struct getgrsid_state *)private_data;
-       char *mapped_name = NULL;
-       fstring raw_name;
-       NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
-
-       if (!success) {
-               DEBUG(5,("getgrsid_lookupsid_recv: lookupsid failed!\n"));
-               request_error(s->state);
-               return;
-       }
-
-       /* either it's a domain group, a domain local group, or a
-          local group in an internal domain */
-
-       if ( !( (name_type==SID_NAME_DOM_GRP) ||
-               ((name_type==SID_NAME_ALIAS) &&
-                (s->domain->primary || s->domain->internal)) ) )
-       {
-               DEBUG(1, ("name '%s\\%s' is not a local or domain group: %d\n",
-                         dom_name, name, name_type));
-               request_error(s->state);
-               return;
-       }
-
-       /* normalize the name and ensure that we have the DOM\name
-         coming out of here */
-
-       fstrcpy(raw_name, name);
-
-       nt_status = normalize_name_unmap(s->state->mem_ctx, raw_name,
-                                        &mapped_name);
-
-       /* basic whitespace reversal */
-       if (NT_STATUS_IS_OK(nt_status)) {
-               s->group_name = talloc_asprintf(s->state->mem_ctx,
-                                               "%s%c%s",
-                                               dom_name,
-                                               *lp_winbind_separator(),
-                                               mapped_name);
-       }
-       /* mapped from alias */
-       else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_RENAMED)) {
-               s->group_name = mapped_name;
-       }
-       /* no mapping at all.  use original string */
-       else {
-               s->group_name = talloc_asprintf(s->state->mem_ctx,
-                                               "%s%c%s",
-                                               dom_name,
-                                               *lp_winbind_separator(),
-                                               raw_name);
-       }
-
-       if (s->group_name == NULL) {
-               DEBUG(1, ("getgrsid_lookupsid_recv: group_name is NULL!\n"));
-               request_error(s->state);
-               return;
-       }
-
-       s->group_type = name_type;
-
-       winbindd_sid2gid_async(s->state->mem_ctx, &s->group_sid,
-                              getgrsid_sid2gid_recv, s);
-}
-
-static void winbindd_getgrsid( struct winbindd_cli_state *state, const DOM_SID group_sid )
-{
-       struct getgrsid_state *s;
-
-       if ( (s = TALLOC_ZERO_P(state->mem_ctx, struct getgrsid_state)) == NULL ) {
-               DEBUG(0, ("talloc failed\n"));
-               request_error(state);
-               return;
-       }
-
-       s->state = state;
-
-       if ( (s->domain = find_domain_from_sid_noinit(&group_sid)) == NULL ) {
-               DEBUG(3, ("Could not find domain for sid %s\n",
-                         sid_string_dbg(&group_sid)));
-               request_error(state);
-               return;
-       }
-
-       sid_copy(&s->group_sid, &group_sid);
-
-       winbindd_lookupsid_async( s->state->mem_ctx,  &group_sid,
-                                 getgrsid_lookupsid_recv, s );
-}
-
 /*
  * set/get/endgrent functions
  */