Ignore:
Timestamp:
May 26, 2009, 9:44:50 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.2.x/source/winbindd/winbindd_ads.c

    r204 r228  
    402402}
    403403
     404/* convert a single name to a sid in a domain - use rpc methods */
     405static NTSTATUS name_to_sid(struct winbindd_domain *domain,
     406                            TALLOC_CTX *mem_ctx,
     407                            enum winbindd_cmd orig_cmd,
     408                            const char *domain_name,
     409                            const char *name,
     410                            DOM_SID *sid,
     411                            enum lsa_SidType *type)
     412{
     413        return reconnect_methods.name_to_sid(domain, mem_ctx, orig_cmd,
     414                                             domain_name, name,
     415                                             sid, type);
     416}
     417
     418/* convert a domain SID to a user or group name - use rpc methods */
     419static NTSTATUS sid_to_name(struct winbindd_domain *domain,
     420                            TALLOC_CTX *mem_ctx,
     421                            const DOM_SID *sid,
     422                            char **domain_name,
     423                            char **name,
     424                            enum lsa_SidType *type)
     425{
     426        return reconnect_methods.sid_to_name(domain, mem_ctx, sid,
     427                                             domain_name, name, type);
     428}
     429
     430/* convert a list of rids to names - use rpc methods */
     431static NTSTATUS rids_to_names(struct winbindd_domain *domain,
     432                              TALLOC_CTX *mem_ctx,
     433                              const DOM_SID *sid,
     434                              uint32 *rids,
     435                              size_t num_rids,
     436                              char **domain_name,
     437                              char ***names,
     438                              enum lsa_SidType **types)
     439{
     440        return reconnect_methods.rids_to_names(domain, mem_ctx, sid,
     441                                               rids, num_rids,
     442                                               domain_name, names, types);
     443}
     444
    404445/* If you are looking for "dn_lookup": Yes, it used to be here!
    405446 * It has gone now since it was a major speed bottleneck in
     
    642683static NTSTATUS lookup_usergroups_memberof(struct winbindd_domain *domain,
    643684                                           TALLOC_CTX *mem_ctx,
    644                                            const char *user_dn, 
     685                                           const char *user_dn,
    645686                                           DOM_SID *primary_group,
    646                                            size_t *p_num_groups, DOM_SID **user_sids)
     687                                           size_t *p_num_groups,
     688                                           DOM_SID **user_sids)
    647689{
    648690        ADS_STATUS rc;
     
    653695        DOM_SID *group_sids = NULL;
    654696        int i;
    655         char **strings;
    656         size_t num_strings = 0;
     697        char **strings = NULL;
     698        size_t num_strings = 0, num_sids = 0;
    657699
    658700
     
    660702
    661703        if ( !winbindd_can_contact_domain( domain ) ) {
    662                 DEBUG(10,("lookup_usergroups_memberof: No incoming trust for domain %s\n",
    663                           domain->name));               
     704                DEBUG(10,("lookup_usergroups_memberof: No incoming trust for "
     705                          "domain %s\n", domain->name));
    664706                return NT_STATUS_OK;
    665707        }
     
    669711        if (!ads) {
    670712                domain->last_status = NT_STATUS_SERVER_DISABLED;
    671                 goto done;
    672         }
    673 
    674         rc = ads_search_retry_extended_dn_ranged(ads, mem_ctx, user_dn, attrs, 
    675                                                  ADS_EXTENDED_DN_HEX_STRING, 
     713                return NT_STATUS_UNSUCCESSFUL;
     714        }
     715
     716        rc = ads_search_retry_extended_dn_ranged(ads, mem_ctx, user_dn, attrs,
     717                                                 ADS_EXTENDED_DN_HEX_STRING,
    676718                                                 &strings, &num_strings);
    677719
    678720        if (!ADS_ERR_OK(rc)) {
    679                 DEBUG(1,("lookup_usergroups_memberof ads_search member=%s: %s\n",
    680                         user_dn, ads_errstr(rc)));
     721                DEBUG(1,("lookup_usergroups_memberof ads_search "
     722                        "member=%s: %s\n", user_dn, ads_errstr(rc)));
    681723                return ads_ntstatus(rc);
    682724        }
    683        
     725
    684726        *user_sids = NULL;
    685727        num_groups = 0;
     
    694736        group_sids = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID, num_strings + 1);
    695737        if (!group_sids) {
    696                 TALLOC_FREE(strings);
    697738                status = NT_STATUS_NO_MEMORY;
    698739                goto done;
     
    700741
    701742        for (i=0; i<num_strings; i++) {
    702 
    703                 if (!ads_get_sid_from_extended_dn(mem_ctx, strings[i],
    704                                                   ADS_EXTENDED_DN_HEX_STRING,
    705                                                   &(group_sids)[i])) {
    706                         TALLOC_FREE(group_sids);
    707                         TALLOC_FREE(strings);
    708                         status = NT_STATUS_NO_MEMORY;
    709                         goto done;
    710                 }
     743                rc = ads_get_sid_from_extended_dn(mem_ctx, strings[i],
     744                                                  ADS_EXTENDED_DN_HEX_STRING,
     745                                                  &(group_sids)[i]);
     746                if (!ADS_ERR_OK(rc)) {
     747                        /* ignore members without SIDs */
     748                        if (NT_STATUS_EQUAL(ads_ntstatus(rc),
     749                            NT_STATUS_NOT_FOUND)) {
     750                                continue;
     751                        }
     752                        else {
     753                                status = ads_ntstatus(rc);
     754                                goto done;
     755                        }
     756                }
     757                num_sids++;
    711758        }
    712759
     
    717764        }
    718765
    719         for (i=0; i<num_strings; i++) {
     766        for (i=0; i<num_sids; i++) {
    720767
    721768                /* ignore Builtin groups from ADS - Guenther */
     
    729776                        goto done;
    730777                }
    731        
     778
    732779        }
    733780
     
    735782        status = (*user_sids != NULL) ? NT_STATUS_OK : NT_STATUS_NO_MEMORY;
    736783
    737         DEBUG(3,("ads lookup_usergroups (memberof) succeeded for dn=%s\n", user_dn));
     784        DEBUG(3,("ads lookup_usergroups (memberof) succeeded for dn=%s\n",
     785                user_dn));
     786
    738787done:
     788        TALLOC_FREE(strings);
    739789        TALLOC_FREE(group_sids);
    740790
     
    895945}
    896946
     947/* Lookup aliases a user is member of - use rpc methods */
     948static NTSTATUS lookup_useraliases(struct winbindd_domain *domain,
     949                                   TALLOC_CTX *mem_ctx,
     950                                   uint32 num_sids, const DOM_SID *sids,
     951                                   uint32 *num_aliases, uint32 **alias_rids)
     952{
     953        return reconnect_methods.lookup_useraliases(domain, mem_ctx,
     954                                                    num_sids, sids,
     955                                                    num_aliases,
     956                                                    alias_rids);
     957}
     958
    897959/*
    898960  find the members of a group, given a group rid and domain
     
    900962static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
    901963                                TALLOC_CTX *mem_ctx,
    902                                 const DOM_SID *group_sid, uint32 *num_names, 
    903                                 DOM_SID **sid_mem, char ***names, 
     964                                const DOM_SID *group_sid, uint32 *num_names,
     965                                DOM_SID **sid_mem, char ***names,
    904966                                uint32 **name_types)
    905967{
     
    922984        TALLOC_CTX *tmp_ctx = NULL;
    923985
    924         DEBUG(10,("ads: lookup_groupmem %s sid=%s\n", domain->name, 
     986        DEBUG(10,("ads: lookup_groupmem %s sid=%s\n", domain->name,
    925987                  sid_string_dbg(group_sid)));
    926988
     
    936998        if ( !winbindd_can_contact_domain( domain ) ) {
    937999                DEBUG(10,("lookup_groupmem: No incoming trust for domain %s\n",
    938                           domain->name));               
     1000                          domain->name));
    9391001                return NT_STATUS_OK;
    9401002        }
    9411003
    9421004        ads = ads_cached_connection(domain);
    943        
     1005
    9441006        if (!ads) {
    9451007                domain->last_status = NT_STATUS_SERVER_DISABLED;
     
    9531015
    9541016        /* search for all members of the group */
    955         if (!(ldap_exp = talloc_asprintf(tmp_ctx, "(objectSid=%s)", 
    956                                          sidbinstr))) 
     1017        if (!(ldap_exp = talloc_asprintf(tmp_ctx, "(objectSid=%s)",
     1018                                         sidbinstr)))
    9571019        {
    9581020                SAFE_FREE(sidbinstr);
     
    9671029        args.critical = True;
    9681030
    969         rc = ads_ranged_search(ads, tmp_ctx, LDAP_SCOPE_SUBTREE, ads->config.bind_path, 
     1031        rc = ads_ranged_search(ads, tmp_ctx, LDAP_SCOPE_SUBTREE, ads->config.bind_path,
    9701032                               ldap_exp, &args, "member", &members, &num_members);
    9711033
     
    9741036                status = NT_STATUS_UNSUCCESSFUL;
    9751037                goto done;
    976         } 
    977        
     1038        }
     1039
    9781040        DEBUG(10, ("ads lookup_groupmem: got %d sids via extended dn call\n", (int)num_members));
    979        
     1041
    9801042        /* Now that we have a list of sids, we need to get the
    9811043         * lists of names and name_types belonging to these sids.
    982          * even though conceptually not quite clean,  we use the 
    983          * RPC call lsa_lookup_sids for this since it can handle a 
     1044         * even though conceptually not quite clean,  we use the
     1045         * RPC call lsa_lookup_sids for this since it can handle a
    9841046         * list of sids. ldap calls can just resolve one sid at a time.
    9851047         *
     
    9891051         * we try to resolve as many sids as possible from the
    9901052         * cache. Only the rest is passed to the lsa_lookup_sids call. */
    991        
     1053
    9921054        if (num_members) {
    9931055                (*sid_mem) = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID, num_members);
     
    10161078                DOM_SID sid;
    10171079
    1018                 if (!ads_get_sid_from_extended_dn(tmp_ctx, members[i], args.val, &sid)) {
    1019                         status = NT_STATUS_INVALID_PARAMETER;
    1020                         goto done;
    1021                 }
    1022                 if (lookup_cached_sid(mem_ctx, &sid, &domain_name, &name, &name_type)) {
     1080                rc = ads_get_sid_from_extended_dn(tmp_ctx, members[i], args.val,
     1081                    &sid);
     1082                if (!ADS_ERR_OK(rc)) {
     1083                        if (NT_STATUS_EQUAL(ads_ntstatus(rc),
     1084                            NT_STATUS_NOT_FOUND)) {
     1085                                /* Group members can be objects, like Exchange
     1086                                 * Public Folders, that don't have a SID.  Skip
     1087                                 * them. */
     1088                                continue;
     1089                        }
     1090                        else {
     1091                                status = ads_ntstatus(rc);
     1092                                goto done;
     1093                        }
     1094                }
     1095                if (lookup_cached_sid(mem_ctx, &sid, &domain_name, &name,
     1096                    &name_type)) {
    10231097                        DEBUG(10,("ads: lookup_groupmem: got sid %s from "
    10241098                                  "cache\n", sid_string_dbg(&sid)));
    10251099                        sid_copy(&(*sid_mem)[*num_names], &sid);
    1026                         (*names)[*num_names] = talloc_asprintf(*names, "%s%c%s",
    1027                                                                domain_name,
    1028                                                                *lp_winbind_separator(),
    1029                                                                name );
     1100                        (*names)[*num_names] = fill_domain_username_talloc(
     1101                                                        *names,
     1102                                                        domain_name,
     1103                                                        name,
     1104                                                        true);
    10301105
    10311106                        (*name_types)[*num_names] = name_type;
     
    10521127                }
    10531128
    1054                 status = rpccli_lsa_lookup_sids(cli, tmp_ctx, 
     1129                status = rpccli_lsa_lookup_sids(cli, tmp_ctx,
    10551130                                                &lsa_policy,
    1056                                                 num_nocache, 
    1057                                                 sid_mem_nocache, 
    1058                                                 &domains_nocache, 
    1059                                                 &names_nocache, 
     1131                                                num_nocache,
     1132                                                sid_mem_nocache,
     1133                                                &domains_nocache,
     1134                                                &names_nocache,
    10601135                                                &name_types_nocache);
    10611136
     1137                if (!(NT_STATUS_IS_OK(status) ||
     1138                      NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED) ||
     1139                      NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)))
     1140                {
     1141                        DEBUG(1, ("lsa_lookupsids call failed with %s "
     1142                                  "- retrying...\n", nt_errstr(status)));
     1143
     1144                        status = cm_connect_lsa(domain, tmp_ctx, &cli,
     1145                                                &lsa_policy);
     1146
     1147                        if (!NT_STATUS_IS_OK(status)) {
     1148                                goto done;
     1149                        }
     1150
     1151                        status = rpccli_lsa_lookup_sids(cli, tmp_ctx,
     1152                                                        &lsa_policy,
     1153                                                        num_nocache,
     1154                                                        sid_mem_nocache,
     1155                                                        &domains_nocache,
     1156                                                        &names_nocache,
     1157                                                        &name_types_nocache);
     1158                }
     1159
    10621160                if (NT_STATUS_IS_OK(status) ||
    1063                     NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) 
     1161                    NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED))
    10641162                {
    1065                         /* Copy the entries over from the "_nocache" arrays 
    1066                          * to the result arrays, skipping the gaps the 
     1163                        /* Copy the entries over from the "_nocache" arrays
     1164                         * to the result arrays, skipping the gaps the
    10671165                         * lookup_sids call left. */
    10681166                        for (i=0; i < num_nocache; i++) {
    1069                                 if (((names_nocache)[i] != NULL) && 
    1070                                     ((name_types_nocache)[i] != SID_NAME_UNKNOWN)) 
     1167                                if (((names_nocache)[i] != NULL) &&
     1168                                    ((name_types_nocache)[i] != SID_NAME_UNKNOWN))
    10711169                                {
    10721170                                        sid_copy(&(*sid_mem)[*num_names],
    10731171                                                 &sid_mem_nocache[i]);
    1074                                         (*names)[*num_names] = talloc_asprintf( *names,
    1075                                                                                 "%s%c%s",
    1076                                                                                 domains_nocache[i],
    1077                                                                                 *lp_winbind_separator(),
    1078                                                                                 names_nocache[i] );
     1172                                        (*names)[*num_names] =
     1173                                                fill_domain_username_talloc(
     1174                                                        *names,
     1175                                                        domains_nocache[i],
     1176                                                        names_nocache[i],
     1177                                                        true);
    10791178                                        (*name_types)[*num_names] = name_types_nocache[i];
    10801179                                        (*num_names)++;
     
    11471246        }
    11481247        return ads_ntstatus(rc);
     1248}
     1249
     1250/* find the lockout policy of a domain - use rpc methods */
     1251static NTSTATUS lockout_policy(struct winbindd_domain *domain,
     1252                               TALLOC_CTX *mem_ctx,
     1253                               struct samr_DomInfo12 *policy)
     1254{
     1255        return reconnect_methods.lockout_policy(domain, mem_ctx, policy);
     1256}
     1257
     1258/* find the password policy of a domain - use rpc methods */
     1259static NTSTATUS password_policy(struct winbindd_domain *domain,
     1260                                TALLOC_CTX *mem_ctx,
     1261                                struct samr_DomInfo1 *policy)
     1262{
     1263        return reconnect_methods.password_policy(domain, mem_ctx, policy);
    11491264}
    11501265
     
    13391454        enum_dom_groups,
    13401455        enum_local_groups,
    1341         msrpc_name_to_sid,
    1342         msrpc_sid_to_name,
    1343         msrpc_rids_to_names,
     1456        name_to_sid,
     1457        sid_to_name,
     1458        rids_to_names,
    13441459        query_user,
    13451460        lookup_usergroups,
    1346         msrpc_lookup_useraliases,
     1461        lookup_useraliases,
    13471462        lookup_groupmem,
    13481463        sequence_number,
    1349         msrpc_lockout_policy,
    1350         msrpc_password_policy,
     1464        lockout_policy,
     1465        password_policy,
    13511466        trusted_domains,
    13521467};
Note: See TracChangeset for help on using the changeset viewer.