Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/passdb/pdb_ldap.c

    r596 r745  
    4545
    4646#include "includes.h"
     47#include "passdb.h"
    4748#include "../libcli/auth/libcli_auth.h"
     49#include "secrets.h"
     50#include "idmap_cache.h"
     51#include "../libcli/security/security.h"
     52#include "../lib/util/util_pw.h"
     53#include "lib/winbind_util.h"
    4854
    4955#undef DBGC_CLASS
     
    5258#include <lber.h>
    5359#include <ldap.h>
    54 
    55 /*
    56  * Work around versions of the LDAP client libs that don't have the OIDs
    57  * defined, or have them defined under the old name. 
    58  * This functionality is really a factor of the server, not the client
    59  *
    60  */
    61 
    62 #if defined(LDAP_EXOP_X_MODIFY_PASSWD) && !defined(LDAP_EXOP_MODIFY_PASSWD)
    63 #define LDAP_EXOP_MODIFY_PASSWD LDAP_EXOP_X_MODIFY_PASSWD
    64 #elif !defined(LDAP_EXOP_MODIFY_PASSWD)
    65 #define LDAP_EXOP_MODIFY_PASSWD "1.3.6.1.4.1.4203.1.11.1"
    66 #endif
    67 
    68 #if defined(LDAP_EXOP_X_MODIFY_PASSWD_ID) && !defined(LDAP_EXOP_MODIFY_PASSWD_ID)
    69 #define LDAP_TAG_EXOP_MODIFY_PASSWD_ID LDAP_EXOP_X_MODIFY_PASSWD_ID
    70 #elif !defined(LDAP_EXOP_MODIFY_PASSWD_ID)
    71 #define LDAP_TAG_EXOP_MODIFY_PASSWD_ID        ((ber_tag_t) 0x80U)
    72 #endif
    73 
    74 #if defined(LDAP_EXOP_X_MODIFY_PASSWD_NEW) && !defined(LDAP_EXOP_MODIFY_PASSWD_NEW)
    75 #define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW LDAP_EXOP_X_MODIFY_PASSWD_NEW
    76 #elif !defined(LDAP_EXOP_MODIFY_PASSWD_NEW)
    77 #define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW       ((ber_tag_t) 0x82U)
    78 #endif
    7960
    8061
     
    8566 **********************************************************************/
    8667
    87 static LDAP *priv2ld(struct ldapsam_privates *priv)
     68LDAP *priv2ld(struct ldapsam_privates *priv)
    8869{
    8970        return priv->smbldap_state->ldap_struct;
     
    377358
    378359static int ldapsam_search_suffix_by_rid (struct ldapsam_privates *ldap_state,
    379                                          uint32 rid, LDAPMessage ** result,
     360                                         uint32_t rid, LDAPMessage ** result,
    380361                                         const char **attr)
    381362{
     
    400381
    401382static int ldapsam_search_suffix_by_sid (struct ldapsam_privates *ldap_state,
    402                                  const DOM_SID *sid, LDAPMessage ** result,
     383                                 const struct dom_sid *sid, LDAPMessage ** result,
    403384                                 const char **attr)
    404385{
     
    530511                        *workstations = NULL,
    531512                        *munged_dial = NULL;
    532         uint32          user_rid;
     513        uint32_t                user_rid;
    533514        uint8           smblmpwd[LM_HASH_LEN],
    534515                        smbntpwd[NT_HASH_LEN];
    535516        bool            use_samba_attrs = True;
    536         uint32          acct_ctrl = 0;
    537         uint16          logon_divs;
    538         uint16          bad_password_count = 0,
     517        uint32_t                acct_ctrl = 0;
     518        uint16_t                logon_divs;
     519        uint16_t                bad_password_count = 0,
    539520                        logon_count = 0;
    540         uint32 hours_len;
     521        uint32_t hours_len;
    541522        uint8           hours[MAX_HOURS_LEN];
    542523        char *temp = NULL;
    543         LOGIN_CACHE     *cache_entry = NULL;
    544         uint32          pwHistLen;
     524        struct login_cache cache_entry;
     525        uint32_t                pwHistLen;
    545526        bool expand_explicit = lp_passdb_expand_explicit();
    546527        bool ret = false;
     
    605586                                        LDAP_ATTR_USER_RID),
    606587                                ctx))!=NULL) {
    607                         user_rid = (uint32)atol(temp);
     588                        user_rid = (uint32_t)atol(temp);
    608589                        pdb_set_user_sid_from_rid(sampass, user_rid, PDB_SET);
    609590                }
    610591        }
    611592
    612         if (pdb_get_init_flags(sampass,PDB_USERSID) == PDB_DEFAULT) {
     593        if (IS_SAM_DEFAULT(sampass, PDB_USERSID)) {
    613594                DEBUG(1, ("init_sam_from_ldap: no %s or %s attribute found for this user %s\n",
    614595                        get_userattr_key2string(ldap_state->schema_ver,
     
    916897                pwHistLen = MIN(pwHistLen, MAX_PW_HISTORY_LEN);
    917898
    918                 if ((pwhist = TALLOC_ARRAY(ctx, uint8,
    919                                         pwHistLen * PW_HISTORY_ENTRY_LEN)) ==
    920                                 NULL){
     899                pwhist = TALLOC_ARRAY(ctx, uint8,
     900                                      pwHistLen * PW_HISTORY_ENTRY_LEN);
     901                if (pwhist == NULL) {
    921902                        DEBUG(0, ("init_sam_from_ldap: talloc failed!\n"));
    922903                        goto fn_exit;
     
    986967                        ctx);
    987968        if (temp) {
    988                 bad_password_count = (uint32) atol(temp);
     969                bad_password_count = (uint32_t) atol(temp);
    989970                pdb_set_bad_password_count(sampass,
    990971                                bad_password_count, PDB_SET);
     
    1010991                        ctx);
    1011992        if (temp) {
    1012                 logon_count = (uint32) atol(temp);
     993                logon_count = (uint32_t) atol(temp);
    1013994                pdb_set_logon_count(sampass, logon_count, PDB_SET);
    1014995        }
     
    10251006                pdb_gethexhours(temp, hours);
    10261007                memset((char *)temp, '\0', strlen(temp) +1);
    1027                 pdb_set_hours(sampass, hours, PDB_SET);
     1008                pdb_set_hours(sampass, hours, hours_len, PDB_SET);
    10281009                ZERO_STRUCT(hours);
    10291010        }
     
    10331014                bool have_uid = false;
    10341015                bool have_gid = false;
    1035                 DOM_SID mapped_gsid;
    1036                 const DOM_SID *primary_gsid;
     1016                struct dom_sid mapped_gsid;
     1017                const struct dom_sid *primary_gsid;
    10371018
    10381019                ZERO_STRUCT(unix_pw);
     
    11051086                gid_to_sid(&mapped_gsid, sampass->unix_pw->pw_gid);
    11061087                primary_gsid = pdb_get_group_sid(sampass);
    1107                 if (primary_gsid && sid_equal(primary_gsid, &mapped_gsid)) {
     1088                if (primary_gsid && dom_sid_equal(primary_gsid, &mapped_gsid)) {
    11081089                        store_gid_sid_cache(primary_gsid,
    11091090                                            sampass->unix_pw->pw_gid);
     
    11211102
    11221103        /* see if we have newer updates */
    1123         if (!(cache_entry = login_cache_read(sampass))) {
     1104        if (!login_cache_read(sampass, &cache_entry)) {
    11241105                DEBUG (9, ("No cache entry, bad count = %u, bad time = %u\n",
    11251106                           (unsigned int)pdb_get_bad_password_count(sampass),
     
    11311112        DEBUG(7, ("ldap time is %u, cache time is %u, bad time = %u\n",
    11321113                  (unsigned int)ldap_entry_time,
    1133                   (unsigned int)cache_entry->entry_timestamp,
    1134                   (unsigned int)cache_entry->bad_password_time));
    1135 
    1136         if (ldap_entry_time > cache_entry->entry_timestamp) {
     1114                  (unsigned int)cache_entry.entry_timestamp,
     1115                  (unsigned int)cache_entry.bad_password_time));
     1116
     1117        if (ldap_entry_time > cache_entry.entry_timestamp) {
    11371118                /* cache is older than directory , so
    11381119                   we need to delete the entry but allow the
     
    11431124                pdb_set_acct_ctrl(sampass,
    11441125                                  pdb_get_acct_ctrl(sampass) |
    1145                                   (cache_entry->acct_ctrl & ACB_AUTOLOCK),
     1126                                  (cache_entry.acct_ctrl & ACB_AUTOLOCK),
    11461127                                  PDB_SET);
    11471128                pdb_set_bad_password_count(sampass,
    1148                                            cache_entry->bad_password_count,
     1129                                           cache_entry.bad_password_count,
    11491130                                           PDB_SET);
    11501131                pdb_set_bad_password_time(sampass,
    1151                                           cache_entry->bad_password_time,
     1132                                          cache_entry.bad_password_time,
    11521133                                          PDB_SET);
    11531134        }
     
    11581139
    11591140        TALLOC_FREE(ctx);
    1160         SAFE_FREE(cache_entry);
    11611141        return ret;
    11621142}
     
    11741154{
    11751155        char *temp = NULL;
    1176         uint32 rid;
     1156        uint32_t rid;
    11771157
    11781158        if (mods == NULL || sampass == NULL) {
     
    12031183        if (need_update(sampass, PDB_USERSID)) {
    12041184                fstring sid_string;
    1205                 const DOM_SID *user_sid = pdb_get_user_sid(sampass);
     1185                const struct dom_sid *user_sid = pdb_get_user_sid(sampass);
    12061186
    12071187                switch ( ldap_state->schema_ver ) {
     
    12401220        if (need_update(sampass, PDB_GROUPSID)) {
    12411221                fstring sid_string;
    1242                 const DOM_SID *group_sid = pdb_get_group_sid(sampass);
     1222                const struct dom_sid *group_sid = pdb_get_group_sid(sampass);
    12431223
    12441224                switch ( ldap_state->schema_ver ) {
     
    13981378                if (need_update(sampass, PDB_PWHISTORY)) {
    13991379                        char *pwstr = NULL;
    1400                         uint32 pwHistLen = 0;
     1380                        uint32_t pwHistLen = 0;
    14011381                        pdb_get_account_policy(PDB_POLICY_PASSWORD_HISTORY, &pwHistLen);
    14021382
     
    14111391                        } else {
    14121392                                int i;
    1413                                 uint32 currHistLen = 0;
     1393                                uint32_t currHistLen = 0;
    14141394                                const uint8 *pwhist = pdb_get_pw_history(sampass, &currHistLen);
    14151395                                if (pwhist != NULL) {
     
    14731453        if (need_update(sampass, PDB_BAD_PASSWORD_COUNT))  /* &&
    14741454            need_update(sampass, PDB_BAD_PASSWORD_TIME)) */ {
    1475                 uint16 badcount = pdb_get_bad_password_count(sampass);
     1455                uint16_t badcount = pdb_get_bad_password_count(sampass);
    14761456                time_t badtime = pdb_get_bad_password_time(sampass);
    1477                 uint32 pol;
     1457                uint32_t pol;
    14781458                pdb_get_account_policy(PDB_POLICY_BAD_ATTEMPT_LOCKOUT, &pol);
    14791459
     
    15121492                        login_cache_delentry(sampass);
    15131493                } else {
    1514                         LOGIN_CACHE cache_entry;
     1494                        struct login_cache cache_entry;
    15151495
    15161496                        cache_entry.entry_timestamp = time(NULL);
     
    15201500
    15211501                        DEBUG(7, ("Updating bad password count and time in login cache\n"));
    1522                         login_cache_write(sampass, cache_entry);
     1502                        login_cache_write(sampass, &cache_entry);
    15231503                }
    15241504        }
     
    16261606
    16271607static int ldapsam_get_ldap_user_by_sid(struct ldapsam_privates *ldap_state,
    1628                                    const DOM_SID *sid, LDAPMessage **result)
     1608                                   const struct dom_sid *sid, LDAPMessage **result)
    16291609{
    16301610        int rc = -1;
    16311611        const char ** attr_list;
    1632         uint32 rid;
     1612        uint32_t rid;
    16331613
    16341614        switch ( ldap_state->schema_ver ) {
     
    16761656*********************************************************************/
    16771657
    1678 static NTSTATUS ldapsam_getsampwsid(struct pdb_methods *my_methods, struct samu * user, const DOM_SID *sid)
     1658static NTSTATUS ldapsam_getsampwsid(struct pdb_methods *my_methods, struct samu * user, const struct dom_sid *sid)
    16791659{
    16801660        struct ldapsam_privates *ldap_state = (struct ldapsam_privates *)my_methods->private_data;
     
    17371717        if (!newpwd || !dn) {
    17381718                return NT_STATUS_INVALID_PARAMETER;
    1739         }
    1740 
    1741         if (!mods) {
    1742                 DEBUG(5,("ldapsam_modify_entry: mods is empty: nothing to modify\n"));
    1743                 /* may be password change below however */
    1744         } else {
    1745                 switch(ldap_op) {
    1746                         case LDAP_MOD_ADD:
    1747                                 if (ldap_state->is_nds_ldap) {
    1748                                         smbldap_set_mod(&mods, LDAP_MOD_ADD,
    1749                                                         "objectclass",
    1750                                                         "inetOrgPerson");
    1751                                 } else {
    1752                                         smbldap_set_mod(&mods, LDAP_MOD_ADD,
    1753                                                         "objectclass",
    1754                                                         LDAP_OBJ_ACCOUNT);
    1755                                 }
    1756                                 rc = smbldap_add(ldap_state->smbldap_state,
    1757                                                  dn, mods);
    1758                                 break;
    1759                         case LDAP_MOD_REPLACE:
    1760                                 rc = smbldap_modify(ldap_state->smbldap_state,
    1761                                                     dn ,mods);
    1762                                 break;
    1763                         default:       
    1764                                 DEBUG(0,("ldapsam_modify_entry: Wrong LDAP operation type: %d!\n",
    1765                                          ldap_op));
    1766                                 return NT_STATUS_INVALID_PARAMETER;
    1767                 }
    1768 
    1769                 if (rc!=LDAP_SUCCESS) {
    1770                         return NT_STATUS_UNSUCCESSFUL;
    1771                 } 
    17721719        }
    17731720
     
    18971844                ber_bvfree(bv);
    18981845        }
     1846
     1847        if (!mods) {
     1848                DEBUG(5,("ldapsam_modify_entry: mods is empty: nothing to modify\n"));
     1849                /* may be password change below however */
     1850        } else {
     1851                switch(ldap_op) {
     1852                        case LDAP_MOD_ADD:
     1853                                if (ldap_state->is_nds_ldap) {
     1854                                        smbldap_set_mod(&mods, LDAP_MOD_ADD,
     1855                                                        "objectclass",
     1856                                                        "inetOrgPerson");
     1857                                } else {
     1858                                        smbldap_set_mod(&mods, LDAP_MOD_ADD,
     1859                                                        "objectclass",
     1860                                                        LDAP_OBJ_ACCOUNT);
     1861                                }
     1862                                rc = smbldap_add(ldap_state->smbldap_state,
     1863                                                 dn, mods);
     1864                                break;
     1865                        case LDAP_MOD_REPLACE:
     1866                                rc = smbldap_modify(ldap_state->smbldap_state,
     1867                                                    dn ,mods);
     1868                                break;
     1869                        default:
     1870                                DEBUG(0,("ldapsam_modify_entry: Wrong LDAP operation type: %d!\n",
     1871                                         ldap_op));
     1872                                return NT_STATUS_INVALID_PARAMETER;
     1873                }
     1874
     1875                if (rc!=LDAP_SUCCESS) {
     1876                        return NT_STATUS_UNSUCCESSFUL;
     1877                }
     1878        }
     1879
    18991880        return NT_STATUS_OK;
    19001881}
     
    20702051static NTSTATUS ldapsam_del_groupmem(struct pdb_methods *my_methods,
    20712052                                     TALLOC_CTX *tmp_ctx,
    2072                                      uint32 group_rid,
    2073                                      uint32 member_rid);
     2053                                     uint32_t group_rid,
     2054                                     uint32_t member_rid);
    20742055
    20752056static NTSTATUS ldapsam_enum_group_memberships(struct pdb_methods *methods,
    20762057                                               TALLOC_CTX *mem_ctx,
    20772058                                               struct samu *user,
    2078                                                DOM_SID **pp_sids,
     2059                                               struct dom_sid **pp_sids,
    20792060                                               gid_t **pp_gids,
    2080                                                size_t *p_num_groups);
     2061                                               uint32_t *p_num_groups);
    20812062
    20822063static NTSTATUS ldapsam_rename_sam_account(struct pdb_methods *my_methods,
     
    21772158        LDAPMod         **mods = NULL;
    21782159        int             ldap_op = LDAP_MOD_REPLACE;
    2179         uint32          num_result;
     2160        uint32_t                num_result;
    21802161        const char      **attr_list;
    21812162        char *escape_user = NULL;
    21822163        const char      *username = pdb_get_username(newpwd);
    2183         const DOM_SID   *sid = pdb_get_user_sid(newpwd);
     2164        const struct dom_sid    *sid = pdb_get_user_sid(newpwd);
    21842165        char *filter = NULL;
    21852166        char *dn = NULL;
     
    25942575
    25952576static NTSTATUS ldapsam_getgrsid(struct pdb_methods *methods, GROUP_MAP *map,
    2596                                  DOM_SID sid)
     2577                                 struct dom_sid sid)
    25972578{
    25982579        char *filter = NULL;
     
    26642645static bool ldapsam_extract_rid_from_entry(LDAP *ldap_struct,
    26652646                                           LDAPMessage *entry,
    2666                                            const DOM_SID *domain_sid,
    2667                                            uint32 *rid)
     2647                                           const struct dom_sid *domain_sid,
     2648                                           uint32_t *rid)
    26682649{
    26692650        fstring str;
    2670         DOM_SID sid;
     2651        struct dom_sid sid;
    26712652
    26722653        if (!smbldap_get_single_attribute(ldap_struct, entry, "sambaSID",
     
    26812662        }
    26822663
    2683         if (sid_compare_domain(&sid, domain_sid) != 0) {
     2664        if (dom_sid_compare_domain(&sid, domain_sid) != 0) {
    26842665                DEBUG(10, ("SID %s is not in expected domain %s\n",
    26852666                           str, sid_string_dbg(domain_sid)));
     
    26972678static NTSTATUS ldapsam_enum_group_members(struct pdb_methods *methods,
    26982679                                           TALLOC_CTX *mem_ctx,
    2699                                            const DOM_SID *group,
    2700                                            uint32 **pp_member_rids,
     2680                                           const struct dom_sid *group,
     2681                                           uint32_t **pp_member_rids,
    27012682                                           size_t *p_num_members)
    27022683{
     
    28152796                {
    28162797                        char *sidstr;
    2817                         DOM_SID sid;
    2818                         uint32 rid;
     2798                        struct dom_sid sid;
     2799                        uint32_t rid;
    28192800
    28202801                        sidstr = smbldap_talloc_single_attribute(conn->ldap_struct,
     
    28672848             entry = ldap_next_entry(conn->ldap_struct, entry))
    28682849        {
    2869                 uint32 rid;
     2850                uint32_t rid;
    28702851
    28712852                if (!ldapsam_extract_rid_from_entry(conn->ldap_struct,
     
    28982879                                               TALLOC_CTX *mem_ctx,
    28992880                                               struct samu *user,
    2900                                                DOM_SID **pp_sids,
     2881                                               struct dom_sid **pp_sids,
    29012882                                               gid_t **pp_gids,
    2902                                                size_t *p_num_groups)
     2883                                               uint32_t *p_num_groups)
    29032884{
    29042885        struct ldapsam_privates *ldap_state =
     
    29122893        LDAPMessage *entry;
    29132894        NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
    2914         size_t num_sids, num_gids;
     2895        uint32_t num_sids;
     2896        uint32_t num_gids;
    29152897        char *gidstr;
    29162898        gid_t primary_gid = -1;
     
    30152997        {
    30162998                fstring str;
    3017                 DOM_SID sid;
     2999                struct dom_sid sid;
    30183000                gid_t gid;
    30193001                char *end;
     
    30533035        }
    30543036
    3055         if (sid_compare(&global_sid_NULL, &(*pp_sids)[0]) == 0) {
     3037        if (dom_sid_compare(&global_sid_NULL, &(*pp_sids)[0]) == 0) {
    30563038                DEBUG(3, ("primary group of [%s] not found\n",
    30573039                          pdb_get_username(user)));
     
    31403122        NTSTATUS result;
    31413123
    3142         DOM_SID sid;
     3124        struct dom_sid sid;
    31433125
    31443126        int rc;
     
    33453327
    33463328static NTSTATUS ldapsam_delete_group_mapping_entry(struct pdb_methods *methods,
    3347                                                    DOM_SID sid)
     3329                                                   struct dom_sid sid)
    33483330{
    33493331        struct ldapsam_privates *priv =
     
    35083490
    35093491static NTSTATUS ldapsam_enum_group_mapping(struct pdb_methods *methods,
    3510                                            const DOM_SID *domsid, enum lsa_SidType sid_name_use,
     3492                                           const struct dom_sid *domsid, enum lsa_SidType sid_name_use,
    35113493                                           GROUP_MAP **pp_rmap,
    35123494                                           size_t *p_num_entries,
    35133495                                           bool unix_only)
    35143496{
    3515         GROUP_MAP map;
     3497        GROUP_MAP map = { 0, };
    35163498        size_t entries = 0;
    35173499
     
    35583540
    35593541static NTSTATUS ldapsam_modify_aliasmem(struct pdb_methods *methods,
    3560                                         const DOM_SID *alias,
    3561                                         const DOM_SID *member,
     3542                                        const struct dom_sid *alias,
     3543                                        const struct dom_sid *member,
    35623544                                        int modop)
    35633545{
     
    36633645
    36643646static NTSTATUS ldapsam_add_aliasmem(struct pdb_methods *methods,
    3665                                      const DOM_SID *alias,
    3666                                      const DOM_SID *member)
     3647                                     const struct dom_sid *alias,
     3648                                     const struct dom_sid *member)
    36673649{
    36683650        return ldapsam_modify_aliasmem(methods, alias, member, LDAP_MOD_ADD);
     
    36703652
    36713653static NTSTATUS ldapsam_del_aliasmem(struct pdb_methods *methods,
    3672                                      const DOM_SID *alias,
    3673                                      const DOM_SID *member)
     3654                                     const struct dom_sid *alias,
     3655                                     const struct dom_sid *member)
    36743656{
    36753657        return ldapsam_modify_aliasmem(methods, alias, member,
     
    36783660
    36793661static NTSTATUS ldapsam_enum_aliasmem(struct pdb_methods *methods,
    3680                                       const DOM_SID *alias,
     3662                                      const struct dom_sid *alias,
    36813663                                      TALLOC_CTX *mem_ctx,
    3682                                       DOM_SID **pp_members,
     3664                                      struct dom_sid **pp_members,
    36833665                                      size_t *p_num_members)
    36843666{
     
    36913673        int i;
    36923674        char *filter = NULL;
    3693         size_t num_members = 0;
     3675        uint32_t num_members = 0;
    36943676        enum lsa_SidType type = SID_NAME_USE_NONE;
    36953677        fstring tmp;
     
    37663748
    37673749        for (i=0; i<count; i++) {
    3768                 DOM_SID member;
     3750                struct dom_sid member;
    37693751                NTSTATUS status;
    37703752
     
    37903772static NTSTATUS ldapsam_alias_memberships(struct pdb_methods *methods,
    37913773                                          TALLOC_CTX *mem_ctx,
    3792                                           const DOM_SID *domain_sid,
    3793                                           const DOM_SID *members,
     3774                                          const struct dom_sid *domain_sid,
     3775                                          const struct dom_sid *members,
    37943776                                          size_t num_members,
    3795                                           uint32 **pp_alias_rids,
     3777                                          uint32_t **pp_alias_rids,
    37963778                                          size_t *p_num_alias_rids)
    37973779{
     
    38713853        {
    38723854                fstring sid_str;
    3873                 DOM_SID sid;
    3874                 uint32 rid;
     3855                struct dom_sid sid;
     3856                uint32_t rid;
    38753857
    38763858                if (!smbldap_get_single_attribute(ldap_struct, entry,
     
    39093891static NTSTATUS ldapsam_set_account_policy_in_ldap(struct pdb_methods *methods,
    39103892                                                   enum pdb_policy_type type,
    3911                                                    uint32 value)
     3893                                                   uint32_t value)
    39123894{
    39133895        NTSTATUS ntstatus = NT_STATUS_UNSUCCESSFUL;
     
    39653947static NTSTATUS ldapsam_get_account_policy_from_ldap(struct pdb_methods *methods,
    39663948                                                     enum pdb_policy_type type,
    3967                                                      uint32 *value)
     3949                                                     uint32_t *value)
    39683950{
    39693951        NTSTATUS ntstatus = NT_STATUS_UNSUCCESSFUL;
     
    39973979        attrs[1] = NULL;
    39983980
    3999         filter = talloc_asprintf(NULL, "(objectClass=%s)", LDAP_OBJ_DOMINFO);
     3981        filter = talloc_asprintf(talloc_tos(), "(objectClass=%s)", LDAP_OBJ_DOMINFO);
    40003982        if (filter == NULL) {
    40013983                return NT_STATUS_NO_MEMORY;
     
    40043986                            LDAP_SCOPE_BASE, filter, attrs, 0,
    40053987                            &result);
    4006 
     3988        TALLOC_FREE(filter);
    40073989        if (rc != LDAP_SUCCESS) {
    40083990                return ntstatus;
     
    40244006        }
    40254007
    4026         *value = (uint32)atol(vals[0]);
     4008        *value = (uint32_t)atol(vals[0]);
    40274009
    40284010        ntstatus = NT_STATUS_OK;
     
    41004082
    41014083static NTSTATUS ldapsam_lookup_rids(struct pdb_methods *methods,
    4102                                     const DOM_SID *domain_sid,
     4084                                    const struct dom_sid *domain_sid,
    41034085                                    int num_rids,
    4104                                     uint32 *rids,
     4086                                    uint32_t *rids,
    41054087                                    const char **names,
    41064088                                    enum lsa_SidType *attrs)
     
    41434125
    41444126        for (i=0; i<num_rids; i++) {
    4145                 DOM_SID sid;
     4127                struct dom_sid sid;
    41464128                sid_compose(&sid, domain_sid, rids[i]);
    41474129                allsids = talloc_asprintf_append_buffer(
     
    41834165             entry != NULL;
    41844166             entry = ldap_next_entry(ld, entry)) {
    4185                 uint32 rid;
     4167                uint32_t rid;
    41864168                int rid_index;
    41874169                const char *name;
     
    42574239             entry = ldap_next_entry(ld, entry))
    42584240        {
    4259                 uint32 rid;
     4241                uint32_t rid;
    42604242                int rid_index;
    42614243                const char *attr;
     
    43484330}
    43494331
    4350 const char **talloc_attrs(TALLOC_CTX *mem_ctx, ...)
     4332static const char **talloc_attrs(TALLOC_CTX *mem_ctx, ...)
    43514333{
    43524334        int i, num = 0;
     
    43814363        struct smbldap_state *connection;
    43824364
    4383         uint32 acct_flags;
    4384         uint16 group_type;
     4365        uint32_t acct_flags;
     4366        uint16_t group_type;
    43854367
    43864368        const char *base;
     
    45574539        char **vals;
    45584540        size_t converted_size;
    4559         DOM_SID sid;
    4560         uint32 acct_flags;
     4541        struct dom_sid sid;
     4542        uint32_t acct_flags;
    45614543
    45624544        vals = ldap_get_values(ld, entry, "sambaAcctFlags");
     
    46504632static bool ldapsam_search_users(struct pdb_methods *methods,
    46514633                                 struct pdb_search *search,
    4652                                  uint32 acct_flags)
     4634                                 uint32_t acct_flags)
    46534635{
    46544636        struct ldapsam_privates *ldap_state =
     
    47034685        char **vals;
    47044686        size_t converted_size;
    4705         DOM_SID sid;
    4706         uint16 group_type;
     4687        struct dom_sid sid;
     4688        uint16_t group_type;
    47074689
    47084690        result->account_name = "";
     
    48114793
    48124794                default:
    4813                         DEBUG(0,("unkown group type: %d\n", group_type));
     4795                        DEBUG(0,("unknown group type: %d\n", group_type));
    48144796                        return False;
    48154797        }
     
    48224804static bool ldapsam_search_grouptype(struct pdb_methods *methods,
    48234805                                     struct pdb_search *search,
    4824                                      const DOM_SID *sid,
     4806                                     const struct dom_sid *sid,
    48254807                                     enum lsa_SidType type)
    48264808{
     
    48744856static bool ldapsam_search_aliases(struct pdb_methods *methods,
    48754857                                   struct pdb_search *search,
    4876                                    const DOM_SID *sid)
     4858                                   const struct dom_sid *sid)
    48774859{
    48784860        return ldapsam_search_grouptype(methods, search, sid, SID_NAME_ALIAS);
     
    48854867
    48864868static NTSTATUS ldapsam_get_new_rid(struct ldapsam_privates *priv,
    4887                                     uint32 *rid)
     4869                                    uint32_t *rid)
    48884870{
    48894871        struct smbldap_state *smbldap_state = priv->smbldap_state;
     
    48954877        char *value;
    48964878        int rc;
    4897         uint32 nextRid = 0;
     4879        uint32_t nextRid = 0;
    48984880        const char *dn;
    48994881
     
    49324914                                                "sambaNextRid", mem_ctx);
    49334915        if (value != NULL) {
    4934                 uint32 tmp = (uint32)strtoul(value, NULL, 10);
     4916                uint32_t tmp = (uint32_t)strtoul(value, NULL, 10);
    49354917                nextRid = MAX(nextRid, tmp);
    49364918        }
     
    49394921                                                "sambaNextUserRid", mem_ctx);
    49404922        if (value != NULL) {
    4941                 uint32 tmp = (uint32)strtoul(value, NULL, 10);
     4923                uint32_t tmp = (uint32_t)strtoul(value, NULL, 10);
    49424924                nextRid = MAX(nextRid, tmp);
    49434925        }
     
    49464928                                                "sambaNextGroupRid", mem_ctx);
    49474929        if (value != NULL) {
    4948                 uint32 tmp = (uint32)strtoul(value, NULL, 10);
     4930                uint32_t tmp = (uint32_t)strtoul(value, NULL, 10);
    49494931                nextRid = MAX(nextRid, tmp);
    49504932        }
     
    49814963}
    49824964
    4983 static NTSTATUS ldapsam_new_rid_internal(struct pdb_methods *methods, uint32 *rid)
     4965static NTSTATUS ldapsam_new_rid_internal(struct pdb_methods *methods, uint32_t *rid)
    49844966{
    49854967        int i;
     
    50034985}
    50044986
    5005 static bool ldapsam_new_rid(struct pdb_methods *methods, uint32 *rid)
     4987static bool ldapsam_new_rid(struct pdb_methods *methods, uint32_t *rid)
    50064988{
    50074989        NTSTATUS result = ldapsam_new_rid_internal(methods, rid);
     
    50104992
    50114993static bool ldapsam_sid_to_id(struct pdb_methods *methods,
    5012                               const DOM_SID *sid,
     4994                              const struct dom_sid *sid,
    50134995                              union unid_t *id, enum lsa_SidType *type)
    50144996{
     
    51075089 */
    51085090static bool ldapsam_uid_to_sid(struct pdb_methods *methods, uid_t uid,
    5109                                DOM_SID *sid)
     5091                               struct dom_sid *sid)
    51105092{
    51115093        struct ldapsam_privates *priv =
     
    51175099        bool ret = false;
    51185100        char *user_sid_string;
    5119         DOM_SID *user_sid;
     5101        struct dom_sid user_sid;
    51205102        int rc;
    51215103        TALLOC_CTX *tmp_ctx = talloc_stackframe();
     
    51565138        }
    51575139
    5158         user_sid = string_sid_talloc(tmp_ctx, user_sid_string);
    5159         if (user_sid == NULL) {
     5140        if (!string_to_sid(&user_sid, user_sid_string)) {
    51605141                DEBUG(3, ("Error calling sid_string_talloc for sid '%s'\n",
    51615142                          user_sid_string));
     
    51635144        }
    51645145
    5165         sid_copy(sid, user_sid);
     5146        sid_copy(sid, &user_sid);
    51665147
    51675148        store_uid_sid_cache(sid, uid);
     
    51805161 */
    51815162static bool ldapsam_gid_to_sid(struct pdb_methods *methods, gid_t gid,
    5182                                DOM_SID *sid)
     5163                               struct dom_sid *sid)
    51835164{
    51845165        struct ldapsam_privates *priv =
     
    51905171        bool ret = false;
    51915172        char *group_sid_string;
    5192         DOM_SID group_sid;
     5173        struct dom_sid group_sid;
    51935174        int rc;
    51945175        TALLOC_CTX *tmp_ctx = talloc_stackframe();
     
    52625243static NTSTATUS ldapsam_create_user(struct pdb_methods *my_methods,
    52635244                                    TALLOC_CTX *tmp_ctx, const char *name,
    5264                                     uint32 acb_info, uint32 *rid)
     5245                                    uint32_t acb_info, uint32_t *rid)
    52655246{
    52665247        struct ldapsam_privates *ldap_state = (struct ldapsam_privates *)my_methods->private_data;
    52675248        LDAPMessage *entry = NULL;
    52685249        LDAPMessage *result = NULL;
    5269         uint32 num_result;
     5250        uint32_t num_result;
    52705251        bool is_machine = False;
    52715252        bool add_posix = False;
     
    52795260        char *shell;
    52805261        const char *dn = NULL;
    5281         DOM_SID group_sid;
    5282         DOM_SID user_sid;
     5262        struct dom_sid group_sid;
     5263        struct dom_sid user_sid;
    52835264        gid_t gid = -1;
    52845265        uid_t uid = -1;
     
    53875368        }
    53885369
    5389         if (!init_ldap_from_sam(ldap_state, NULL, &mods, user, element_is_set_or_changed)) {
     5370        if (!init_ldap_from_sam(ldap_state, entry, &mods, user, element_is_set_or_changed)) {
    53905371                DEBUG(1,("ldapsam_create_user: Unable to fill user structs\n"));
    53915372                return NT_STATUS_UNSUCCESSFUL;
     
    54035384
    54045385                /* retrieve the Domain Users group gid */
    5405                 if (!sid_compose(&group_sid, get_global_sam_sid(), DOMAIN_GROUP_RID_USERS) ||
     5386                if (!sid_compose(&group_sid, get_global_sam_sid(), DOMAIN_RID_USERS) ||
    54065387                    !sid_to_gid(&group_sid, &gid)) {
    54075388                        DEBUG (0, ("ldapsam_create_user: Unable to get the Domain Users gid: bailing out!\n"));
     
    55345515                struct dom_sid *sids = NULL;
    55355516                gid_t *gids = NULL;
    5536                 size_t num_groups = 0;
     5517                uint32_t num_groups = 0;
    55375518                int i;
    55385519                uint32_t user_rid = pdb_get_user_rid(sam_acct);
     
    55845565                                         TALLOC_CTX *tmp_ctx,
    55855566                                         const char *name,
    5586                                          uint32 *rid)
     5567                                         uint32_t *rid)
    55875568{
    55885569        struct ldapsam_privates *ldap_state = (struct ldapsam_privates *)my_methods->private_data;
     
    55905571        LDAPMessage *entry = NULL;
    55915572        LDAPMessage *result = NULL;
    5592         uint32 num_result;
     5573        uint32_t num_result;
    55935574        bool is_new_entry = False;
    55945575        LDAPMod **mods = NULL;
     
    55995580        char *gidstr;
    56005581        const char *dn = NULL;
    5601         DOM_SID group_sid;
     5582        struct dom_sid group_sid;
    56025583        gid_t gid = -1;
    56035584        int rc;
     
    56565637
    56575638        if (num_result == 0) {
     5639                is_new_entry = true;
     5640        }
     5641
     5642        if (!NT_STATUS_IS_OK((ret = ldapsam_new_rid_internal(my_methods, rid)))) {
     5643                DEBUG(1, ("ldapsam_create_group: Could not allocate a new RID\n"));
     5644                return ret;
     5645        }
     5646
     5647        sid_compose(&group_sid, get_global_sam_sid(), *rid);
     5648
     5649        groupsidstr = talloc_strdup(tmp_ctx, sid_string_talloc(tmp_ctx,
     5650                                                               &group_sid));
     5651        grouptype = talloc_asprintf(tmp_ctx, "%d", SID_NAME_DOM_GRP);
     5652
     5653        if (!groupsidstr || !grouptype) {
     5654                DEBUG(0,("ldapsam_create_group: Out of memory!\n"));
     5655                return NT_STATUS_NO_MEMORY;
     5656        }
     5657
     5658        smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
     5659        smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid", groupsidstr);
     5660        smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", grouptype);
     5661        smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", name);
     5662
     5663        if (is_new_entry) {
    56585664                char *escape_name;
    56595665
    56605666                DEBUG(3,("ldapsam_create_user: Creating new posix group\n"));
    5661 
    5662                 is_new_entry = True;
    56635667
    56645668                /* lets allocate a new groupid for this group */
     
    56905694        }
    56915695
    5692         if (!NT_STATUS_IS_OK((ret = ldapsam_new_rid_internal(my_methods, rid)))) {
    5693                 DEBUG(1, ("ldapsam_create_group: Could not allocate a new RID\n"));
    5694                 return ret;
    5695         }
    5696 
    5697         sid_compose(&group_sid, get_global_sam_sid(), *rid);
    5698 
    5699         groupsidstr = talloc_strdup(tmp_ctx, sid_string_talloc(tmp_ctx,
    5700                                                                &group_sid));
    5701         grouptype = talloc_asprintf(tmp_ctx, "%d", SID_NAME_DOM_GRP);
    5702 
    5703         if (!groupsidstr || !grouptype) {
    5704                 DEBUG(0,("ldapsam_create_group: Out of memory!\n"));
    5705                 return NT_STATUS_NO_MEMORY;
    5706         }
    5707 
    5708         smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_GROUPMAP);
    5709         smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaSid", groupsidstr);
    5710         smbldap_set_mod(&mods, LDAP_MOD_ADD, "sambaGroupType", grouptype);
    5711         smbldap_set_mod(&mods, LDAP_MOD_ADD, "displayName", name);
    57125696        talloc_autofree_ldapmod(tmp_ctx, mods);
    57135697
     
    57365720}
    57375721
    5738 static NTSTATUS ldapsam_delete_dom_group(struct pdb_methods *my_methods, TALLOC_CTX *tmp_ctx, uint32 rid)
     5722static NTSTATUS ldapsam_delete_dom_group(struct pdb_methods *my_methods, TALLOC_CTX *tmp_ctx, uint32_t rid)
    57395723{
    57405724        struct ldapsam_privates *ldap_state = (struct ldapsam_privates *)my_methods->private_data;
     
    57455729        char *gidstr;
    57465730        char *filter;
    5747         DOM_SID group_sid;
     5731        struct dom_sid group_sid;
    57485732        int rc;
    57495733
     
    58325816static NTSTATUS ldapsam_change_groupmem(struct pdb_methods *my_methods,
    58335817                                        TALLOC_CTX *tmp_ctx,
    5834                                         uint32 group_rid,
    5835                                         uint32 member_rid,
     5818                                        uint32_t group_rid,
     5819                                        uint32_t member_rid,
    58365820                                        int modop)
    58375821{
     
    58395823        LDAPMessage *entry = NULL;
    58405824        LDAPMessage *result = NULL;
    5841         uint32 num_result;
     5825        uint32_t num_result;
    58425826        LDAPMod **mods = NULL;
    58435827        char *filter;
    58445828        char *uidstr;
    58455829        const char *dn = NULL;
    5846         DOM_SID group_sid;
    5847         DOM_SID member_sid;
     5830        struct dom_sid group_sid;
     5831        struct dom_sid member_sid;
    58485832        int rc;
    58495833
     
    59945978static NTSTATUS ldapsam_add_groupmem(struct pdb_methods *my_methods,
    59955979                                     TALLOC_CTX *tmp_ctx,
    5996                                      uint32 group_rid,
    5997                                      uint32 member_rid)
     5980                                     uint32_t group_rid,
     5981                                     uint32_t member_rid)
    59985982{
    59995983        return ldapsam_change_groupmem(my_methods, tmp_ctx, group_rid, member_rid, LDAP_MOD_ADD);
     
    60015985static NTSTATUS ldapsam_del_groupmem(struct pdb_methods *my_methods,
    60025986                                     TALLOC_CTX *tmp_ctx,
    6003                                      uint32 group_rid,
    6004                                      uint32 member_rid)
     5987                                     uint32_t group_rid,
     5988                                     uint32_t member_rid)
    60055989{
    60065990        return ldapsam_change_groupmem(my_methods, tmp_ctx, group_rid, member_rid, LDAP_MOD_DELETE);
     
    60145998        LDAPMessage *entry = NULL;
    60155999        LDAPMessage *result = NULL;
    6016         uint32 num_result;
     6000        uint32_t num_result;
    60176001        LDAPMod **mods = NULL;
    60186002        char *filter;
     
    61296113        LDAPMessage *result = NULL;
    61306114        char *trusted_dn;
    6131         uint32 num_result;
     6115        uint32_t num_result;
    61326116
    61336117        filter = talloc_asprintf(talloc_tos(),
     
    61796163                                      const char *domain,
    61806164                                      char** pwd,
    6181                                       DOM_SID *sid,
     6165                                      struct dom_sid *sid,
    61826166                                      time_t *pass_last_set_time)
    61836167{
     
    62236207        if (sid != NULL) {
    62246208                char *sid_str;
    6225                 DOM_SID *dom_sid;
     6209                struct dom_sid dom_sid;
    62266210                sid_str = smbldap_talloc_single_attribute(priv2ld(ldap_state),
    62276211                                                          entry, "sambaSID",
     
    62306214                        return False;
    62316215                }
    6232                 dom_sid = string_sid_talloc(talloc_tos(), sid_str);
    6233                 if (dom_sid == NULL) {
     6216                if (!string_to_sid(&dom_sid, sid_str)) {
    62346217                        return False;
    62356218                }
    6236                 sid_copy(sid, dom_sid);
     6219                sid_copy(sid, &dom_sid);
    62376220        }
    62386221
     
    62436226                                      const char* domain,
    62446227                                      const char* pwd,
    6245                                       const DOM_SID *sid)
     6228                                      const struct dom_sid *sid)
    62466229{
    62476230        struct ldapsam_privates *ldap_state =
     
    63416324static NTSTATUS ldapsam_enum_trusteddoms(struct pdb_methods *methods,
    63426325                                         TALLOC_CTX *mem_ctx,
    6343                                          uint32 *num_domains,
     6326                                         uint32_t *num_domains,
    63446327                                         struct trustdom_info ***domains)
    63456328{
     
    65586541        NTSTATUS nt_status;
    65596542        struct ldapsam_privates *ldap_state = NULL;
    6560         uint32 alg_rid_base;
     6543        uint32_t alg_rid_base;
    65616544        char *alg_rid_base_string = NULL;
    65626545        LDAPMessage *result = NULL;
    65636546        LDAPMessage *entry = NULL;
    6564         DOM_SID ldap_domain_sid;
    6565         DOM_SID secrets_domain_sid;
     6547        struct dom_sid ldap_domain_sid;
     6548        struct dom_sid secrets_domain_sid;
    65666549        char *domain_sid_string = NULL;
    65676550        char *dn = NULL;
     
    65706553        trim_char( uri, '\"', '\"' );
    65716554        nt_status = pdb_init_ldapsam_common(pdb_method, uri);
    6572         if (uri) {
    6573                 TALLOC_FREE(uri);
    6574         }
     6555
     6556        TALLOC_FREE(uri);
    65756557
    65766558        if (!NT_STATUS_IS_OK(nt_status)) {
     
    66226604                DEBUGADD(2, ("pdb_init_ldapsam: Continuing on regardless, "
    66236605                             "will be unable to allocate new users/groups, "
    6624                              "and will risk BDCs having inconsistant SIDs\n"));
     6606                             "and will risk BDCs having inconsistent SIDs\n"));
    66256607                sid_copy(&ldap_state->domain_sid, get_global_sam_sid());
    66266608                return NT_STATUS_OK;
     
    66666648                found_sid = secrets_fetch_domain_sid(ldap_state->domain_name,
    66676649                                                     &secrets_domain_sid);
    6668                 if (!found_sid || !sid_equal(&secrets_domain_sid,
     6650                if (!found_sid || !dom_sid_equal(&secrets_domain_sid,
    66696651                                             &ldap_domain_sid)) {
    66706652                        DEBUG(1, ("pdb_init_ldapsam: Resetting SID for domain "
     
    66916673                    talloc_tos());
    66926674        if (alg_rid_base_string) {
    6693                 alg_rid_base = (uint32)atol(alg_rid_base_string);
     6675                alg_rid_base = (uint32_t)atol(alg_rid_base_string);
    66946676                if (alg_rid_base != algorithmic_rid_base()) {
    66956677                        DEBUG(0, ("The value of 'algorithmic RID base' has "
     
    67196701        pdb_nds_init();
    67206702
     6703        pdb_ipa_init();
     6704
    67216705        return NT_STATUS_OK;
    67226706}
Note: See TracChangeset for help on using the changeset viewer.