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:
4 deleted
15 edited
8 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

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

    r480 r745  
    33   struct samu local cache for
    44   Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2004.
    5      
     5
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    10    
     10
    1111   This program is distributed in the hope that it will be useful,
    1212   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414   GNU General Public License for more details.
    15    
     15
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "passdb.h"
     23#include "util_tdb.h"
    2124
    2225#undef DBGC_CLASS
     
    3235{
    3336        char* cache_fname = NULL;
    34        
     37
    3538        /* skip file open if it's already opened */
    3639        if (cache) return True;
     
    6467
    6568/* if we can't read the cache, oh well, no need to return anything */
    66 LOGIN_CACHE * login_cache_read(struct samu *sampass)
     69bool login_cache_read(struct samu *sampass, struct login_cache *entry)
    6770{
    6871        char *keystr;
    6972        TDB_DATA databuf;
    70         LOGIN_CACHE *entry;
    7173        uint32_t entry_timestamp = 0, bad_password_time = 0;
    7274        uint16_t acct_ctrl;
    7375
    74         if (!login_cache_init())
    75                 return NULL;
     76        if (!login_cache_init()) {
     77                return false;
     78        }
    7679
    7780        if (pdb_get_nt_username(sampass) == NULL) {
    78                 return NULL;
     81                return false;
    7982        }
    8083
     
    8285        if (!keystr || !keystr[0]) {
    8386                SAFE_FREE(keystr);
    84                 return NULL;
     87                return false;
    8588        }
    8689
     
    9093        SAFE_FREE(keystr);
    9194
    92         if (!(entry = SMB_MALLOC_P(LOGIN_CACHE))) {
    93                 DEBUG(1, ("Unable to allocate cache entry buffer!\n"));
    94                 SAFE_FREE(databuf.dptr);
    95                 return NULL;
    96         }
    9795        ZERO_STRUCTP(entry);
    9896
     
    103101                        &bad_password_time) == -1) {
    104102                DEBUG(7, ("No cache entry found\n"));
    105                 SAFE_FREE(entry);
    106103                SAFE_FREE(databuf.dptr);
    107                 return NULL;
     104                return false;
    108105        }
    109106
     
    123120                  (unsigned int)entry->entry_timestamp, entry->acct_ctrl,
    124121                  entry->bad_password_count, (unsigned int)entry->bad_password_time));
    125         return entry;
    126 }
    127 
    128 bool login_cache_write(const struct samu *sampass, LOGIN_CACHE entry)
     122        return true;
     123}
     124
     125bool login_cache_write(const struct samu *sampass,
     126                       const struct login_cache *entry)
    129127{
    130128        char *keystr;
     
    132130        bool ret;
    133131        uint32_t entry_timestamp;
    134         uint32_t bad_password_time = (uint32_t)entry.bad_password_time;
     132        uint32_t bad_password_time = entry->bad_password_time;
    135133
    136134        if (!login_cache_init())
     
    152150                tdb_pack(NULL, 0, SAM_CACHE_FORMAT,
    153151                         entry_timestamp,
    154                          entry.acct_ctrl,
    155                          entry.bad_password_count,
     152                         entry->acct_ctrl,
     153                         entry->bad_password_count,
    156154                         bad_password_time);
    157155        databuf.dptr = SMB_MALLOC_ARRAY(uint8, databuf.dsize);
     
    160158                return False;
    161159        }
    162                          
     160
    163161        if (tdb_pack(databuf.dptr, databuf.dsize, SAM_CACHE_FORMAT,
    164162                         entry_timestamp,
    165                          entry.acct_ctrl,
    166                          entry.bad_password_count,
     163                         entry->acct_ctrl,
     164                         entry->bad_password_count,
    167165                         bad_password_time)
    168166            != databuf.dsize) {
     
    182180        int ret;
    183181        char *keystr;
    184        
     182
    185183        if (!login_cache_init())
    186184                return False;   
     
    199197        ret = tdb_delete_bystring(cache, keystr);
    200198        DEBUG(9, ("tdb_delete returned %d\n", ret));
    201        
     199
    202200        SAFE_FREE(keystr);
    203201        return ret == 0;
  • trunk/server/source3/passdb/lookup_sid.c

    r414 r745  
    55   Copyright (C) Gerald (Jerry) Carter   2003
    66   Copyright (C) Volker Lendecke         2005
    7    
     7
    88   This program is free software; you can redistribute it and/or modify
    99   it under the terms of the GNU General Public License as published by
    1010   the Free Software Foundation; either version 3 of the License, or
    1111   (at your option) any later version.
    12    
     12
    1313   This program is distributed in the hope that it will be useful,
    1414   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1515   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1616   GNU General Public License for more details.
    17    
     17
    1818   You should have received a copy of the GNU General Public License
    1919   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2121
    2222#include "includes.h"
     23#include "passdb.h"
     24#include "../librpc/gen_ndr/ndr_security.h"
     25#include "secrets.h"
     26#include "memcache.h"
     27#include "idmap_cache.h"
     28#include "../libcli/security/security.h"
     29#include "lib/winbind_util.h"
    2330
    2431/*****************************************************************
     
    3340                 const char *full_name, int flags,
    3441                 const char **ret_domain, const char **ret_name,
    35                  DOM_SID *ret_sid, enum lsa_SidType *ret_type)
     42                 struct dom_sid *ret_sid, enum lsa_SidType *ret_type)
    3643{
    3744        char *p;
     
    4047        const char *name = NULL;
    4148        uint32 rid;
    42         DOM_SID sid;
     49        struct dom_sid sid;
    4350        enum lsa_SidType type;
    4451        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
     
    6673        }
    6774
    68         DEBUG(10,("lookup_name: %s => %s (domain), %s (name)\n",
     75        DEBUG(10,("lookup_name: %s => domain=[%s], name=[%s]\n",
    6976                full_name, domain, name));
    7077        DEBUG(10, ("lookup_name: flags = 0x0%x\n", flags));
     
    7683                /* It's our own domain, lookup the name in passdb */
    7784                if (lookup_global_sam_name(name, flags, &rid, &type)) {
    78                         sid_copy(&sid, get_global_sam_sid());
    79                         sid_append_rid(&sid, rid);
     85                        sid_compose(&sid, get_global_sam_sid(), rid);
    8086                        goto ok;
    8187                }
     
    97103                /* Explicit request for a name in BUILTIN */
    98104                if (lookup_builtin_name(name, &rid)) {
    99                         sid_copy(&sid, &global_sid_Builtin);
    100                         sid_append_rid(&sid, rid);
     105                        sid_compose(&sid, &global_sid_Builtin, rid);
    101106                        type = SID_NAME_ALIAS;
    102107                        goto ok;
     
    216221        {
    217222                domain = talloc_strdup(tmp_ctx, builtin_domain_name());
    218                 sid_copy(&sid, &global_sid_Builtin);
    219                 sid_append_rid(&sid, rid);
     223                sid_compose(&sid, &global_sid_Builtin, rid);
    220224                type = SID_NAME_ALIAS;
    221225                goto ok;
     
    231235        {
    232236                domain = talloc_strdup(tmp_ctx, get_global_sam_name());
    233                 sid_copy(&sid, get_global_sam_sid());
    234                 sid_append_rid(&sid, rid);
     237                sid_compose(&sid, get_global_sam_sid(), rid);
    235238                goto ok;
    236239        }
     
    258261
    259262        if (IS_DC && winbind_lookup_name("", name, &sid, &type)) {
    260                 DOM_SID dom_sid;
    261                 uint32 tmp_rid;
     263                struct dom_sid dom_sid;
    262264                enum lsa_SidType domain_type;
    263                
     265
    264266                if (type == SID_NAME_DOMAIN) {
    265267                        /* Swap name and type */
     
    273275
    274276                sid_copy(&dom_sid, &sid);
    275                 sid_split_rid(&dom_sid, &tmp_rid);
     277                sid_split_rid(&dom_sid, NULL);
    276278
    277279                if (!winbind_lookup_sid(tmp_ctx, &dom_sid, &domain, NULL,
     
    362364                 const char *full_name, int flags,
    363365                 const char **ret_domain, const char **ret_name,
    364                  DOM_SID *ret_sid, enum lsa_SidType *ret_type)
     366                 struct dom_sid *ret_sid, enum lsa_SidType *ret_type)
    365367{
    366368        char *qualified_name;
     
    403405                return true;
    404406        }
    405        
     407
    406408        /* Finally try with "Unix Users" or "Unix Group" */
    407409        qualified_name = talloc_asprintf(mem_ctx, "%s\\%s",
     
    420422
    421423static bool wb_lookup_rids(TALLOC_CTX *mem_ctx,
    422                            const DOM_SID *domain_sid,
     424                           const struct dom_sid *domain_sid,
    423425                           int num_rids, uint32 *rids,
    424426                           const char **domain_name,
     
    470472}
    471473
    472 static bool lookup_rids(TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid,
     474static bool lookup_rids(TALLOC_CTX *mem_ctx, const struct dom_sid *domain_sid,
    473475                        int num_rids, uint32_t *rids,
    474476                        const char **domain_name,
     
    544546        if (sid_check_is_wellknown_domain(domain_sid, NULL)) {
    545547                for (i=0; i<num_rids; i++) {
    546                         DOM_SID sid;
    547                         sid_copy(&sid, domain_sid);
    548                         sid_append_rid(&sid, rids[i]);
     548                        struct dom_sid sid;
     549                        sid_compose(&sid, domain_sid, rids[i]);
    549550                        if (lookup_wellknown_sid(mem_ctx, &sid,
    550551                                                 domain_name, &(*names)[i])) {
     
    606607 */
    607608
    608 static bool lookup_as_domain(const DOM_SID *sid, TALLOC_CTX *mem_ctx,
     609static bool lookup_as_domain(const struct dom_sid *sid, TALLOC_CTX *mem_ctx,
    609610                             const char **name)
    610611{
     
    657658
    658659                for (i=0; i<num_domains; i++) {
    659                         if (sid_equal(sid, &domains[i]->sid)) {
     660                        if (dom_sid_equal(sid, &domains[i]->sid)) {
    660661                                *name = talloc_strdup(mem_ctx,
    661662                                                      domains[i]->name);
     
    694695 */
    695696
    696 static bool check_dom_sid_to_level(const DOM_SID *sid, int level)
     697static bool check_dom_sid_to_level(const struct dom_sid *sid, int level)
    697698{
    698699        int ret = false;
     
    729730 * belonging to a domain and hands them in bulk to the appropriate lookup
    730731 * function. In particular pdb_lookup_rids with ldapsam_trusted benefits
    731  * *hugely* from this. Winbind is going to be extended with a lookup_rids
    732  * interface as well, so on a DC we can do a bulk lsa_lookuprids to the
    733  * appropriate DC.
     732 * *hugely* from this.
    734733 */
    735734
    736735NTSTATUS lookup_sids(TALLOC_CTX *mem_ctx, int num_sids,
    737                      const DOM_SID **sids, int level,
     736                     const struct dom_sid **sids, int level,
    738737                     struct lsa_dom_info **ret_domains,
    739738                     struct lsa_name_info **ret_names)
     
    783782
    784783        for (i=0; i<num_sids; i++) {
    785                 DOM_SID sid;
    786                 uint32 rid;
     784                struct dom_sid sid;
     785                uint32_t rid = 0;
    787786                const char *domain_name = NULL;
    788787
     
    802801                                goto fail;
    803802                        }
    804                                
     803
    805804                        name_infos[i].rid = 0;
    806805                        name_infos[i].type = SID_NAME_DOMAIN;
     
    836835                                break;
    837836                        }
    838                         if (sid_equal(&sid, &dom_infos[j].sid)) {
     837                        if (dom_sid_equal(&sid, &dom_infos[j].sid)) {
    839838                                break;
    840839                        }
     
    921920                        goto fail;
    922921                }
    923                        
     922
    924923                for (j=0; j<dom->num_idxs; j++) {
    925924                        int idx = dom->idxs[j];
     
    954953*****************************************************************/ 
    955954
    956 bool lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
     955bool lookup_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
    957956                const char **ret_domain, const char **ret_name,
    958957                enum lsa_SidType *ret_type)
     
    10181017*****************************************************************/
    10191018
    1020 static bool fetch_sid_from_uid_cache(DOM_SID *psid, uid_t uid)
     1019static bool fetch_sid_from_uid_cache(struct dom_sid *psid, uid_t uid)
    10211020{
    10221021        DATA_BLOB cache_value;
     
    10301029        memcpy(psid, cache_value.data, MIN(sizeof(*psid), cache_value.length));
    10311030        SMB_ASSERT(cache_value.length >= offsetof(struct dom_sid, id_auth));
    1032         SMB_ASSERT(cache_value.length == ndr_size_dom_sid(psid, NULL, 0));
     1031        SMB_ASSERT(cache_value.length == ndr_size_dom_sid(psid, 0));
    10331032
    10341033        return true;
     
    10391038*****************************************************************/
    10401039
    1041 static bool fetch_uid_from_cache( uid_t *puid, const DOM_SID *psid )
     1040static bool fetch_uid_from_cache( uid_t *puid, const struct dom_sid *psid )
    10421041{
    10431042        DATA_BLOB cache_value;
    10441043
    10451044        if (!memcache_lookup(NULL, SID_UID_CACHE,
    1046                              data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)),
     1045                             data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
    10471046                             &cache_value)) {
    10481047                return false;
     
    10591058*****************************************************************/
    10601059
    1061 void store_uid_sid_cache(const DOM_SID *psid, uid_t uid)
     1060void store_uid_sid_cache(const struct dom_sid *psid, uid_t uid)
    10621061{
    10631062        memcache_add(NULL, SID_UID_CACHE,
    1064                      data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)),
     1063                     data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
    10651064                     data_blob_const(&uid, sizeof(uid)));
    10661065        memcache_add(NULL, UID_SID_CACHE,
    10671066                     data_blob_const(&uid, sizeof(uid)),
    1068                      data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)));
     1067                     data_blob_const(psid, ndr_size_dom_sid(psid, 0)));
    10691068}
    10701069
     
    10731072*****************************************************************/
    10741073
    1075 static bool fetch_sid_from_gid_cache(DOM_SID *psid, gid_t gid)
     1074static bool fetch_sid_from_gid_cache(struct dom_sid *psid, gid_t gid)
    10761075{
    10771076        DATA_BLOB cache_value;
     
    10851084        memcpy(psid, cache_value.data, MIN(sizeof(*psid), cache_value.length));
    10861085        SMB_ASSERT(cache_value.length >= offsetof(struct dom_sid, id_auth));
    1087         SMB_ASSERT(cache_value.length == ndr_size_dom_sid(psid, NULL, 0));
     1086        SMB_ASSERT(cache_value.length == ndr_size_dom_sid(psid, 0));
    10881087
    10891088        return true;
     
    10941093*****************************************************************/
    10951094
    1096 static bool fetch_gid_from_cache(gid_t *pgid, const DOM_SID *psid)
     1095static bool fetch_gid_from_cache(gid_t *pgid, const struct dom_sid *psid)
    10971096{
    10981097        DATA_BLOB cache_value;
    10991098
    11001099        if (!memcache_lookup(NULL, SID_GID_CACHE,
    1101                              data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)),
     1100                             data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
    11021101                             &cache_value)) {
    11031102                return false;
     
    11141113*****************************************************************/
    11151114
    1116 void store_gid_sid_cache(const DOM_SID *psid, gid_t gid)
     1115void store_gid_sid_cache(const struct dom_sid *psid, gid_t gid)
    11171116{
    11181117        memcache_add(NULL, SID_GID_CACHE,
    1119                      data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)),
     1118                     data_blob_const(psid, ndr_size_dom_sid(psid, 0)),
    11201119                     data_blob_const(&gid, sizeof(gid)));
    11211120        memcache_add(NULL, GID_SID_CACHE,
    11221121                     data_blob_const(&gid, sizeof(gid)),
    1123                      data_blob_const(psid, ndr_size_dom_sid(psid, NULL, 0)));
     1122                     data_blob_const(psid, ndr_size_dom_sid(psid, 0)));
    11241123}
    11251124
     
    11281127*****************************************************************/ 
    11291128
    1130 static void legacy_uid_to_sid(DOM_SID *psid, uid_t uid)
     1129static void legacy_uid_to_sid(struct dom_sid *psid, uid_t uid)
    11311130{
    11321131        bool ret;
     
    11591158*****************************************************************/ 
    11601159
    1161 static void legacy_gid_to_sid(DOM_SID *psid, gid_t gid)
     1160static void legacy_gid_to_sid(struct dom_sid *psid, gid_t gid)
    11621161{
    11631162        bool ret;
     
    11731172                goto done;
    11741173        }
    1175        
     1174
    11761175        /* This is an unmapped group */
    11771176
     
    11901189*****************************************************************/ 
    11911190
    1192 static bool legacy_sid_to_uid(const DOM_SID *psid, uid_t *puid)
     1191static bool legacy_sid_to_uid(const struct dom_sid *psid, uid_t *puid)
    11931192{
    11941193        enum lsa_SidType type;
    1195         uint32 rid;
    1196 
    1197         if (sid_peek_check_rid(get_global_sam_sid(), psid, &rid)) {
     1194
     1195        if (sid_check_is_in_our_domain(psid)) {
    11981196                union unid_t id;
    11991197                bool ret;
     
    12341232*****************************************************************/ 
    12351233
    1236 static bool legacy_sid_to_gid(const DOM_SID *psid, gid_t *pgid)
    1237 {
    1238         uint32 rid;
     1234static bool legacy_sid_to_gid(const struct dom_sid *psid, gid_t *pgid)
     1235{
    12391236        GROUP_MAP map;
    12401237        union unid_t id;
     
    12581255        }
    12591256
    1260         if (sid_peek_check_rid(get_global_sam_sid(), psid, &rid)) {
     1257        if (sid_check_is_in_our_domain(psid)) {
    12611258                bool ret;
    12621259
     
    12761273                        goto done;
    12771274                }
    1278        
     1275
    12791276                /* This was ours, but it was not mapped.  Fail */
    12801277        }
     
    12831280                  sid_string_dbg(psid)));
    12841281        return false;
    1285        
     1282
    12861283 done:
    12871284        DEBUG(10,("LEGACY: sid %s -> gid %u\n", sid_string_dbg(psid),
     
    12971294*****************************************************************/ 
    12981295
    1299 void uid_to_sid(DOM_SID *psid, uid_t uid)
     1296void uid_to_sid(struct dom_sid *psid, uid_t uid)
    13001297{
    13011298        bool expired = true;
     
    13501347*****************************************************************/ 
    13511348
    1352 void gid_to_sid(DOM_SID *psid, gid_t gid)
     1349void gid_to_sid(struct dom_sid *psid, gid_t gid)
    13531350{
    13541351        bool expired = true;
     
    13991396}
    14001397
     1398bool sids_to_unix_ids(const struct dom_sid *sids, uint32_t num_sids,
     1399                      struct wbcUnixId *ids)
     1400{
     1401        struct wbcDomainSid *wbc_sids = NULL;
     1402        struct wbcUnixId *wbc_ids = NULL;
     1403        uint32_t i, num_not_cached;
     1404        wbcErr err;
     1405        bool ret = false;
     1406
     1407        wbc_sids = TALLOC_ARRAY(talloc_tos(), struct wbcDomainSid, num_sids);
     1408        if (wbc_sids == NULL) {
     1409                return false;
     1410        }
     1411
     1412        num_not_cached = 0;
     1413
     1414        for (i=0; i<num_sids; i++) {
     1415                bool expired;
     1416                uint32_t rid;
     1417
     1418                if (fetch_uid_from_cache(&ids[i].id.uid, &sids[i])) {
     1419                        ids[i].type = WBC_ID_TYPE_UID;
     1420                        continue;
     1421                }
     1422                if (fetch_gid_from_cache(&ids[i].id.gid, &sids[i])) {
     1423                        ids[i].type = WBC_ID_TYPE_GID;
     1424                        continue;
     1425                }
     1426                if (sid_peek_check_rid(&global_sid_Unix_Users,
     1427                                       &sids[i], &rid)) {
     1428                        ids[i].type = WBC_ID_TYPE_UID;
     1429                        ids[i].id.uid = rid;
     1430                        continue;
     1431                }
     1432                if (sid_peek_check_rid(&global_sid_Unix_Groups,
     1433                                       &sids[i], &rid)) {
     1434                        ids[i].type = WBC_ID_TYPE_GID;
     1435                        ids[i].id.gid = rid;
     1436                        continue;
     1437                }
     1438                if (idmap_cache_find_sid2uid(&sids[i], &ids[i].id.uid,
     1439                                             &expired)
     1440                    && !expired) {
     1441                        ids[i].type = WBC_ID_TYPE_UID;
     1442                        continue;
     1443                }
     1444                if (idmap_cache_find_sid2gid(&sids[i], &ids[i].id.gid,
     1445                                             &expired)
     1446                    && !expired) {
     1447                        ids[i].type = WBC_ID_TYPE_GID;
     1448                        continue;
     1449                }
     1450                ids[i].type = WBC_ID_TYPE_NOT_SPECIFIED;
     1451                memcpy(&wbc_sids[num_not_cached], &sids[i],
     1452                       ndr_size_dom_sid(&sids[i], 0));
     1453                num_not_cached += 1;
     1454        }
     1455        if (num_not_cached == 0) {
     1456                goto done;
     1457        }
     1458        wbc_ids = TALLOC_ARRAY(talloc_tos(), struct wbcUnixId, num_not_cached);
     1459        if (wbc_ids == NULL) {
     1460                goto fail;
     1461        }
     1462        for (i=0; i<num_not_cached; i++) {
     1463                wbc_ids[i].type = WBC_ID_TYPE_NOT_SPECIFIED;
     1464        }
     1465        err = wbcSidsToUnixIds(wbc_sids, num_not_cached, wbc_ids);
     1466        if (!WBC_ERROR_IS_OK(err)) {
     1467                DEBUG(10, ("wbcSidsToUnixIds returned %s\n",
     1468                           wbcErrorString(err)));
     1469        }
     1470
     1471        num_not_cached = 0;
     1472
     1473        for (i=0; i<num_sids; i++) {
     1474                if (ids[i].type == WBC_ID_TYPE_NOT_SPECIFIED) {
     1475                        ids[i] = wbc_ids[num_not_cached];
     1476                        num_not_cached += 1;
     1477                }
     1478        }
     1479
     1480        for (i=0; i<num_sids; i++) {
     1481                if (ids[i].type != WBC_ID_TYPE_NOT_SPECIFIED) {
     1482                        continue;
     1483                }
     1484                if (legacy_sid_to_gid(&sids[i], &ids[i].id.gid)) {
     1485                        ids[i].type = WBC_ID_TYPE_GID;
     1486                        continue;
     1487                }
     1488                if (legacy_sid_to_uid(&sids[i], &ids[i].id.uid)) {
     1489                        ids[i].type = WBC_ID_TYPE_UID;
     1490                        continue;
     1491                }
     1492        }
     1493done:
     1494        ret = true;
     1495fail:
     1496        TALLOC_FREE(wbc_ids);
     1497        TALLOC_FREE(wbc_sids);
     1498        return ret;
     1499}
     1500
    14011501/*****************************************************************
    14021502 *THE CANONICAL* convert SID to uid function.
    14031503*****************************************************************/ 
    14041504
    1405 bool sid_to_uid(const DOM_SID *psid, uid_t *puid)
     1505bool sid_to_uid(const struct dom_sid *psid, uid_t *puid)
    14061506{
    14071507        bool expired = true;
     
    14651565*****************************************************************/ 
    14661566
    1467 bool sid_to_gid(const DOM_SID *psid, gid_t *pgid)
     1567bool sid_to_gid(const struct dom_sid *psid, gid_t *pgid)
    14681568{
    14691569        bool expired = true;
     
    15211621        return true;
    15221622}
     1623
     1624/**
     1625 * @brief This function gets the primary group SID mapping the primary
     1626 *        GID of the user as obtained by an actual getpwnam() call.
     1627 *        This is necessary to avoid issues with arbitrary group SIDs
     1628 *        stored in passdb. We try as hard as we can to get the SID
     1629 *        corresponding to the GID, including trying group mapping.
     1630 *        If nothing else works, we will force "Domain Users" as the
     1631 *        primary group.
     1632 *        This is needed because we must always be able to lookup the
     1633 *        primary group SID, so we cannot settle for an arbitrary SID.
     1634 *
     1635 *        This call can be expensive. Use with moderation.
     1636 *        If you have a "samu" struct around use pdb_get_group_sid()
     1637 *        instead as it does properly cache results.
     1638 *
     1639 * @param mem_ctx[in]     The memory context iused to allocate the result.
     1640 * @param username[in]    The user's name
     1641 * @param _pwd[in|out]    If available, pass in user's passwd struct.
     1642 *                        It will contain a tallocated passwd if NULL was
     1643 *                        passed in.
     1644 * @param _group_sid[out] The user's Primary Group SID
     1645 *
     1646 * @return NTSTATUS error code.
     1647 */
     1648NTSTATUS get_primary_group_sid(TALLOC_CTX *mem_ctx,
     1649                                const char *username,
     1650                                struct passwd **_pwd,
     1651                                struct dom_sid **_group_sid)
     1652{
     1653        TALLOC_CTX *tmp_ctx;
     1654        bool need_lookup_sid = false;
     1655        struct dom_sid *group_sid;
     1656        struct passwd *pwd = *_pwd;
     1657
     1658        tmp_ctx = talloc_new(mem_ctx);
     1659        if (!tmp_ctx) {
     1660                return NT_STATUS_NO_MEMORY;
     1661        }
     1662
     1663        if (!pwd) {
     1664                pwd = Get_Pwnam_alloc(mem_ctx, username);
     1665                if (!pwd) {
     1666                        DEBUG(0, ("Failed to find a Unix account for %s",
     1667                                  username));
     1668                        TALLOC_FREE(tmp_ctx);
     1669                        return NT_STATUS_NO_SUCH_USER;
     1670                }
     1671        }
     1672
     1673        group_sid = talloc_zero(mem_ctx, struct dom_sid);
     1674        if (!group_sid) {
     1675                TALLOC_FREE(tmp_ctx);
     1676                return NT_STATUS_NO_MEMORY;
     1677        }
     1678
     1679        gid_to_sid(group_sid, pwd->pw_gid);
     1680        if (!is_null_sid(group_sid)) {
     1681                struct dom_sid domain_sid;
     1682                uint32_t rid;
     1683
     1684                /* We need a sid within our domain */
     1685                sid_copy(&domain_sid, group_sid);
     1686                sid_split_rid(&domain_sid, &rid);
     1687                if (dom_sid_equal(&domain_sid, get_global_sam_sid())) {
     1688                        /*
     1689                         * As shortcut for the expensive lookup_sid call
     1690                         * compare the domain sid part
     1691                         */
     1692                        switch (rid) {
     1693                        case DOMAIN_RID_ADMINS:
     1694                        case DOMAIN_RID_USERS:
     1695                                goto done;
     1696                        default:
     1697                                need_lookup_sid = true;
     1698                                break;
     1699                        }
     1700                } else {
     1701                        /* Try group mapping */
     1702                        ZERO_STRUCTP(group_sid);
     1703                        if (pdb_gid_to_sid(pwd->pw_gid, group_sid)) {
     1704                                need_lookup_sid = true;
     1705                        }
     1706                }
     1707        }
     1708
     1709        /* We must verify that this is a valid SID that resolves to a
     1710         * group of the correct type */
     1711        if (need_lookup_sid) {
     1712                enum lsa_SidType type = SID_NAME_UNKNOWN;
     1713                bool lookup_ret;
     1714
     1715                DEBUG(10, ("do lookup_sid(%s) for group of user %s\n",
     1716                           sid_string_dbg(group_sid), username));
     1717
     1718                /* Now check that it's actually a domain group and
     1719                 * not something else */
     1720                lookup_ret = lookup_sid(tmp_ctx, group_sid,
     1721                                        NULL, NULL, &type);
     1722
     1723                if (lookup_ret && (type == SID_NAME_DOM_GRP)) {
     1724                        goto done;
     1725                }
     1726
     1727                DEBUG(3, ("Primary group %s for user %s is"
     1728                          " a %s and not a domain group\n",
     1729                          sid_string_dbg(group_sid), username,
     1730                          sid_type_lookup(type)));
     1731        }
     1732
     1733        /* Everything else, failed.
     1734         * Just set it to the 'Domain Users' RID of 513 which will
     1735           always resolve to a name */
     1736        DEBUG(3, ("Forcing Primary Group to 'Domain Users' for %s\n",
     1737                  username));
     1738
     1739        sid_compose(group_sid, get_global_sam_sid(), DOMAIN_RID_USERS);
     1740
     1741done:
     1742        *_pwd = talloc_move(mem_ctx, &pwd);
     1743        *_group_sid = talloc_move(mem_ctx, &group_sid);
     1744        TALLOC_FREE(tmp_ctx);
     1745        return NT_STATUS_OK;
     1746}
     1747
     1748bool delete_uid_cache(uid_t puid)
     1749{
     1750        DATA_BLOB uid = data_blob_const(&puid, sizeof(puid));
     1751        DATA_BLOB sid;
     1752
     1753        if (!memcache_lookup(NULL, UID_SID_CACHE, uid, &sid)) {
     1754                DEBUG(3, ("UID %d is not memcached!\n", (int)puid));
     1755                return false;
     1756        }
     1757        DEBUG(3, ("Delete mapping UID %d <-> %s from memcache\n", (int)puid,
     1758                  sid_string_dbg((struct dom_sid*)sid.data)));
     1759        memcache_delete(NULL, SID_UID_CACHE, sid);
     1760        memcache_delete(NULL, UID_SID_CACHE, uid);
     1761        return true;
     1762}
     1763
     1764bool delete_gid_cache(gid_t pgid)
     1765{
     1766        DATA_BLOB gid = data_blob_const(&pgid, sizeof(pgid));
     1767        DATA_BLOB sid;
     1768        if (!memcache_lookup(NULL, GID_SID_CACHE, gid, &sid)) {
     1769                DEBUG(3, ("GID %d is not memcached!\n", (int)pgid));
     1770                return false;
     1771        }
     1772        DEBUG(3, ("Delete mapping GID %d <-> %s from memcache\n", (int)pgid,
     1773                  sid_string_dbg((struct dom_sid*)sid.data)));
     1774        memcache_delete(NULL, SID_GID_CACHE, sid);
     1775        memcache_delete(NULL, GID_SID_CACHE, gid);
     1776        return true;
     1777}
     1778
     1779bool delete_sid_cache(const struct dom_sid* psid)
     1780{
     1781        DATA_BLOB sid = data_blob_const(psid, ndr_size_dom_sid(psid, 0));
     1782        DATA_BLOB id;
     1783        if (memcache_lookup(NULL, SID_GID_CACHE, sid, &id)) {
     1784                DEBUG(3, ("Delete mapping %s <-> GID %d from memcache\n",
     1785                          sid_string_dbg(psid), *(int*)id.data));
     1786                memcache_delete(NULL, SID_GID_CACHE, sid);
     1787                memcache_delete(NULL, GID_SID_CACHE, id);
     1788        } else if (memcache_lookup(NULL, SID_UID_CACHE, sid, &id)) {
     1789                DEBUG(3, ("Delete mapping %s <-> UID %d from memcache\n",
     1790                          sid_string_dbg(psid), *(int*)id.data));
     1791                memcache_delete(NULL, SID_UID_CACHE, sid);
     1792                memcache_delete(NULL, UID_SID_CACHE, id);
     1793        } else {
     1794                DEBUG(3, ("SID %s is not memcached!\n", sid_string_dbg(psid)));
     1795                return false;
     1796        }
     1797        return true;
     1798}
     1799
     1800void flush_gid_cache(void)
     1801{
     1802        DEBUG(3, ("Flush GID <-> SID memcache\n"));
     1803        memcache_flush(NULL, SID_GID_CACHE);
     1804        memcache_flush(NULL, GID_SID_CACHE);
     1805}
     1806
     1807void flush_uid_cache(void)
     1808{
     1809        DEBUG(3, ("Flush UID <-> SID memcache\n"));
     1810        memcache_flush(NULL, SID_UID_CACHE);
     1811        memcache_flush(NULL, UID_SID_CACHE);
     1812}
  • trunk/server/source3/passdb/machine_sid.c

    r414 r745  
    66   Copyright (C) Gerald (Jerry) Carter          2000
    77   Copyright (C) Stefan (metze) Metzmacher      2002
    8      
     8
    99   This program is free software; you can redistribute it and/or modify
    1010   it under the terms of the GNU General Public License as published by
    1111   the Free Software Foundation; either version 3 of the License, or
    1212   (at your option) any later version.
    13    
     13
    1414   This program is distributed in the hope that it will be useful,
    1515   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1616   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1717   GNU General Public License for more details.
    18    
     18
    1919   You should have received a copy of the GNU General Public License
    2020   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2222
    2323#include "includes.h"
     24#include "passdb.h"
     25#include "secrets.h"
     26#include "dbwrap.h"
     27#include "../libcli/security/security.h"
    2428
    2529/* NOTE! the global_sam_sid is the SID of our local SAM. This is only
    2630   equal to the domain SID when we are a DC, otherwise its our
    2731   workstation SID */
    28 static DOM_SID *global_sam_sid=NULL;
     32static struct dom_sid *global_sam_sid=NULL;
    2933
    3034#undef DBGC_CLASS
     
    3640****************************************************************************/
    3741
    38 static bool read_sid_from_file(const char *fname, DOM_SID *sid)
     42static bool read_sid_from_file(const char *fname, struct dom_sid *sid)
    3943{
    4044        char **lines;
     
    4347
    4448        lines = file_lines_load(fname, &numlines,0, NULL);
    45        
     49
    4650        if (!lines || numlines < 1) {
    47                 if (lines) TALLOC_FREE(lines);
     51                TALLOC_FREE(lines);
    4852                return False;
    4953        }
    50        
     54
    5155        ret = string_to_sid(sid, lines[0]);
    5256        TALLOC_FREE(lines);
     
    5761  generate a random sid - used to build our own sid if we don't have one
    5862*/
    59 static void generate_random_sid(DOM_SID *sid)
     63static void generate_random_sid(struct dom_sid *sid)
    6064{
    6165        int i;
    6266        uchar raw_sid_data[12];
    6367
    64         memset((char *)sid, '\0', sizeof(*sid));
     68        ZERO_STRUCTP(sid);
     69
    6570        sid->sid_rev_num = 1;
    6671        sid->id_auth[5] = 5;
     
    7782****************************************************************************/
    7883
    79 static DOM_SID *pdb_generate_sam_sid(void)
    80 {
    81         DOM_SID domain_sid;
     84static struct dom_sid *pdb_generate_sam_sid(void)
     85{
     86        struct dom_sid domain_sid;
    8287        char *fname = NULL;
    83         DOM_SID *sam_sid;
    84        
    85         if(!(sam_sid=SMB_MALLOC_P(DOM_SID)))
     88        struct dom_sid *sam_sid;
     89
     90        if(!(sam_sid=SMB_MALLOC_P(struct dom_sid)))
    8691                return NULL;
    8792
     
    111116                }
    112117
    113                 if (!sid_equal(&domain_sid, sam_sid)) {
     118                if (!dom_sid_equal(&domain_sid, sam_sid)) {
    114119
    115120                        /* Domain name sid doesn't match global sam sid. Re-store domain sid as 'local' sid. */
     
    125130
    126131                return sam_sid;
    127                
    128132        }
    129133
     
    180184
    181185/* return our global_sam_sid */
    182 DOM_SID *get_global_sam_sid(void)
     186struct dom_sid *get_global_sam_sid(void)
    183187{
    184188        struct db_context *db;
     
    186190        if (global_sam_sid != NULL)
    187191                return global_sam_sid;
    188        
     192
    189193        /*
    190194         * memory for global_sam_sid is allocated in
     
    229233*****************************************************************/ 
    230234
    231 bool sid_check_is_domain(const DOM_SID *sid)
    232 {
    233         return sid_equal(sid, get_global_sam_sid());
     235bool sid_check_is_domain(const struct dom_sid *sid)
     236{
     237        return dom_sid_equal(sid, get_global_sam_sid());
    234238}
    235239
     
    238242*****************************************************************/ 
    239243
    240 bool sid_check_is_in_our_domain(const DOM_SID *sid)
    241 {
    242         DOM_SID dom_sid;
    243         uint32 rid;
     244bool sid_check_is_in_our_domain(const struct dom_sid *sid)
     245{
     246        struct dom_sid dom_sid;
    244247
    245248        sid_copy(&dom_sid, sid);
    246         sid_split_rid(&dom_sid, &rid);
     249        sid_split_rid(&dom_sid, NULL);
    247250        return sid_check_is_domain(&dom_sid);
    248251}
  • trunk/server/source3/passdb/passdb.c

    r429 r745  
    2424
    2525#include "includes.h"
     26#include "passdb.h"
     27#include "system/passwd.h"
    2628#include "../libcli/auth/libcli_auth.h"
     29#include "secrets.h"
     30#include "../libcli/security/security.h"
     31#include "../lib/util/util_pw.h"
     32#include "util_tdb.h"
    2733
    2834#undef DBGC_CLASS
     
    146152        const char *domain = global_myname();
    147153        char *fullname;
    148         uint32 urid;
     154        uint32_t urid;
    149155
    150156        if ( !pwd ) {
     
    194200
    195201        if ( strequal( pwd->pw_name, guest_account ) ) {
    196                 if ( !pdb_set_user_sid_from_rid(user, DOMAIN_USER_RID_GUEST, PDB_DEFAULT)) {
     202                if ( !pdb_set_user_sid_from_rid(user, DOMAIN_RID_GUEST, PDB_DEFAULT)) {
    197203                        return NT_STATUS_NO_SUCH_USER;
    198204                }
     
    242248
    243249        if ( create && (pdb_capabilities() & PDB_CAP_STORE_RIDS)) {
    244                 uint32 user_rid;
    245                 DOM_SID user_sid;
     250                uint32_t user_rid;
     251                struct dom_sid user_sid;
    246252
    247253                if ( !pdb_new_rid( &user_rid ) ) {
     
    250256                }
    251257
    252                 sid_copy( &user_sid, get_global_sam_sid() );
    253                 sid_append_rid( &user_sid, user_rid );
     258                sid_compose(&user_sid, get_global_sam_sid(), user_rid);
    254259
    255260                if ( !pdb_set_user_sid(user, &user_sid, PDB_SET) ) {
     
    373378**************************************************************/
    374379
    375 void pdb_sethexpwd(char p[33], const unsigned char *pwd, uint32 acct_ctrl)
     380void pdb_sethexpwd(char p[33], const unsigned char *pwd, uint32_t acct_ctrl)
    376381{
    377382        if (pwd != NULL) {
     
    403408
    404409        for (i = 0; i < 32; i += 2) {
    405                 hinybble = toupper_ascii(p[i]);
    406                 lonybble = toupper_ascii(p[i + 1]);
     410                hinybble = toupper_m(p[i]);
     411                lonybble = toupper_m(p[i + 1]);
    407412
    408413                p1 = strchr(hexchars, hinybble);
     
    453458
    454459        for (i = 0; i < 42; i += 2) {
    455                 hinybble = toupper_ascii(p[i]);
    456                 lonybble = toupper_ascii(p[i + 1]);
     460                hinybble = toupper_m(p[i]);
     461                lonybble = toupper_m(p[i + 1]);
    457462
    458463                p1 = strchr(hexchars, hinybble);
     
    497502 ********************************************************************/
    498503
    499 uid_t algorithmic_pdb_user_rid_to_uid(uint32 user_rid)
     504uid_t algorithmic_pdb_user_rid_to_uid(uint32_t user_rid)
    500505{
    501506        int rid_offset = algorithmic_rid_base();
     
    512517 ********************************************************************/
    513518
    514 uint32 algorithmic_pdb_uid_to_user_rid(uid_t uid)
     519uint32_t algorithmic_pdb_uid_to_user_rid(uid_t uid)
    515520{
    516521        int rid_offset = algorithmic_rid_base();
    517         return (((((uint32)uid)*RID_MULTIPLIER) + rid_offset) | USER_RID_TYPE);
     522        return (((((uint32_t)uid)*RID_MULTIPLIER) + rid_offset) | USER_RID_TYPE);
    518523}
    519524
     
    522527 ********************************************************************/
    523528
    524 gid_t pdb_group_rid_to_gid(uint32 group_rid)
     529gid_t pdb_group_rid_to_gid(uint32_t group_rid)
    525530{
    526531        int rid_offset = algorithmic_rid_base();
     
    541546 ********************************************************************/
    542547
    543 uint32 algorithmic_pdb_gid_to_group_rid(gid_t gid)
     548uint32_t algorithmic_pdb_gid_to_group_rid(gid_t gid)
    544549{
    545550        int rid_offset = algorithmic_rid_base();
    546         return (((((uint32)gid)*RID_MULTIPLIER) + rid_offset) | GROUP_RID_TYPE);
     551        return (((((uint32_t)gid)*RID_MULTIPLIER) + rid_offset) | GROUP_RID_TYPE);
    547552}
    548553
     
    551556 ********************************************************************/
    552557
    553 static bool rid_is_well_known(uint32 rid)
     558static bool rid_is_well_known(uint32_t rid)
    554559{
    555560        /* Not using rid_offset here, because this is the actual
     
    563568 ********************************************************************/
    564569
    565 bool algorithmic_pdb_rid_is_user(uint32 rid)
     570bool algorithmic_pdb_rid_is_user(uint32_t rid)
    566571{
    567572        if ( rid_is_well_known(rid) ) {
    568573                /*
    569                  * The only well known user RIDs are DOMAIN_USER_RID_ADMIN
    570                  * and DOMAIN_USER_RID_GUEST.
     574                 * The only well known user RIDs are DOMAIN_RID_ADMINISTRATOR
     575                 * and DOMAIN_RID_GUEST.
    571576                 */
    572                 if(rid == DOMAIN_USER_RID_ADMIN || rid == DOMAIN_USER_RID_GUEST)
     577                if(rid == DOMAIN_RID_ADMINISTRATOR || rid == DOMAIN_RID_GUEST)
    573578                        return True;
    574579        } else if((rid & RID_TYPE_MASK) == USER_RID_TYPE) {
     
    594599
    595600        if ( strequal( name, "None" ) ) {
    596                 *rid = DOMAIN_GROUP_RID_USERS;
     601                *rid = DOMAIN_RID_USERS;
    597602                *type = SID_NAME_DOM_GRP;
    598603
     
    606611        if ((flags & LOOKUP_NAME_GROUP) == 0) {
    607612                struct samu *sam_account = NULL;
    608                 DOM_SID user_sid;
     613                struct dom_sid user_sid;
    609614
    610615                if ( !(sam_account = samu_new( NULL )) ) {
     
    927932*********************************************************************/
    928933
    929 static bool init_samu_from_buffer_v0(struct samu *sampass, uint8 *buf, uint32 buflen)
     934static bool init_samu_from_buffer_v0(struct samu *sampass, uint8_t *buf, uint32_t buflen)
    930935{
    931936
     
    933938           take care on system with 64bit wide time_t
    934939           --SSS */
    935         uint32  logon_time,
     940        uint32_t        logon_time,
    936941                logoff_time,
    937942                kickoff_time,
     
    951956        char *acct_desc = NULL;
    952957        char *workstations = NULL;
    953         uint32  username_len, domain_len, nt_username_len,
     958        uint32_t        username_len, domain_len, nt_username_len,
    954959                dir_drive_len, unknown_str_len, munged_dial_len,
    955960                fullname_len, homedir_len, logon_script_len,
    956961                profile_path_len, acct_desc_len, workstations_len;
    957962
    958         uint32  user_rid, group_rid, remove_me, hours_len, unknown_6;
    959         uint16  acct_ctrl, logon_divs;
    960         uint16  bad_password_count, logon_count;
    961         uint8   *hours = NULL;
    962         uint8   *lm_pw_ptr = NULL, *nt_pw_ptr = NULL;
    963         uint32          len = 0;
    964         uint32          lm_pw_len, nt_pw_len, hourslen;
     963        uint32_t        user_rid, group_rid, remove_me, hours_len, unknown_6;
     964        uint16_t        acct_ctrl, logon_divs;
     965        uint16_t        bad_password_count, logon_count;
     966        uint8_t *hours = NULL;
     967        uint8_t *lm_pw_ptr = NULL, *nt_pw_ptr = NULL;
     968        uint32_t                len = 0;
     969        uint32_t                lm_pw_len, nt_pw_len, hourslen;
    965970        bool ret = True;
    966971
     
    10051010                &unknown_6);                                            /* d */
    10061011
    1007         if (len == (uint32) -1)  {
     1012        if (len == (uint32_t) -1)  {
    10081013                ret = False;
    10091014                goto done;
     
    10861091        pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET);
    10871092        pdb_set_logon_divs(sampass, logon_divs, PDB_SET);
    1088         pdb_set_hours(sampass, hours, PDB_SET);
     1093        pdb_set_hours(sampass, hours, hours_len, PDB_SET);
    10891094
    10901095done:
     
    11121117*********************************************************************/
    11131118
    1114 static bool init_samu_from_buffer_v1(struct samu *sampass, uint8 *buf, uint32 buflen)
     1119static bool init_samu_from_buffer_v1(struct samu *sampass, uint8_t *buf, uint32_t buflen)
    11151120{
    11161121
     
    11181123           take care on system with 64bit wide time_t
    11191124           --SSS */
    1120         uint32  logon_time,
     1125        uint32_t        logon_time,
    11211126                logoff_time,
    11221127                kickoff_time,
     
    11371142        char *acct_desc = NULL;
    11381143        char *workstations = NULL;
    1139         uint32  username_len, domain_len, nt_username_len,
     1144        uint32_t        username_len, domain_len, nt_username_len,
    11401145                dir_drive_len, unknown_str_len, munged_dial_len,
    11411146                fullname_len, homedir_len, logon_script_len,
    11421147                profile_path_len, acct_desc_len, workstations_len;
    11431148
    1144         uint32  user_rid, group_rid, remove_me, hours_len, unknown_6;
    1145         uint16  acct_ctrl, logon_divs;
    1146         uint16  bad_password_count, logon_count;
    1147         uint8   *hours = NULL;
    1148         uint8   *lm_pw_ptr = NULL, *nt_pw_ptr = NULL;
    1149         uint32          len = 0;
    1150         uint32          lm_pw_len, nt_pw_len, hourslen;
     1149        uint32_t        user_rid, group_rid, remove_me, hours_len, unknown_6;
     1150        uint16_t        acct_ctrl, logon_divs;
     1151        uint16_t        bad_password_count, logon_count;
     1152        uint8_t *hours = NULL;
     1153        uint8_t *lm_pw_ptr = NULL, *nt_pw_ptr = NULL;
     1154        uint32_t                len = 0;
     1155        uint32_t                lm_pw_len, nt_pw_len, hourslen;
    11511156        bool ret = True;
    11521157
     
    11931198                &unknown_6);                                            /* d */
    11941199
    1195         if (len == (uint32) -1)  {
     1200        if (len == (uint32_t) -1)  {
    11961201                ret = False;
    11971202                goto done;
     
    12781283        pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET);
    12791284        pdb_set_logon_divs(sampass, logon_divs, PDB_SET);
    1280         pdb_set_hours(sampass, hours, PDB_SET);
     1285        pdb_set_hours(sampass, hours, hours_len, PDB_SET);
    12811286
    12821287done:
     
    13011306}
    13021307
    1303 static bool init_samu_from_buffer_v2(struct samu *sampass, uint8 *buf, uint32 buflen)
     1308static bool init_samu_from_buffer_v2(struct samu *sampass, uint8_t *buf, uint32_t buflen)
    13041309{
    13051310
     
    13071312           take care on system with 64bit wide time_t
    13081313           --SSS */
    1309         uint32  logon_time,
     1314        uint32_t        logon_time,
    13101315                logoff_time,
    13111316                kickoff_time,
     
    13261331        char *acct_desc = NULL;
    13271332        char *workstations = NULL;
    1328         uint32  username_len, domain_len, nt_username_len,
     1333        uint32_t        username_len, domain_len, nt_username_len,
    13291334                dir_drive_len, unknown_str_len, munged_dial_len,
    13301335                fullname_len, homedir_len, logon_script_len,
    13311336                profile_path_len, acct_desc_len, workstations_len;
    13321337
    1333         uint32  user_rid, group_rid, hours_len, unknown_6;
    1334         uint16  acct_ctrl, logon_divs;
    1335         uint16  bad_password_count, logon_count;
    1336         uint8   *hours = NULL;
    1337         uint8   *lm_pw_ptr = NULL, *nt_pw_ptr = NULL, *nt_pw_hist_ptr = NULL;
    1338         uint32          len = 0;
    1339         uint32          lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen;
    1340         uint32 pwHistLen = 0;
     1338        uint32_t        user_rid, group_rid, hours_len, unknown_6;
     1339        uint16_t        acct_ctrl, logon_divs;
     1340        uint16_t        bad_password_count, logon_count;
     1341        uint8_t *hours = NULL;
     1342        uint8_t *lm_pw_ptr = NULL, *nt_pw_ptr = NULL, *nt_pw_hist_ptr = NULL;
     1343        uint32_t                len = 0;
     1344        uint32_t                lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen;
     1345        uint32_t pwHistLen = 0;
    13411346        bool ret = True;
    13421347        fstring tmp_string;
     
    13861391                &unknown_6);                                            /* d */
    13871392
    1388         if (len == (uint32) -1)  {
     1393        if (len == (uint32_t) -1)  {
    13891394                ret = False;
    13901395                goto done;
     
    14751480        pdb_get_account_policy(PDB_POLICY_PASSWORD_HISTORY, &pwHistLen);
    14761481        if (pwHistLen) {
    1477                 uint8 *pw_hist = SMB_MALLOC_ARRAY(uint8, pwHistLen * PW_HISTORY_ENTRY_LEN);
     1482                uint8_t *pw_hist = SMB_MALLOC_ARRAY(uint8_t, pwHistLen * PW_HISTORY_ENTRY_LEN);
    14781483                if (!pw_hist) {
    14791484                        ret = False;
     
    15091514        pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET);
    15101515        pdb_set_logon_divs(sampass, logon_divs, PDB_SET);
    1511         pdb_set_hours(sampass, hours, PDB_SET);
     1516        pdb_set_hours(sampass, hours, hours_len, PDB_SET);
    15121517
    15131518done:
     
    15361541*********************************************************************/
    15371542
    1538 static bool init_samu_from_buffer_v3(struct samu *sampass, uint8 *buf, uint32 buflen)
     1543static bool init_samu_from_buffer_v3(struct samu *sampass, uint8_t *buf, uint32_t buflen)
    15391544{
    15401545
     
    15421547           take care on system with 64bit wide time_t
    15431548           --SSS */
    1544         uint32  logon_time,
     1549        uint32_t        logon_time,
    15451550                logoff_time,
    15461551                kickoff_time,
     
    15611566        char *acct_desc = NULL;
    15621567        char *workstations = NULL;
    1563         uint32  username_len, domain_len, nt_username_len,
     1568        uint32_t        username_len, domain_len, nt_username_len,
    15641569                dir_drive_len, comment_len, munged_dial_len,
    15651570                fullname_len, homedir_len, logon_script_len,
    15661571                profile_path_len, acct_desc_len, workstations_len;
    15671572
    1568         uint32  user_rid, group_rid, hours_len, unknown_6, acct_ctrl;
    1569         uint16  logon_divs;
    1570         uint16  bad_password_count, logon_count;
    1571         uint8   *hours = NULL;
    1572         uint8   *lm_pw_ptr = NULL, *nt_pw_ptr = NULL, *nt_pw_hist_ptr = NULL;
    1573         uint32          len = 0;
    1574         uint32          lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen;
    1575         uint32 pwHistLen = 0;
     1573        uint32_t        user_rid, group_rid, hours_len, unknown_6, acct_ctrl;
     1574        uint16_t  logon_divs;
     1575        uint16_t        bad_password_count, logon_count;
     1576        uint8_t *hours = NULL;
     1577        uint8_t *lm_pw_ptr = NULL, *nt_pw_ptr = NULL, *nt_pw_hist_ptr = NULL;
     1578        uint32_t                len = 0;
     1579        uint32_t                lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen;
     1580        uint32_t pwHistLen = 0;
    15761581        bool ret = True;
    15771582        fstring tmp_string;
     
    16121617                /* Change from V1 is addition of password history field. */
    16131618                &nt_pw_hist_len, &nt_pw_hist_ptr,                       /* B */
    1614                 /* Change from V2 is the uint32 acb_mask */
     1619                /* Change from V2 is the uint32_t acb_mask */
    16151620                &acct_ctrl,                                             /* d */
    16161621                /* Also "remove_me" field was removed. */
     
    16221627                &unknown_6);                                            /* d */
    16231628
    1624         if (len == (uint32) -1)  {
     1629        if (len == (uint32_t) -1)  {
    16251630                ret = False;
    16261631                goto done;
    16271632        }
    16281633
    1629         pdb_set_logon_time(sampass, convert_uint32_to_time_t(logon_time), PDB_SET);
    1630         pdb_set_logoff_time(sampass, convert_uint32_to_time_t(logoff_time), PDB_SET);
    1631         pdb_set_kickoff_time(sampass, convert_uint32_to_time_t(kickoff_time), PDB_SET);
    1632         pdb_set_bad_password_time(sampass, convert_uint32_to_time_t(bad_password_time), PDB_SET);
    1633         pdb_set_pass_can_change_time(sampass, convert_uint32_to_time_t(pass_can_change_time), PDB_SET);
    1634         pdb_set_pass_must_change_time(sampass, convert_uint32_to_time_t(pass_must_change_time), PDB_SET);
    1635         pdb_set_pass_last_set_time(sampass, convert_uint32_to_time_t(pass_last_set_time), PDB_SET);
     1634        pdb_set_logon_time(sampass, convert_uint32_t_to_time_t(logon_time), PDB_SET);
     1635        pdb_set_logoff_time(sampass, convert_uint32_t_to_time_t(logoff_time), PDB_SET);
     1636        pdb_set_kickoff_time(sampass, convert_uint32_t_to_time_t(kickoff_time), PDB_SET);
     1637        pdb_set_bad_password_time(sampass, convert_uint32_t_to_time_t(bad_password_time), PDB_SET);
     1638        pdb_set_pass_can_change_time(sampass, convert_uint32_t_to_time_t(pass_can_change_time), PDB_SET);
     1639        pdb_set_pass_must_change_time(sampass, convert_uint32_t_to_time_t(pass_must_change_time), PDB_SET);
     1640        pdb_set_pass_last_set_time(sampass, convert_uint32_t_to_time_t(pass_last_set_time), PDB_SET);
    16361641
    16371642        pdb_set_username(sampass, username, PDB_SET);
     
    17101715        pdb_get_account_policy(PDB_POLICY_PASSWORD_HISTORY, &pwHistLen);
    17111716        if (pwHistLen) {
    1712                 uint8 *pw_hist = (uint8 *)SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN);
     1717                uint8_t *pw_hist = (uint8_t *)SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN);
    17131718                if (!pw_hist) {
    17141719                        ret = False;
     
    17411746        pdb_set_logon_count(sampass, logon_count, PDB_SET);
    17421747        pdb_set_unknown_6(sampass, unknown_6, PDB_SET);
    1743         /* Change from V2 is the uint32 acct_ctrl */
     1748        /* Change from V2 is the uint32_t acct_ctrl */
    17441749        pdb_set_acct_ctrl(sampass, acct_ctrl, PDB_SET);
    17451750        pdb_set_logon_divs(sampass, logon_divs, PDB_SET);
    1746         pdb_set_hours(sampass, hours, PDB_SET);
     1751        pdb_set_hours(sampass, hours, hours_len, PDB_SET);
    17471752
    17481753done:
     
    17711776*********************************************************************/
    17721777
    1773 static uint32 init_buffer_from_samu_v3 (uint8 **buf, struct samu *sampass, bool size_only)
     1778static uint32_t init_buffer_from_samu_v3 (uint8_t **buf, struct samu *sampass, bool size_only)
    17741779{
    17751780        size_t len, buflen;
     
    17781783           take care on system with 64bit wide time_t
    17791784           --SSS */
    1780         uint32  logon_time,
     1785        uint32_t        logon_time,
    17811786                logoff_time,
    17821787                kickoff_time,
     
    17861791                pass_must_change_time;
    17871792
    1788         uint32  user_rid, group_rid;
     1793        uint32_t  user_rid, group_rid;
    17891794
    17901795        const char *username;
     
    18001805        const char *acct_desc;
    18011806        const char *workstations;
    1802         uint32  username_len, domain_len, nt_username_len,
     1807        uint32_t        username_len, domain_len, nt_username_len,
    18031808                dir_drive_len, comment_len, munged_dial_len,
    18041809                fullname_len, homedir_len, logon_script_len,
    18051810                profile_path_len, acct_desc_len, workstations_len;
    18061811
    1807         const uint8 *lm_pw;
    1808         const uint8 *nt_pw;
    1809         const uint8 *nt_pw_hist;
    1810         uint32  lm_pw_len = 16;
    1811         uint32  nt_pw_len = 16;
    1812         uint32  nt_pw_hist_len;
    1813         uint32 pwHistLen = 0;
     1812        const uint8_t *lm_pw;
     1813        const uint8_t *nt_pw;
     1814        const uint8_t *nt_pw_hist;
     1815        uint32_t        lm_pw_len = 16;
     1816        uint32_t        nt_pw_len = 16;
     1817        uint32_t  nt_pw_hist_len;
     1818        uint32_t pwHistLen = 0;
    18141819
    18151820        *buf = NULL;
    18161821        buflen = 0;
    18171822
    1818         logon_time = convert_time_t_to_uint32(pdb_get_logon_time(sampass));
    1819         logoff_time = convert_time_t_to_uint32(pdb_get_logoff_time(sampass));
    1820         kickoff_time = convert_time_t_to_uint32(pdb_get_kickoff_time(sampass));
    1821         bad_password_time = convert_time_t_to_uint32(pdb_get_bad_password_time(sampass));
    1822         pass_can_change_time = convert_time_t_to_uint32(pdb_get_pass_can_change_time_noncalc(sampass));
    1823         pass_must_change_time = convert_time_t_to_uint32(pdb_get_pass_must_change_time(sampass));
    1824         pass_last_set_time = convert_time_t_to_uint32(pdb_get_pass_last_set_time(sampass));
     1823        logon_time = convert_time_t_to_uint32_t(pdb_get_logon_time(sampass));
     1824        logoff_time = convert_time_t_to_uint32_t(pdb_get_logoff_time(sampass));
     1825        kickoff_time = convert_time_t_to_uint32_t(pdb_get_kickoff_time(sampass));
     1826        bad_password_time = convert_time_t_to_uint32_t(pdb_get_bad_password_time(sampass));
     1827        pass_can_change_time = convert_time_t_to_uint32_t(pdb_get_pass_can_change_time_noncalc(sampass));
     1828        pass_must_change_time = convert_time_t_to_uint32_t(pdb_get_pass_must_change_time(sampass));
     1829        pass_last_set_time = convert_time_t_to_uint32_t(pdb_get_pass_last_set_time(sampass));
    18251830
    18261831        user_rid = pdb_get_user_rid(sampass);
     
    19901995
    19911996        /* malloc the space needed */
    1992         if ( (*buf=(uint8*)SMB_MALLOC(len)) == NULL) {
     1997        if ( (*buf=(uint8_t*)SMB_MALLOC(len)) == NULL) {
    19931998                DEBUG(0,("init_buffer_from_samu_v3: Unable to malloc() memory for buffer!\n"));
    19941999                return (-1);
     
    20412046}
    20422047
    2043 static bool init_samu_from_buffer_v4(struct samu *sampass, uint8 *buf, uint32 buflen)
     2048static bool init_samu_from_buffer_v4(struct samu *sampass, uint8_t *buf, uint32_t buflen)
    20442049{
    20452050        /* nothing changed between V3 and V4 */
     
    20472052}
    20482053
    2049 static uint32 init_buffer_from_samu_v4(uint8 **buf, struct samu *sampass, bool size_only)
     2054static uint32_t init_buffer_from_samu_v4(uint8_t **buf, struct samu *sampass, bool size_only)
    20502055{
    20512056        /* nothing changed between V3 and V4 */
     
    20582063
    20592064bool init_samu_from_buffer(struct samu *sampass, uint32_t level,
    2060                            uint8 *buf, uint32 buflen)
     2065                           uint8_t *buf, uint32_t buflen)
    20612066{
    20622067        switch (level) {
     
    20802085 *********************************************************************/
    20812086
    2082 uint32 init_buffer_from_samu (uint8 **buf, struct samu *sampass, bool size_only)
     2087uint32_t init_buffer_from_samu (uint8_t **buf, struct samu *sampass, bool size_only)
    20832088{
    20842089        return init_buffer_from_samu_v4(buf, sampass, size_only);
     
    20902095bool pdb_copy_sam_account(struct samu *dst, struct samu *src )
    20912096{
    2092         uint8 *buf = NULL;
     2097        uint8_t *buf = NULL;
    20932098        int len;
    20942099
     
    21292134{
    21302135        time_t LastBadPassword;
    2131         uint16 BadPasswordCount;
    2132         uint32 resettime;
     2136        uint16_t BadPasswordCount;
     2137        uint32_t resettime;
    21332138        bool res;
    21342139
     
    21492154
    21502155        /* First, check if there is a reset time to compare */
    2151         if ((resettime == (uint32) -1) || (resettime == 0)) {
     2156        if ((resettime == (uint32_t) -1) || (resettime == 0)) {
    21522157                DEBUG(9, ("No reset time, can't reset bad pw count\n"));
    21532158                return True;
     
    21562161        LastBadPassword = pdb_get_bad_password_time(sampass);
    21572162        DEBUG(7, ("LastBadPassword=%d, resettime=%d, current time=%d.\n",
    2158                    (uint32) LastBadPassword, resettime, (uint32)time(NULL)));
    2159         if (time(NULL) > (LastBadPassword + convert_uint32_to_time_t(resettime)*60)){
     2163                   (uint32_t) LastBadPassword, resettime, (uint32_t)time(NULL)));
     2164        if (time(NULL) > (LastBadPassword + convert_uint32_t_to_time_t(resettime)*60)){
    21602165                pdb_set_bad_password_count(sampass, 0, PDB_CHANGED);
    21612166                pdb_set_bad_password_time(sampass, 0, PDB_CHANGED);
     
    21742179bool pdb_update_autolock_flag(struct samu *sampass, bool *updated)
    21752180{
    2176         uint32 duration;
     2181        uint32_t duration;
    21772182        time_t LastBadPassword;
    21782183        bool res;
     
    21942199
    21952200        /* First, check if there is a duration to compare */
    2196         if ((duration == (uint32) -1)  || (duration == 0)) {
     2201        if ((duration == (uint32_t) -1)  || (duration == 0)) {
    21972202                DEBUG(9, ("pdb_update_autolock_flag: No reset duration, can't reset autolock\n"));
    21982203                return True;
     
    22012206        LastBadPassword = pdb_get_bad_password_time(sampass);
    22022207        DEBUG(7, ("pdb_update_autolock_flag: Account %s, LastBadPassword=%d, duration=%d, current time =%d.\n",
    2203                   pdb_get_username(sampass), (uint32)LastBadPassword, duration*60, (uint32)time(NULL)));
     2208                  pdb_get_username(sampass), (uint32_t)LastBadPassword, duration*60, (uint32_t)time(NULL)));
    22042209
    22052210        if (LastBadPassword == (time_t)0) {
     
    22112216        }
    22122217
    2213         if ((time(NULL) > (LastBadPassword + convert_uint32_to_time_t(duration) * 60))) {
     2218        if ((time(NULL) > (LastBadPassword + convert_uint32_t_to_time_t(duration) * 60))) {
    22142219                pdb_set_acct_ctrl(sampass,
    22152220                                  pdb_get_acct_ctrl(sampass) & ~ACB_AUTOLOCK,
     
    22312236bool pdb_increment_bad_password_count(struct samu *sampass)
    22322237{
    2233         uint32 account_policy_lockout;
     2238        uint32_t account_policy_lockout;
    22342239        bool autolock_updated = False, badpw_updated = False;
    22352240        bool ret;
     
    23672372*******************************************************************/
    23682373
    2369 bool get_trust_pw_hash(const char *domain, uint8 ret_pwd[16],
     2374bool get_trust_pw_hash(const char *domain, uint8_t ret_pwd[16],
    23702375                       const char **account_name,
    23712376                       enum netr_SchannelType *channel)
     
    23992404        return False;
    24002405}
    2401 
    2402 struct samr_LogonHours get_logon_hours_from_pdb(TALLOC_CTX *mem_ctx,
    2403                                                 struct samu *pw)
    2404 {
    2405         struct samr_LogonHours hours;
    2406         const int units_per_week = 168;
    2407 
    2408         ZERO_STRUCT(hours);
    2409         hours.bits = talloc_array(mem_ctx, uint8_t, units_per_week);
    2410         if (!hours.bits) {
    2411                 return hours;
    2412         }
    2413 
    2414         hours.units_per_week = units_per_week;
    2415         memset(hours.bits, 0xFF, units_per_week);
    2416 
    2417         if (pdb_get_hours(pw)) {
    2418                 memcpy(hours.bits, pdb_get_hours(pw),
    2419                        MIN(pdb_get_hours_len(pw), units_per_week));
    2420         }
    2421 
    2422         return hours;
    2423 }
  • trunk/server/source3/passdb/pdb_ads.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "passdb.h"
     22#include "tldap.h"
     23#include "tldap_util.h"
     24#include "../libds/common/flags.h"
     25#include "secrets.h"
     26#include "../librpc/gen_ndr/samr.h"
     27#include "../libcli/ldap/ldap_ndr.h"
     28#include "../libcli/security/security.h"
     29#include "../libds/common/flag_mapping.h"
    2130
    2231struct pdb_ads_state {
     
    3544};
    3645
    37 static NTSTATUS pdb_ads_getsampwsid(struct pdb_methods *m,
    38                                     struct samu *sam_acct,
    39                                     const DOM_SID *sid);
    4046static bool pdb_ads_gid_to_sid(struct pdb_methods *m, gid_t gid,
    41                                DOM_SID *sid);
     47                               struct dom_sid *sid);
    4248static bool pdb_ads_dnblob2sid(struct pdb_ads_state *state, DATA_BLOB *dnblob,
    4349                               struct dom_sid *psid);
     
    6470                return false;
    6571        }
    66         *ptime = uint64s_nt_time_to_unix_abs(&tmp);
     72        *ptime = nt_time_to_unix(tmp);
    6773        return true;
    6874}
     
    151157        }
    152158
    153         sidstr = sid_binstring(talloc_tos(), pdb_get_user_sid(sam));
     159        sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), pdb_get_user_sid(sam));
    154160        if (sidstr == NULL) {
    155161                return NULL;
     
    185191        struct dom_sid sid;
    186192        uint64_t n;
     193        uint32_t i;
    187194        DATA_BLOB blob;
    188195
     
    239246        if (str != NULL) {
    240247                pdb_set_profile_path(sam, str, PDB_SET);
     248        }
     249
     250        str = tldap_talloc_single_attribute(entry, "comment",
     251                                            talloc_tos());
     252        if (str != NULL) {
     253                pdb_set_comment(sam, str, PDB_SET);
     254        }
     255
     256        str = tldap_talloc_single_attribute(entry, "description",
     257                                            talloc_tos());
     258        if (str != NULL) {
     259                pdb_set_acct_desc(sam, str, PDB_SET);
     260        }
     261
     262        str = tldap_talloc_single_attribute(entry, "userWorkstations",
     263                                            talloc_tos());
     264        if (str != NULL) {
     265                pdb_set_workstations(sam, str, PDB_SET);
     266        }
     267
     268        str = tldap_talloc_single_attribute(entry, "userParameters",
     269                                            talloc_tos());
     270        if (str != NULL) {
     271                pdb_set_munged_dial(sam, str, PDB_SET);
    241272        }
    242273
     
    276307
    277308        }
     309
     310        if (tldap_pull_uint32(entry, "countryCode", &i)) {
     311                pdb_set_country_code(sam, i, PDB_SET);
     312        }
     313
     314        if (tldap_pull_uint32(entry, "codePage", &i)) {
     315                pdb_set_code_page(sam, i, PDB_SET);
     316        }
     317
     318        if (tldap_get_single_valueblob(entry, "logonHours", &blob)) {
     319
     320                if (blob.length > MAX_HOURS_LEN) {
     321                        status = NT_STATUS_INVALID_PARAMETER;
     322                        goto fail;
     323                }
     324                pdb_set_logon_divs(sam, blob.length * 8, PDB_SET);
     325                pdb_set_hours_len(sam, blob.length, PDB_SET);
     326                pdb_set_hours(sam, blob.data, blob.length, PDB_SET);
     327
     328        } else {
     329                uint8_t hours[21];
     330                pdb_set_logon_divs(sam, sizeof(hours)/8, PDB_SET);
     331                pdb_set_hours_len(sam, sizeof(hours), PDB_SET);
     332                memset(hours, 0xff, sizeof(hours));
     333                pdb_set_hours(sam, hours, sizeof(hours), PDB_SET);
     334        }
     335
    278336        status = NT_STATUS_OK;
    279337fail:
     
    282340}
    283341
     342static bool pdb_ads_make_time_mod(struct tldap_message *existing,
     343                                  TALLOC_CTX *mem_ctx,
     344                                  struct tldap_mod **pmods, int *pnum_mods,
     345                                  const char *attrib, time_t t)
     346{
     347        uint64_t nt_time;
     348
     349        unix_to_nt_time(&nt_time, t);
     350
     351        return tldap_make_mod_fmt(
     352                existing, mem_ctx, pmods, pnum_mods, attrib,
     353                "%llu", nt_time);
     354}
     355
    284356static bool pdb_ads_init_ads_from_sam(struct pdb_ads_state *state,
    285357                                      struct tldap_message *existing,
    286358                                      TALLOC_CTX *mem_ctx,
    287                                       int *pnum_mods, struct tldap_mod **pmods,
     359                                      struct tldap_mod **pmods, int *pnum_mods,
    288360                                      struct samu *sam)
    289361{
    290362        bool ret = true;
    291363        DATA_BLOB blob;
     364        const char *pw;
    292365
    293366        /* TODO: All fields :-) */
    294367
    295368        ret &= tldap_make_mod_fmt(
    296                 existing, mem_ctx, pnum_mods, pmods, "displayName",
     369                existing, mem_ctx, pmods, pnum_mods, "displayName",
    297370                "%s", pdb_get_fullname(sam));
    298371
    299         blob = data_blob_const(pdb_get_nt_passwd(sam), NT_HASH_LEN);
    300         if (blob.data != NULL) {
    301                 ret &= tldap_add_mod_blobs(mem_ctx, pmods, TLDAP_MOD_REPLACE,
    302                                            "unicodePwd", 1, &blob);
    303         }
    304 
    305         blob = data_blob_const(pdb_get_lanman_passwd(sam), NT_HASH_LEN);
    306         if (blob.data != NULL) {
    307                 ret &= tldap_add_mod_blobs(mem_ctx, pmods, TLDAP_MOD_REPLACE,
    308                                            "dBCSPwd", 1, &blob);
     372        pw = pdb_get_plaintext_passwd(sam);
     373
     374        /*
     375         * If we have the plain text pw, this is probably about to be
     376         * set. Is this true always?
     377         */
     378        if (pw != NULL) {
     379                char *pw_quote;
     380                uint8_t *pw_utf16;
     381                size_t pw_utf16_len;
     382
     383                pw_quote = talloc_asprintf(talloc_tos(), "\"%s\"", pw);
     384                if (pw_quote == NULL) {
     385                        ret = false;
     386                        goto fail;
     387                }
     388
     389                ret &= convert_string_talloc(talloc_tos(),
     390                                             CH_UNIX, CH_UTF16LE,
     391                                             pw_quote, strlen(pw_quote),
     392                                             &pw_utf16, &pw_utf16_len, false);
     393                if (!ret) {
     394                        goto fail;
     395                }
     396                blob = data_blob_const(pw_utf16, pw_utf16_len);
     397
     398                ret &= tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods,
     399                                           TLDAP_MOD_REPLACE,
     400                                           "unicodePwd", &blob, 1);
     401                TALLOC_FREE(pw_utf16);
     402                TALLOC_FREE(pw_quote);
    309403        }
    310404
    311405        ret &= tldap_make_mod_fmt(
    312                 existing, mem_ctx, pnum_mods, pmods, "userAccountControl",
     406                existing, mem_ctx, pmods, pnum_mods, "userAccountControl",
    313407                "%d", ds_acb2uf(pdb_get_acct_ctrl(sam)));
    314408
    315409        ret &= tldap_make_mod_fmt(
    316                 existing, mem_ctx, pnum_mods, pmods, "homeDirectory",
     410                existing, mem_ctx, pmods, pnum_mods, "homeDirectory",
    317411                "%s", pdb_get_homedir(sam));
    318412
    319413        ret &= tldap_make_mod_fmt(
    320                 existing, mem_ctx, pnum_mods, pmods, "homeDrive",
     414                existing, mem_ctx, pmods, pnum_mods, "homeDrive",
    321415                "%s", pdb_get_dir_drive(sam));
    322416
    323417        ret &= tldap_make_mod_fmt(
    324                 existing, mem_ctx, pnum_mods, pmods, "scriptPath",
     418                existing, mem_ctx, pmods, pnum_mods, "scriptPath",
    325419                "%s", pdb_get_logon_script(sam));
    326420
    327421        ret &= tldap_make_mod_fmt(
    328                 existing, mem_ctx, pnum_mods, pmods, "profilePath",
     422                existing, mem_ctx, pmods, pnum_mods, "profilePath",
    329423                "%s", pdb_get_profile_path(sam));
    330424
     425        ret &= tldap_make_mod_fmt(
     426                existing, mem_ctx, pmods, pnum_mods, "comment",
     427                "%s", pdb_get_comment(sam));
     428
     429        ret &= tldap_make_mod_fmt(
     430                existing, mem_ctx, pmods, pnum_mods, "description",
     431                "%s", pdb_get_acct_desc(sam));
     432
     433        ret &= tldap_make_mod_fmt(
     434                existing, mem_ctx, pmods, pnum_mods, "userWorkstations",
     435                "%s", pdb_get_workstations(sam));
     436
     437        ret &= tldap_make_mod_fmt(
     438                existing, mem_ctx, pmods, pnum_mods, "userParameters",
     439                "%s", pdb_get_munged_dial(sam));
     440
     441        ret &= tldap_make_mod_fmt(
     442                existing, mem_ctx, pmods, pnum_mods, "countryCode",
     443                "%i", (int)pdb_get_country_code(sam));
     444
     445        ret &= tldap_make_mod_fmt(
     446                existing, mem_ctx, pmods, pnum_mods, "codePage",
     447                "%i", (int)pdb_get_code_page(sam));
     448
     449        ret &= pdb_ads_make_time_mod(
     450                existing, mem_ctx, pmods, pnum_mods, "accountExpires",
     451                (int)pdb_get_kickoff_time(sam));
     452
     453        ret &= tldap_make_mod_blob(
     454                existing, mem_ctx, pmods, pnum_mods, "logonHours",
     455                data_blob_const(pdb_get_hours(sam), pdb_get_hours_len(sam)));
     456
     457fail:
    331458        return ret;
    332459}
     
    368495                DEBUG(10, ("Expected 1 user, got %d\n", count));
    369496                TALLOC_FREE(result);
    370                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
     497                return NT_STATUS_NO_SUCH_USER;
    371498        }
    372499
     
    427554static NTSTATUS pdb_ads_getsampwsid(struct pdb_methods *m,
    428555                                    struct samu *sam_acct,
    429                                     const DOM_SID *sid)
     556                                    const struct dom_sid *sid)
    430557{
    431558        struct pdb_ads_state *state = talloc_get_type_abort(
     
    433560        char *sidstr, *filter;
    434561
    435         sidstr = sid_binstring(talloc_tos(), sid);
     562        sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
    436563        NT_STATUS_HAVE_NO_MEMORY(sidstr);
    437564
     
    476603        ok = true;
    477604        ok &= tldap_make_mod_fmt(
    478                 NULL, talloc_tos(), &num_mods, &mods, "objectClass", "user");
     605                NULL, talloc_tos(), &mods, &num_mods, "objectClass", "user");
    479606        ok &= tldap_make_mod_fmt(
    480                 NULL, talloc_tos(), &num_mods, &mods, "samAccountName", "%s",
     607                NULL, talloc_tos(), &mods, &num_mods, "samAccountName", "%s",
    481608                name);
    482609        if (!ok) {
     
    485612
    486613
    487         rc = tldap_add(ld, dn, num_mods, mods, NULL, 0, NULL, 0);
     614        rc = tldap_add(ld, dn, mods, num_mods, NULL, 0, NULL, 0);
    488615        if (rc != TLDAP_SUCCESS) {
    489616                DEBUG(10, ("ldap_add failed %s\n",
     
    578705
    579706        if (!pdb_ads_init_ads_from_sam(state, priv->ldapmsg, talloc_tos(),
    580                                        &num_mods, &mods, sam)) {
     707                                       &mods, &num_mods, sam)) {
    581708                return NT_STATUS_NO_MEMORY;
    582709        }
     
    587714        }
    588715
    589         rc = tldap_modify(ld, priv->dn, num_mods, mods, NULL, 0,
     716        rc = tldap_modify(ld, priv->dn, mods, num_mods, NULL, 0,
    590717                          NULL, 0);
    591718        TALLOC_FREE(mods);
     
    620747
    621748static NTSTATUS pdb_ads_getgrfilter(struct pdb_methods *m, GROUP_MAP *map,
    622                                     const char *filter)
     749                                    const char *filter,
     750                                    TALLOC_CTX *mem_ctx,
     751                                    struct tldap_message **pmsg)
    623752{
    624753        struct pdb_ads_state *state = talloc_get_type_abort(
     
    640769        }
    641770        if (talloc_array_length(group) != 1) {
    642                 DEBUG(10, ("Expected 1 user, got %d\n",
     771                DEBUG(10, ("Expected 1 group, got %d\n",
    643772                           (int)talloc_array_length(group)));
    644773                return NT_STATUS_INTERNAL_DB_CORRUPTION;
     
    682811        }
    683812
     813        if (pmsg != NULL) {
     814                *pmsg = talloc_move(mem_ctx, &group[0]);
     815        }
    684816        TALLOC_FREE(group);
    685817        return NT_STATUS_OK;
     
    687819
    688820static NTSTATUS pdb_ads_getgrsid(struct pdb_methods *m, GROUP_MAP *map,
    689                                  DOM_SID sid)
     821                                 struct dom_sid sid)
    690822{
    691823        char *filter;
     
    699831        }
    700832
    701         status = pdb_ads_getgrfilter(m, map, filter);
     833        status = pdb_ads_getgrfilter(m, map, filter, NULL, NULL);
    702834        TALLOC_FREE(filter);
    703835        return status;
     
    725857        }
    726858
    727         status = pdb_ads_getgrfilter(m, map, filter);
     859        status = pdb_ads_getgrfilter(m, map, filter, NULL, NULL);
    728860        TALLOC_FREE(filter);
    729861        return status;
     
    760892
    761893        ok &= tldap_make_mod_fmt(
    762                 NULL, talloc_tos(), &num_mods, &mods, "samAccountName", "%s",
     894                NULL, talloc_tos(), &mods, &num_mods, "samAccountName", "%s",
    763895                name);
    764896        ok &= tldap_make_mod_fmt(
    765                 NULL, talloc_tos(), &num_mods, &mods, "objectClass", "group");
     897                NULL, talloc_tos(), &mods, &num_mods, "objectClass", "group");
    766898        ok &= tldap_make_mod_fmt(
    767                 NULL, talloc_tos(), &num_mods, &mods, "groupType",
     899                NULL, talloc_tos(), &mods, &num_mods, "groupType",
    768900                "%d", (int)GTYPE_SECURITY_GLOBAL_GROUP);
    769901
     
    773905        }
    774906
    775         rc = tldap_add(ld, dn, num_mods, mods, NULL, 0, NULL, 0);
     907        rc = tldap_add(ld, dn, mods, num_mods, NULL, 0, NULL, 0);
    776908        if (rc != TLDAP_SUCCESS) {
    777909                DEBUG(10, ("ldap_add failed %s\n",
     
    825957        sid_compose(&sid, &state->domainsid, rid);
    826958
    827         sidstr = sid_binstring(talloc_tos(), &sid);
     959        sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), &sid);
    828960        NT_STATUS_HAVE_NO_MEMORY(sidstr);
    829961
     
    8791011                                                   GROUP_MAP *map)
    8801012{
     1013        struct pdb_ads_state *state = talloc_get_type_abort(
     1014                m->private_data, struct pdb_ads_state);
     1015        struct tldap_context *ld;
     1016        struct tldap_mod *mods = NULL;
     1017        char *filter;
     1018        struct tldap_message *existing;
     1019        char *dn;
     1020        GROUP_MAP existing_map;
     1021        int rc, num_mods = 0;
     1022        bool ret;
     1023        NTSTATUS status;
     1024
     1025        ld = pdb_ads_ld(state);
     1026        if (ld == NULL) {
     1027                return NT_STATUS_LDAP(TLDAP_SERVER_DOWN);
     1028        }
     1029
     1030        filter = talloc_asprintf(talloc_tos(),
     1031                                 "(&(objectsid=%s)(objectclass=group))",
     1032                                 sid_string_talloc(talloc_tos(), &map->sid));
     1033        if (filter == NULL) {
     1034                return NT_STATUS_NO_MEMORY;
     1035        }
     1036        status = pdb_ads_getgrfilter(m, &existing_map, filter,
     1037                                     talloc_tos(), &existing);
     1038        TALLOC_FREE(filter);
     1039
     1040        if (!tldap_entry_dn(existing, &dn)) {
     1041                return NT_STATUS_LDAP(TLDAP_DECODING_ERROR);
     1042        }
     1043
     1044        ret = true;
     1045
     1046        ret &= tldap_make_mod_fmt(
     1047                existing, talloc_tos(), &mods, &num_mods, "description",
     1048                "%s", map->comment);
     1049        ret &= tldap_make_mod_fmt(
     1050                existing, talloc_tos(), &mods, &num_mods, "samaccountname",
     1051                "%s", map->nt_name);
     1052
     1053        if (!ret) {
     1054                return NT_STATUS_NO_MEMORY;
     1055        }
     1056
     1057        if (num_mods == 0) {
     1058                TALLOC_FREE(existing);
     1059                return NT_STATUS_OK;
     1060        }
     1061
     1062        rc = tldap_modify(ld, dn, mods, num_mods, NULL, 0, NULL, 0);
     1063        if (rc != TLDAP_SUCCESS) {
     1064                DEBUG(10, ("ldap_modify for %s failed: %s\n", dn,
     1065                           tldap_errstr(talloc_tos(), ld, rc)));
     1066                TALLOC_FREE(existing);
     1067                return NT_STATUS_LDAP(rc);
     1068        }
     1069        TALLOC_FREE(existing);
     1070        return NT_STATUS_OK;
     1071}
     1072
     1073static NTSTATUS pdb_ads_delete_group_mapping_entry(struct pdb_methods *m,
     1074                                                   struct dom_sid sid)
     1075{
    8811076        return NT_STATUS_NOT_IMPLEMENTED;
    8821077}
    8831078
    884 static NTSTATUS pdb_ads_delete_group_mapping_entry(struct pdb_methods *m,
    885                                                    DOM_SID sid)
    886 {
    887         return NT_STATUS_NOT_IMPLEMENTED;
    888 }
    889 
    8901079static NTSTATUS pdb_ads_enum_group_mapping(struct pdb_methods *m,
    891                                            const DOM_SID *sid,
     1080                                           const struct dom_sid *sid,
    8921081                                           enum lsa_SidType sid_name_use,
    8931082                                           GROUP_MAP **pp_rmap,
     
    9001089static NTSTATUS pdb_ads_enum_group_members(struct pdb_methods *m,
    9011090                                           TALLOC_CTX *mem_ctx,
    902                                            const DOM_SID *group,
     1091                                           const struct dom_sid *group,
    9031092                                           uint32 **pmembers,
    9041093                                           size_t *pnum_members)
     
    9131102        uint32_t *members;
    9141103
    915         sidstr = sid_binstring(talloc_tos(), group);
     1104        sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), group);
    9161105        NT_STATUS_HAVE_NO_MEMORY(sidstr);
    9171106
     
    9361125        }
    9371126
    938         if (!tldap_entry_values(msg[0], "member", &num_members, &blobs)) {
    939                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
     1127        if (!tldap_entry_values(msg[0], "member", &blobs, &num_members)) {
     1128                *pmembers = NULL;
     1129                *pnum_members = 0;
     1130                return NT_STATUS_OK;
    9401131        }
    9411132
     
    9621153                                               TALLOC_CTX *mem_ctx,
    9631154                                               struct samu *user,
    964                                                DOM_SID **pp_sids,
     1155                                               struct dom_sid **pp_sids,
    9651156                                               gid_t **pp_gids,
    966                                                size_t *p_num_groups)
     1157                                               uint32_t *p_num_groups)
    9671158{
    9681159        struct pdb_ads_state *state = talloc_get_type_abort(
    9691160                m->private_data, struct pdb_ads_state);
    970         struct pdb_ads_samu_private *priv = pdb_ads_get_samu_private(
    971                 m, user);
     1161        struct pdb_ads_samu_private *priv;
    9721162        const char *attrs[1] = { "objectSid" };
    9731163        struct tldap_message **groups;
     
    9771167        gid_t *gids;
    9781168
    979         rc = pdb_ads_search_fmt(
    980                 state, state->domaindn, TLDAP_SCOPE_SUB,
    981                 attrs, ARRAY_SIZE(attrs), 0, talloc_tos(), &groups,
    982                 "(&(member=%s)(grouptype=%d)(objectclass=group))",
    983                 priv->dn, GTYPE_SECURITY_GLOBAL_GROUP);
    984         if (rc != TLDAP_SUCCESS) {
    985                 DEBUG(10, ("ldap_search failed %s\n",
    986                            tldap_errstr(talloc_tos(), state->ld, rc)));
    987                 return NT_STATUS_LDAP(rc);
    988         }
    989 
    990         count = talloc_array_length(groups);
    991 
    992         group_sids = talloc_array(mem_ctx, struct dom_sid, count);
     1169        priv = pdb_ads_get_samu_private(m, user);
     1170        if (priv != NULL) {
     1171                rc = pdb_ads_search_fmt(
     1172                        state, state->domaindn, TLDAP_SCOPE_SUB,
     1173                        attrs, ARRAY_SIZE(attrs), 0, talloc_tos(), &groups,
     1174                        "(&(member=%s)(grouptype=%d)(objectclass=group))",
     1175                        priv->dn, GTYPE_SECURITY_GLOBAL_GROUP);
     1176                if (rc != TLDAP_SUCCESS) {
     1177                        DEBUG(10, ("ldap_search failed %s\n",
     1178                                   tldap_errstr(talloc_tos(), state->ld, rc)));
     1179                        return NT_STATUS_LDAP(rc);
     1180                }
     1181                count = talloc_array_length(groups);
     1182        } else {
     1183                /*
     1184                 * This happens for artificial samu users
     1185                 */
     1186                DEBUG(10, ("Could not get pdb_ads_samu_private\n"));
     1187                count = 0;
     1188        }
     1189
     1190        group_sids = talloc_array(mem_ctx, struct dom_sid, count+1);
    9931191        if (group_sids == NULL) {
    9941192                return NT_STATUS_NO_MEMORY;
    9951193        }
    996         gids = talloc_array(mem_ctx, gid_t, count);
     1194        gids = talloc_array(mem_ctx, gid_t, count+1);
    9971195        if (gids == NULL) {
    9981196                TALLOC_FREE(group_sids);
    9991197                return NT_STATUS_NO_MEMORY;
    10001198        }
    1001         num_groups = 0;
     1199
     1200        sid_copy(&group_sids[0], pdb_get_group_sid(user));
     1201        if (!sid_to_gid(&group_sids[0], &gids[0])) {
     1202                TALLOC_FREE(gids);
     1203                TALLOC_FREE(group_sids);
     1204                return NT_STATUS_INTERNAL_DB_CORRUPTION;
     1205        }
     1206        num_groups = 1;
    10021207
    10031208        for (i=0; i<count; i++) {
     
    10391244        char *groupdn, *memberdn;
    10401245        struct tldap_mod *mods;
     1246        int num_mods;
    10411247        int rc;
    10421248        NTSTATUS status;
     
    10621268
    10631269        mods = NULL;
    1064 
    1065         if (!tldap_add_mod_str(talloc_tos(), &mods, mod_op,
     1270        num_mods = 0;
     1271
     1272        if (!tldap_add_mod_str(talloc_tos(), &mods, &num_mods, mod_op,
    10661273                               "member", memberdn)) {
    10671274                TALLOC_FREE(frame);
     
    10691276        }
    10701277
    1071         rc = tldap_modify(ld, groupdn, 1, mods, NULL, 0, NULL, 0);
     1278        rc = tldap_modify(ld, groupdn, mods, num_mods, NULL, 0, NULL, 0);
    10721279        TALLOC_FREE(frame);
    10731280        if (rc != TLDAP_SUCCESS) {
    10741281                DEBUG(10, ("ldap_modify failed: %s\n",
    10751282                           tldap_errstr(talloc_tos(), state->ld, rc)));
    1076                 if (rc == TLDAP_TYPE_OR_VALUE_EXISTS) {
     1283                if ((mod_op == TLDAP_MOD_ADD) &&
     1284                    (rc == TLDAP_ALREADY_EXISTS)) {
    10771285                        return NT_STATUS_MEMBER_IN_GROUP;
    10781286                }
    1079                 if (rc == TLDAP_NO_SUCH_ATTRIBUTE) {
     1287                if ((mod_op == TLDAP_MOD_DELETE) &&
     1288                    (rc == TLDAP_UNWILLING_TO_PERFORM)) {
    10801289                        return NT_STATUS_MEMBER_NOT_IN_GROUP;
    10811290                }
     
    11311340
    11321341        ok &= tldap_make_mod_fmt(
    1133                 NULL, talloc_tos(), &num_mods, &mods, "samAccountName", "%s",
     1342                NULL, talloc_tos(), &mods, &num_mods, "samAccountName", "%s",
    11341343                name);
    11351344        ok &= tldap_make_mod_fmt(
    1136                 NULL, talloc_tos(), &num_mods, &mods, "objectClass", "group");
     1345                NULL, talloc_tos(), &mods, &num_mods, "objectClass", "group");
    11371346        ok &= tldap_make_mod_fmt(
    1138                 NULL, talloc_tos(), &num_mods, &mods, "groupType",
     1347                NULL, talloc_tos(), &mods, &num_mods, "groupType",
    11391348                "%d", (int)GTYPE_SECURITY_DOMAIN_LOCAL_GROUP);
    11401349
     
    11441353        }
    11451354
    1146         rc = tldap_add(ld, dn, num_mods, mods, NULL, 0, NULL, 0);
     1355        rc = tldap_add(ld, dn, mods, num_mods, NULL, 0, NULL, 0);
    11471356        if (rc != TLDAP_SUCCESS) {
    11481357                DEBUG(10, ("ldap_add failed %s\n",
     
    11831392
    11841393static NTSTATUS pdb_ads_delete_alias(struct pdb_methods *m,
    1185                                      const DOM_SID *sid)
     1394                                     const struct dom_sid *sid)
    11861395{
    11871396        struct pdb_ads_state *state = talloc_get_type_abort(
     
    11891398        struct tldap_context *ld;
    11901399        struct tldap_message **alias;
    1191         char *sidstr, *dn;
     1400        char *sidstr, *dn = NULL;
    11921401        int rc;
    11931402
     
    11971406        }
    11981407
    1199         sidstr = sid_binstring(talloc_tos(), sid);
     1408        sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
    12001409        if (sidstr == NULL) {
    12011410                return NT_STATUS_NO_MEMORY;
     
    12121421                DEBUG(10, ("ldap_search failed: %s\n",
    12131422                           tldap_errstr(talloc_tos(), state->ld, rc)));
    1214                 TALLOC_FREE(dn);
    12151423                return NT_STATUS_LDAP(rc);
    12161424        }
     
    12301438                DEBUG(10, ("ldap_delete failed: %s\n",
    12311439                           tldap_errstr(talloc_tos(), state->ld, rc)));
    1232                 TALLOC_FREE(dn);
    12331440                return NT_STATUS_LDAP(rc);
    12341441        }
     
    12381445
    12391446static NTSTATUS pdb_ads_set_aliasinfo(struct pdb_methods *m,
    1240                                       const DOM_SID *sid,
     1447                                      const struct dom_sid *sid,
    12411448                                      struct acct_info *info)
    12421449{
     
    12581465        }
    12591466
    1260         sidstr = sid_binstring(talloc_tos(), sid);
     1467        sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
    12611468        NT_STATUS_HAVE_NO_MEMORY(sidstr);
    12621469
     
    12921499
    12931500        ok &= tldap_make_mod_fmt(
    1294                 msg[0], msg, &num_mods, &mods, "description",
     1501                msg[0], msg, &mods, &num_mods, "description",
    12951502                "%s", info->acct_desc);
    12961503        ok &= tldap_make_mod_fmt(
    1297                 msg[0], msg, &num_mods, &mods, "samAccountName",
     1504                msg[0], msg, &mods, &num_mods, "samAccountName",
    12981505                "%s", info->acct_name);
    12991506        if (!ok) {
     
    13071514        }
    13081515
    1309         rc = tldap_modify(ld, dn, num_mods, mods, NULL, 0, NULL, 0);
     1516        rc = tldap_modify(ld, dn, mods, num_mods, NULL, 0, NULL, 0);
    13101517        TALLOC_FREE(msg);
    13111518        if (rc != TLDAP_SUCCESS) {
     
    13251532        int rc;
    13261533
    1327         sidstr = sid_binstring(talloc_tos(), sid);
     1534        sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), sid);
    13281535        NT_STATUS_HAVE_NO_MEMORY(sidstr);
    13291536
     
    13621569
    13631570static NTSTATUS pdb_ads_mod_aliasmem(struct pdb_methods *m,
    1364                                      const DOM_SID *alias,
    1365                                      const DOM_SID *member,
     1571                                     const struct dom_sid *alias,
     1572                                     const struct dom_sid *member,
    13661573                                     int mod_op)
    13671574{
     
    13711578        TALLOC_CTX *frame = talloc_stackframe();
    13721579        struct tldap_mod *mods;
     1580        int num_mods;
    13731581        int rc;
    13741582        char *aliasdn, *memberdn;
     
    13961604
    13971605        mods = NULL;
    1398 
    1399         if (!tldap_add_mod_str(talloc_tos(), &mods, mod_op,
     1606        num_mods = 0;
     1607
     1608        if (!tldap_add_mod_str(talloc_tos(), &mods, &num_mods, mod_op,
    14001609                               "member", memberdn)) {
    14011610                TALLOC_FREE(frame);
     
    14031612        }
    14041613
    1405         rc = tldap_modify(ld, aliasdn, 1, mods, NULL, 0, NULL, 0);
     1614        rc = tldap_modify(ld, aliasdn, mods, num_mods, NULL, 0, NULL, 0);
    14061615        TALLOC_FREE(frame);
    14071616        if (rc != TLDAP_SUCCESS) {
     
    14211630
    14221631static NTSTATUS pdb_ads_add_aliasmem(struct pdb_methods *m,
    1423                                      const DOM_SID *alias,
    1424                                      const DOM_SID *member)
     1632                                     const struct dom_sid *alias,
     1633                                     const struct dom_sid *member)
    14251634{
    14261635        return pdb_ads_mod_aliasmem(m, alias, member, TLDAP_MOD_ADD);
     
    14281637
    14291638static NTSTATUS pdb_ads_del_aliasmem(struct pdb_methods *m,
    1430                                      const DOM_SID *alias,
    1431                                      const DOM_SID *member)
     1639                                     const struct dom_sid *alias,
     1640                                     const struct dom_sid *member)
    14321641{
    14331642        return pdb_ads_mod_aliasmem(m, alias, member, TLDAP_MOD_DELETE);
     
    14661675
    14671676static NTSTATUS pdb_ads_enum_aliasmem(struct pdb_methods *m,
    1468                                       const DOM_SID *alias,
     1677                                      const struct dom_sid *alias,
    14691678                                      TALLOC_CTX *mem_ctx,
    1470                                       DOM_SID **pmembers,
     1679                                      struct dom_sid **pmembers,
    14711680                                      size_t *pnum_members)
    14721681{
     
    14801689        struct dom_sid *members;
    14811690
    1482         sidstr = sid_binstring(talloc_tos(), alias);
     1691        sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), alias);
    14831692        NT_STATUS_HAVE_NO_MEMORY(sidstr);
    14841693
     
    15031712        }
    15041713
    1505         if (!tldap_entry_values(msg[0], "member", &num_members, &blobs)) {
    1506                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
     1714        if (!tldap_entry_values(msg[0], "member", &blobs, &num_members)) {
     1715                *pmembers = NULL;
     1716                *pnum_members = 0;
     1717                return NT_STATUS_OK;
    15071718        }
    15081719
     
    15261737static NTSTATUS pdb_ads_enum_alias_memberships(struct pdb_methods *m,
    15271738                                               TALLOC_CTX *mem_ctx,
    1528                                                const DOM_SID *domain_sid,
    1529                                                const DOM_SID *members,
     1739                                               const struct dom_sid *domain_sid,
     1740                                               const struct dom_sid *members,
    15301741                                               size_t num_members,
    15311742                                               uint32_t **palias_rids,
     
    15351746                m->private_data, struct pdb_ads_state);
    15361747        const char *attrs[1] = { "objectSid" };
    1537         struct tldap_message **msg;
     1748        struct tldap_message **msg = NULL;
    15381749        uint32_t *alias_rids = NULL;
    15391750        size_t num_alias_rids = 0;
     
    16211832
    16221833static NTSTATUS pdb_ads_lookup_rids(struct pdb_methods *m,
    1623                                     const DOM_SID *domain_sid,
     1834                                    const struct dom_sid *domain_sid,
    16241835                                    int num_rids,
    16251836                                    uint32 *rids,
     
    16491860                sid_compose(&sid, domain_sid, rids[i]);
    16501861
    1651                 sidstr = sid_binstring(talloc_tos(), &sid);
     1862                sidstr = ldap_encode_ndr_dom_sid(talloc_tos(), &sid);
    16521863                NT_STATUS_HAVE_NO_MEMORY(sidstr);
    16531864
     
    16971908
    16981909static NTSTATUS pdb_ads_lookup_names(struct pdb_methods *m,
    1699                                      const DOM_SID *domain_sid,
     1910                                     const struct dom_sid *domain_sid,
    17001911                                     int num_names,
    17011912                                     const char **pp_names,
     
    17771988                                  struct pdb_search *search,
    17781989                                  const char *filter,
     1990                                  uint32_t acct_flags,
    17791991                                  struct pdb_ads_search_state **pstate)
    17801992{
     
    17912003                return false;
    17922004        }
     2005        sstate->acct_flags = acct_flags;
    17932006
    17942007        rc = pdb_ads_search_fmt(
     
    18162029                struct samr_displayentry *e;
    18172030                struct dom_sid sid;
     2031                uint32_t ctrl;
    18182032
    18192033                e = &sstate->entries[sstate->num_entries];
     
    18252039                }
    18262040                sid_peek_rid(&sid, &e->rid);
    1827                 e->acct_flags = ACB_NORMAL;
    1828                 e->account_name = tldap_talloc_single_attribute(
    1829                         users[i], "samAccountName", sstate->entries);
     2041
     2042                if (tldap_pull_uint32(users[i], "userAccountControl", &ctrl)) {
     2043
     2044                        e->acct_flags = ds_uf2acb(ctrl);
     2045
     2046                        DEBUG(10, ("pdb_ads_search_filter: Found %x, "
     2047                                   "filter %x\n", (int)e->acct_flags,
     2048                                   (int)sstate->acct_flags));
     2049
     2050
     2051                        if ((sstate->acct_flags != 0) &&
     2052                            ((sstate->acct_flags & e->acct_flags) == 0)) {
     2053                                continue;
     2054                        }
     2055
     2056                        if (e->acct_flags & (ACB_WSTRUST|ACB_SVRTRUST)) {
     2057                                e->acct_flags |= ACB_NORMAL;
     2058                        }
     2059                } else {
     2060                        e->acct_flags = ACB_NORMAL;
     2061                }
     2062
     2063                if (e->rid == DOMAIN_RID_GUEST) {
     2064                        /*
     2065                         * Guest is specially crafted in s3. Make
     2066                         * QueryDisplayInfo match QueryUserInfo
     2067                         */
     2068                        e->account_name = lp_guestaccount();
     2069                        e->fullname = lp_guestaccount();
     2070                        e->description = "";
     2071                        e->acct_flags = ACB_NORMAL;
     2072                } else {
     2073                        e->account_name = tldap_talloc_single_attribute(
     2074                                users[i], "samAccountName", sstate->entries);
     2075                        e->fullname = tldap_talloc_single_attribute(
     2076                                users[i], "displayName", sstate->entries);
     2077                        e->description = tldap_talloc_single_attribute(
     2078                                users[i], "description", sstate->entries);
     2079                }
    18302080                if (e->account_name == NULL) {
    18312081                        return false;
    18322082                }
    1833                 e->fullname = tldap_talloc_single_attribute(
    1834                         users[i], "displayName", sstate->entries);
    18352083                if (e->fullname == NULL) {
    18362084                        e->fullname = "";
    18372085                }
    1838                 e->description = tldap_talloc_single_attribute(
    1839                         users[i], "description", sstate->entries);
    18402086                if (e->description == NULL) {
    18412087                        e->description = "";
     
    18602106{
    18612107        struct pdb_ads_search_state *sstate;
     2108        char *filter;
    18622109        bool ret;
    18632110
    1864         ret = pdb_ads_search_filter(m, search, "(objectclass=user)", &sstate);
     2111        DEBUG(10, ("pdb_ads_search_users got flags %x\n", acct_flags));
     2112
     2113        if (acct_flags & ACB_NORMAL) {
     2114                filter = talloc_asprintf(
     2115                        talloc_tos(),
     2116                        "(&(objectclass=user)(sAMAccountType=%d))",
     2117                        ATYPE_NORMAL_ACCOUNT);
     2118        } else if (acct_flags & ACB_WSTRUST) {
     2119                filter = talloc_asprintf(
     2120                        talloc_tos(),
     2121                        "(&(objectclass=user)(sAMAccountType=%d))",
     2122                        ATYPE_WORKSTATION_TRUST);
     2123        } else {
     2124                filter = talloc_strdup(talloc_tos(), "(objectclass=user)");
     2125        }
     2126        if (filter == NULL) {
     2127                return false;
     2128        }
     2129
     2130        ret = pdb_ads_search_filter(m, search, filter, acct_flags, &sstate);
     2131        TALLOC_FREE(filter);
    18652132        if (!ret) {
    18662133                return false;
    18672134        }
    1868         sstate->acct_flags = acct_flags;
    18692135        return true;
    18702136}
     
    18832149                return false;
    18842150        }
    1885         ret = pdb_ads_search_filter(m, search, filter, &sstate);
     2151        ret = pdb_ads_search_filter(m, search, filter, 0, &sstate);
    18862152        TALLOC_FREE(filter);
    18872153        if (!ret) {
    18882154                return false;
    18892155        }
    1890         sstate->acct_flags = 0;
    18912156        return true;
    18922157}
     
    18942159static bool pdb_ads_search_aliases(struct pdb_methods *m,
    18952160                                   struct pdb_search *search,
    1896                                    const DOM_SID *sid)
     2161                                   const struct dom_sid *sid)
    18972162{
    18982163        struct pdb_ads_search_state *sstate;
     
    19092174                return false;
    19102175        }
    1911         ret = pdb_ads_search_filter(m, search, filter, &sstate);
     2176        ret = pdb_ads_search_filter(m, search, filter, 0, &sstate);
    19122177        TALLOC_FREE(filter);
    19132178        if (!ret) {
    19142179                return false;
    19152180        }
    1916         sstate->acct_flags = 0;
    19172181        return true;
    19182182}
    19192183
    19202184static bool pdb_ads_uid_to_sid(struct pdb_methods *m, uid_t uid,
    1921                                DOM_SID *sid)
     2185                               struct dom_sid *sid)
    19222186{
    19232187        struct pdb_ads_state *state = talloc_get_type_abort(
     
    19282192
    19292193static bool pdb_ads_gid_to_sid(struct pdb_methods *m, gid_t gid,
    1930                                DOM_SID *sid)
     2194                               struct dom_sid *sid)
    19312195{
    19322196        struct pdb_ads_state *state = talloc_get_type_abort(
     
    19362200}
    19372201
    1938 static bool pdb_ads_sid_to_id(struct pdb_methods *m, const DOM_SID *sid,
     2202static bool pdb_ads_sid_to_id(struct pdb_methods *m, const struct dom_sid *sid,
    19392203                              union unid_t *id, enum lsa_SidType *type)
    19402204{
    19412205        struct pdb_ads_state *state = talloc_get_type_abort(
    19422206                m->private_data, struct pdb_ads_state);
     2207        const char *attrs[4] = { "objectClass", "samAccountType",
     2208                                 "uidNumber", "gidNumber" };
    19432209        struct tldap_message **msg;
    1944         char *sidstr;
    1945         uint32_t rid;
     2210        char *sidstr, *base;
     2211        uint32_t atype;
    19462212        int rc;
    1947 
    1948         /*
    1949          * This is a big, big hack: Just hard-code the rid as uid/gid.
    1950          */
    1951 
    1952         sid_peek_rid(sid, &rid);
    1953 
    1954         sidstr = sid_binstring(talloc_tos(), sid);
     2213        bool ret = false;
     2214
     2215        sidstr = sid_binstring_hex(sid);
    19552216        if (sidstr == NULL) {
    19562217                return false;
    19572218        }
     2219        base = talloc_asprintf(talloc_tos(), "<SID=%s>", sidstr);
     2220        SAFE_FREE(sidstr);
    19582221
    19592222        rc = pdb_ads_search_fmt(
    1960                 state, state->domaindn, TLDAP_SCOPE_SUB,
    1961                 NULL, 0, 0, talloc_tos(), &msg,
    1962                 "(&(objectsid=%s)(objectclass=user))", sidstr);
    1963         if ((rc == TLDAP_SUCCESS) && (talloc_array_length(msg) > 0)) {
    1964                 id->uid = rid;
     2223                state, base, TLDAP_SCOPE_BASE,
     2224                attrs, ARRAY_SIZE(attrs), 0, talloc_tos(), &msg,
     2225                "(objectclass=*)");
     2226        TALLOC_FREE(base);
     2227
     2228        if (rc != TLDAP_SUCCESS) {
     2229                DEBUG(10, ("pdb_ads_search_fmt failed: %s\n",
     2230                           tldap_errstr(talloc_tos(), state->ld, rc)));
     2231                return false;
     2232        }
     2233        if (talloc_array_length(msg) != 1) {
     2234                DEBUG(10, ("Got %d objects, expected 1\n",
     2235                           (int)talloc_array_length(msg)));
     2236                goto fail;
     2237        }
     2238        if (!tldap_pull_uint32(msg[0], "samAccountType", &atype)) {
     2239                DEBUG(10, ("samAccountType not found\n"));
     2240                goto fail;
     2241        }
     2242        if (atype == ATYPE_ACCOUNT) {
     2243                uint32_t uid;
    19652244                *type = SID_NAME_USER;
    1966                 TALLOC_FREE(sidstr);
    1967                 return true;
    1968         }
    1969 
    1970         rc = pdb_ads_search_fmt(
    1971                 state, state->domaindn, TLDAP_SCOPE_SUB,
    1972                 NULL, 0, 0, talloc_tos(), &msg,
    1973                 "(&(objectsid=%s)(objectclass=group))", sidstr);
    1974         if ((rc == TLDAP_SUCCESS) && (talloc_array_length(msg) > 0)) {
    1975                 id->gid = rid;
     2245                if (!tldap_pull_uint32(msg[0], "uidNumber", &uid)) {
     2246                        DEBUG(10, ("Did not find uidNumber\n"));
     2247                        goto fail;
     2248                }
     2249                id->uid = uid;
     2250        } else {
     2251                uint32_t gid;
    19762252                *type = SID_NAME_DOM_GRP;
    1977                 TALLOC_FREE(sidstr);
    1978                 return true;
    1979         }
    1980 
    1981         TALLOC_FREE(sidstr);
    1982         return false;
     2253                if (!tldap_pull_uint32(msg[0], "gidNumber", &gid)) {
     2254                        DEBUG(10, ("Did not find gidNumber\n"));
     2255                        goto fail;
     2256                }
     2257                id->gid = gid;
     2258        }
     2259        ret = true;
     2260fail:
     2261        TALLOC_FREE(msg);
     2262        return ret;
    19832263}
    19842264
     
    19952275static bool pdb_ads_get_trusteddom_pw(struct pdb_methods *m,
    19962276                                      const char *domain, char** pwd,
    1997                                       DOM_SID *sid,
     2277                                      struct dom_sid *sid,
    19982278                                      time_t *pass_last_set_time)
    19992279{
     
    20032283static bool pdb_ads_set_trusteddom_pw(struct pdb_methods *m,
    20042284                                      const char* domain, const char* pwd,
    2005                                       const DOM_SID *sid)
     2285                                      const struct dom_sid *sid)
    20062286{
    20072287        return false;
     
    22022482        ZERO_STRUCT(state->socket_address);
    22032483        state->socket_address.sun_family = AF_UNIX;
    2204         strncpy(state->socket_address.sun_path, location,
    2205                 sizeof(state->socket_address.sun_path) - 1);
     2484        strlcpy(state->socket_address.sun_path, location,
     2485                sizeof(state->socket_address.sun_path));
    22062486
    22072487        ld = pdb_ads_ld(state);
     
    22312511        state->configdn = tldap_talloc_single_attribute(
    22322512                rootdse, "configurationNamingContext", state);
    2233         if (state->domaindn == NULL) {
     2513        if (state->configdn == NULL) {
    22342514                DEBUG(10, ("Could not get configurationNamingContext\n"));
    22352515                status = NT_STATUS_INTERNAL_DB_CORRUPTION;
     
    23202600        NTSTATUS status;
    23212601
    2322         m = talloc(talloc_autofree_context(), struct pdb_methods);
     2602        m = talloc(NULL, struct pdb_methods);
    23232603        if (m == NULL) {
    23242604                return NT_STATUS_NO_MEMORY;
  • trunk/server/source3/passdb/pdb_compat.c

    r414 r745  
    77   Copyright (C) Andrew Bartlett                2001-2002
    88   Copyright (C) Stefan (metze) Metzmacher      2002
    9      
     9
    1010   This program is free software; you can redistribute it and/or modify
    1111   it under the terms of the GNU General Public License as published by
    1212   the Free Software Foundation; either version 3 of the License, or
    1313   (at your option) any later version.
    14    
     14
    1515   This program is distributed in the hope that it will be useful,
    1616   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1717   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1818   GNU General Public License for more details.
    19    
     19
    2020   You should have received a copy of the GNU General Public License
    2121   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2323
    2424#include "includes.h"
     25#include "passdb.h"
     26#include "../libcli/security/security.h"
    2527
    2628#undef DBGC_CLASS
     
    3436                if (sid_peek_check_rid(get_global_sam_sid(), pdb_get_user_sid(sampass),&u_rid))
    3537                        return u_rid;
    36        
     38
    3739        return (0);
    3840}
     
    5052bool pdb_set_user_sid_from_rid (struct samu *sampass, uint32 rid, enum pdb_value_state flag)
    5153{
    52         DOM_SID u_sid;
    53         const DOM_SID *global_sam_sid;
    54        
     54        struct dom_sid u_sid;
     55        const struct dom_sid *global_sam_sid;
     56
    5557        if (!sampass)
    5658                return False;
     
    6163        }
    6264
    63         sid_copy(&u_sid, global_sam_sid);
    64 
    65         if (!sid_append_rid(&u_sid, rid))
     65        if (!sid_compose(&u_sid, global_sam_sid, rid)) {
    6666                return False;
     67        }
    6768
    6869        if (!pdb_set_user_sid(sampass, &u_sid, flag))
     
    7778bool pdb_set_group_sid_from_rid (struct samu *sampass, uint32 grid, enum pdb_value_state flag)
    7879{
    79         DOM_SID g_sid;
    80         const DOM_SID *global_sam_sid;
     80        struct dom_sid g_sid;
     81        const struct dom_sid *global_sam_sid;
    8182
    8283        if (!sampass)
    8384                return False;
    84        
     85
    8586        if (!(global_sam_sid = get_global_sam_sid())) {
    8687                DEBUG(1, ("pdb_set_user_sid_from_rid: Could not read global sam sid!\n"));
     
    8889        }
    8990
    90         sid_copy(&g_sid, global_sam_sid);
    91        
    92         if (!sid_append_rid(&g_sid, grid))
     91        if (!sid_compose(&g_sid, global_sam_sid, grid)) {
    9392                return False;
     93        }
    9494
    9595        if (!pdb_set_group_sid(sampass, &g_sid, flag))
  • trunk/server/source3/passdb/pdb_get_set.c

    r414 r745  
    2323
    2424#include "includes.h"
     25#include "passdb.h"
    2526#include "../libcli/auth/libcli_auth.h"
     27#include "../libcli/security/security.h"
    2628
    2729#undef DBGC_CLASS
     
    4143 ********************************************************************/
    4244
    43 uint32 pdb_get_acct_ctrl(const struct samu *sampass)
     45uint32_t pdb_get_acct_ctrl(const struct samu *sampass)
    4446{
    4547        return sampass->acct_ctrl;
     
    7375time_t pdb_get_pass_can_change_time(const struct samu *sampass)
    7476{
    75         uint32 allow;
     77        uint32_t allow;
    7678
    7779        /* if the last set time is zero, it means the user cannot
     
    8688        */
    8789        if (sampass->pass_can_change_time == get_time_t_max() &&
    88             pdb_get_init_flags(sampass, PDB_CANCHANGETIME) == PDB_CHANGED)
     90            IS_SAM_CHANGED(sampass, PDB_CANCHANGETIME))
    8991                return sampass->pass_can_change_time;
    9092
     
    105107time_t pdb_get_pass_must_change_time(const struct samu *sampass)
    106108{
    107         uint32 expire;
     109        uint32_t expire;
    108110
    109111        if (sampass->pass_last_set_time == 0)
     
    114116
    115117        if (!pdb_get_account_policy(PDB_POLICY_MAX_PASSWORD_AGE, &expire)
    116             || expire == (uint32)-1 || expire == 0)
     118            || expire == (uint32_t)-1 || expire == 0)
    117119                return get_time_t_max();
    118120
     
    122124bool pdb_get_pass_can_change(const struct samu *sampass)
    123125{
    124         if (sampass->pass_can_change_time == get_time_t_max() &&
    125             sampass->pass_last_set_time != 0)
     126        if (sampass->pass_can_change_time == get_time_t_max())
    126127                return False;
    127128        return True;
    128129}
    129130
    130 uint16 pdb_get_logon_divs(const struct samu *sampass)
     131uint16_t pdb_get_logon_divs(const struct samu *sampass)
    131132{
    132133        return sampass->logon_divs;
    133134}
    134135
    135 uint32 pdb_get_hours_len(const struct samu *sampass)
     136uint32_t pdb_get_hours_len(const struct samu *sampass)
    136137{
    137138        return sampass->hours_len;
     
    157158}
    158159
    159 const uint8 *pdb_get_pw_history(const struct samu *sampass, uint32 *current_hist_len)
     160const uint8 *pdb_get_pw_history(const struct samu *sampass, uint32_t *current_hist_len)
    160161{
    161162        SMB_ASSERT((!sampass->nt_pw_his.data)
     
    176177}
    177178
    178 const DOM_SID *pdb_get_user_sid(const struct samu *sampass)
     179const struct dom_sid *pdb_get_user_sid(const struct samu *sampass)
    179180{
    180181        return &sampass->user_sid;
    181182}
    182183
    183 const DOM_SID *pdb_get_group_sid(struct samu *sampass)
    184 {
    185         DOM_SID *gsid;
    186         struct passwd *pwd;
    187         bool need_lookup_sid = false;
     184const struct dom_sid *pdb_get_group_sid(struct samu *sampass)
     185{
     186        NTSTATUS status;
    188187
    189188        /* Return the cached group SID if we have that */
    190         if ( sampass->group_sid ) {
     189        if (sampass->group_sid) {
    191190                return sampass->group_sid;
    192         }
    193 
    194         /* generate the group SID from the user's primary Unix group */
    195 
    196         if ( !(gsid  = TALLOC_ZERO_P( sampass, DOM_SID )) ) {
    197                 return NULL;
    198191        }
    199192
     
    202195           be a newly allocated one.  We rely on the user's Unix primary gid.
    203196           We have no choice but to fail if we can't find it. */
    204 
    205         if ( sampass->unix_pw ) {
    206                 pwd = sampass->unix_pw;
    207         } else {
    208                 pwd = Get_Pwnam_alloc( sampass, pdb_get_username(sampass) );
    209         }
    210 
    211         if ( !pwd ) {
    212                 DEBUG(0,("pdb_get_group_sid: Failed to find Unix account for %s\n", pdb_get_username(sampass) ));
     197        status = get_primary_group_sid(sampass,
     198                                        pdb_get_username(sampass),
     199                                        &sampass->unix_pw,
     200                                        &sampass->group_sid);
     201        if (!NT_STATUS_IS_OK(status)) {
    213202                return NULL;
    214203        }
    215204
    216         gid_to_sid(gsid, pwd->pw_gid);
    217         if (!is_null_sid(gsid)) {
    218                 DOM_SID dgsid;
    219                 uint32_t rid;
    220 
    221                 sid_copy(&dgsid, gsid);
    222                 sid_split_rid(&dgsid, &rid);
    223                 if (sid_equal(&dgsid, get_global_sam_sid())) {
    224                         /*
    225                          * As shortcut for the expensive lookup_sid call
    226                          * compare the domain sid part
    227                          */
    228                         switch (rid) {
    229                         case DOMAIN_RID_ADMINS:
    230                         case DOMAIN_RID_USERS:
    231                                 sampass->group_sid = gsid;
    232                                 return sampass->group_sid;
    233                         default:
    234                                 need_lookup_sid = true;
    235                                 break;
    236                         }
    237                 } else {
    238                         ZERO_STRUCTP(gsid);
    239                         if (pdb_gid_to_sid(pwd->pw_gid, gsid)) {
    240                                 need_lookup_sid = true;
    241                         }
    242                 }
    243         }
    244 
    245         if (need_lookup_sid) {
    246                 enum lsa_SidType type = SID_NAME_UNKNOWN;
    247                 TALLOC_CTX *mem_ctx;
    248                 bool lookup_ret;
    249                 const DOM_SID *usid = pdb_get_user_sid(sampass);
    250 
    251                 mem_ctx = talloc_init("pdb_get_group_sid");
    252                 if (!mem_ctx) {
    253                         return NULL;
    254                 }
    255 
    256                 DEBUG(10,("do lookup_sid(%s) for group of user %s\n",
    257                           sid_string_dbg(gsid), sid_string_dbg(usid)));
    258 
    259                 /* Now check that it's actually a domain group and not something else */
    260 
    261                 lookup_ret = lookup_sid(mem_ctx, gsid, NULL, NULL, &type);
    262 
    263                 TALLOC_FREE( mem_ctx );
    264 
    265                 if ( lookup_ret && (type == SID_NAME_DOM_GRP) ) {
    266                         sampass->group_sid = gsid;
    267                         return sampass->group_sid;
    268                 }
    269 
    270                 DEBUG(3, ("Primary group %s for user %s is a %s and not a domain group\n",
    271                         sid_string_dbg(gsid), pwd->pw_name, sid_type_lookup(type)));
    272         }
    273 
    274         /* Just set it to the 'Domain Users' RID of 512 which will
    275            always resolve to a name */
    276 
    277         sid_copy( gsid, get_global_sam_sid() );
    278         sid_append_rid( gsid, DOMAIN_GROUP_RID_USERS );
    279 
    280         sampass->group_sid = gsid;
    281 
    282205        return sampass->group_sid;
    283 }       
     206}
    284207
    285208/**
     
    373296}
    374297
    375 uint16 pdb_get_bad_password_count(const struct samu *sampass)
     298uint16_t pdb_get_bad_password_count(const struct samu *sampass)
    376299{
    377300        return sampass->bad_password_count;
    378301}
    379302
    380 uint16 pdb_get_logon_count(const struct samu *sampass)
     303uint16_t pdb_get_logon_count(const struct samu *sampass)
    381304{
    382305        return sampass->logon_count;
    383306}
    384307
    385 uint32 pdb_get_unknown_6(const struct samu *sampass)
     308uint16_t pdb_get_country_code(const struct samu *sampass)
     309{
     310        return sampass->country_code;
     311}
     312
     313uint16_t pdb_get_code_page(const struct samu *sampass)
     314{
     315        return sampass->code_page;
     316}
     317
     318uint32_t pdb_get_unknown_6(const struct samu *sampass)
    386319{
    387320        return sampass->unknown_6;
     
    401334 ********************************************************************/
    402335
    403 bool pdb_set_acct_ctrl(struct samu *sampass, uint32 acct_ctrl, enum pdb_value_state flag)
     336bool pdb_set_acct_ctrl(struct samu *sampass, uint32_t acct_ctrl, enum pdb_value_state flag)
    404337{
    405338        sampass->acct_ctrl = acct_ctrl;
     
    449382}
    450383
    451 bool pdb_set_hours_len(struct samu *sampass, uint32 len, enum pdb_value_state flag)
     384bool pdb_set_hours_len(struct samu *sampass, uint32_t len, enum pdb_value_state flag)
    452385{
    453386        sampass->hours_len = len;
     
    455388}
    456389
    457 bool pdb_set_logon_divs(struct samu *sampass, uint16 hours, enum pdb_value_state flag)
     390bool pdb_set_logon_divs(struct samu *sampass, uint16_t hours, enum pdb_value_state flag)
    458391{
    459392        sampass->logon_divs = hours;
     
    527460}
    528461
    529 bool pdb_set_user_sid(struct samu *sampass, const DOM_SID *u_sid, enum pdb_value_state flag)
     462bool pdb_set_user_sid(struct samu *sampass, const struct dom_sid *u_sid, enum pdb_value_state flag)
    530463{
    531464        if (!u_sid)
     
    542475bool pdb_set_user_sid_from_string(struct samu *sampass, fstring u_sid, enum pdb_value_state flag)
    543476{
    544         DOM_SID new_sid;
     477        struct dom_sid new_sid;
    545478
    546479        if (!u_sid)
     
    571504********************************************************************/
    572505
    573 bool pdb_set_group_sid(struct samu *sampass, const DOM_SID *g_sid, enum pdb_value_state flag)
     506bool pdb_set_group_sid(struct samu *sampass, const struct dom_sid *g_sid, enum pdb_value_state flag)
    574507{
    575508        gid_t gid;
     509        struct dom_sid dug_sid;
    576510
    577511        if (!g_sid)
    578512                return False;
    579513
    580         if ( !(sampass->group_sid = TALLOC_P( sampass, DOM_SID )) ) {
     514        if ( !(sampass->group_sid = TALLOC_P( sampass, struct dom_sid )) ) {
    581515                return False;
    582516        }
     
    585519           store DOMAIN_USERS as the primary groupSID */
    586520
    587         if ( sid_to_gid( g_sid, &gid ) ) {
     521        sid_compose(&dug_sid, get_global_sam_sid(), DOMAIN_RID_USERS);
     522
     523        if (dom_sid_equal(&dug_sid, g_sid)) {
     524                sid_copy(sampass->group_sid, &dug_sid);
     525        } else if (sid_to_gid( g_sid, &gid ) ) {
    588526                sid_copy(sampass->group_sid, g_sid);
    589527        } else {
    590                 sid_copy( sampass->group_sid, get_global_sam_sid() );
    591                 sid_append_rid( sampass->group_sid, DOMAIN_GROUP_RID_USERS );
     528                sid_copy(sampass->group_sid, &dug_sid);
    592529        }
    593530
     
    909846********************************************************************/
    910847
    911 bool pdb_set_pw_history(struct samu *sampass, const uint8 *pwd, uint32 historyLen, enum pdb_value_state flag)
     848bool pdb_set_pw_history(struct samu *sampass, const uint8 *pwd, uint32_t historyLen, enum pdb_value_state flag)
    912849{
    913850        if (historyLen && pwd){
     851                data_blob_free(&(sampass->nt_pw_his));
    914852                sampass->nt_pw_his = data_blob_talloc(sampass,
    915853                                                pwd, historyLen*PW_HISTORY_ENTRY_LEN);
     
    949887}
    950888
    951 bool pdb_set_bad_password_count(struct samu *sampass, uint16 bad_password_count, enum pdb_value_state flag)
     889bool pdb_set_bad_password_count(struct samu *sampass, uint16_t bad_password_count, enum pdb_value_state flag)
    952890{
    953891        sampass->bad_password_count = bad_password_count;
     
    955893}
    956894
    957 bool pdb_set_logon_count(struct samu *sampass, uint16 logon_count, enum pdb_value_state flag)
     895bool pdb_set_logon_count(struct samu *sampass, uint16_t logon_count, enum pdb_value_state flag)
    958896{
    959897        sampass->logon_count = logon_count;
     
    961899}
    962900
    963 bool pdb_set_unknown_6(struct samu *sampass, uint32 unkn, enum pdb_value_state flag)
     901bool pdb_set_country_code(struct samu *sampass, uint16_t country_code,
     902                          enum pdb_value_state flag)
     903{
     904        sampass->country_code = country_code;
     905        return pdb_set_init_flags(sampass, PDB_COUNTRY_CODE, flag);
     906}
     907
     908bool pdb_set_code_page(struct samu *sampass, uint16_t code_page,
     909                       enum pdb_value_state flag)
     910{
     911        sampass->code_page = code_page;
     912        return pdb_set_init_flags(sampass, PDB_CODE_PAGE, flag);
     913}
     914
     915bool pdb_set_unknown_6(struct samu *sampass, uint32_t unkn, enum pdb_value_state flag)
    964916{
    965917        sampass->unknown_6 = unkn;
     
    967919}
    968920
    969 bool pdb_set_hours(struct samu *sampass, const uint8 *hours, enum pdb_value_state flag)
    970 {
     921bool pdb_set_hours(struct samu *sampass, const uint8 *hours, int hours_len,
     922                   enum pdb_value_state flag)
     923{
     924        if (hours_len > sizeof(sampass->hours)) {
     925                return false;
     926        }
     927
    971928        if (!hours) {
    972                 memset ((char *)sampass->hours, 0, MAX_HOURS_LEN);
    973         } else {
    974                 memcpy (sampass->hours, hours, MAX_HOURS_LEN);
     929                memset ((char *)sampass->hours, 0, hours_len);
     930        } else {
     931                memcpy (sampass->hours, hours, hours_len);
    975932        }
    976933
     
    1017974        uchar new_nt_p16[NT_HASH_LEN];
    1018975        uchar *pwhistory;
    1019         uint32 pwHistLen;
    1020         uint32 current_history_len;
     976        uint32_t pwHistLen;
     977        uint32_t current_history_len;
    1021978
    1022979        if (!plaintext)
     
    11261083
    11271084/* check for any PDB_SET/CHANGED field and fill the appropriate mask bit */
    1128 uint32 pdb_build_fields_present(struct samu *sampass)
     1085uint32_t pdb_build_fields_present(struct samu *sampass)
    11291086{
    11301087        /* value set to all for testing */
  • trunk/server/source3/passdb/pdb_interface.c

    r596 r745  
    2222
    2323#include "includes.h"
     24#include "system/passwd.h"
     25#include "passdb.h"
     26#include "secrets.h"
     27#include "../librpc/gen_ndr/samr.h"
     28#include "memcache.h"
     29#include "nsswitch/winbind_client.h"
     30#include "../libcli/security/security.h"
     31#include "../lib/util/util_pw.h"
    2432
    2533#undef DBGC_CLASS
     
    217225}
    218226
     227/**
     228 * @brief Check if the user account has been locked out and try to unlock it.
     229 *
     230 * If the user has been automatically locked out and a lockout duration is set,
     231 * then check if we can unlock the account and reset the bad password values.
     232 *
     233 * @param[in]  sampass  The sam user to check.
     234 *
     235 * @return              True if the function was successfull, false on an error.
     236 */
     237static bool pdb_try_account_unlock(struct samu *sampass)
     238{
     239        uint32_t acb_info = pdb_get_acct_ctrl(sampass);
     240
     241        if ((acb_info & ACB_NORMAL) && (acb_info & ACB_AUTOLOCK)) {
     242                uint32_t lockout_duration;
     243                time_t bad_password_time;
     244                time_t now = time(NULL);
     245                bool ok;
     246
     247                ok = pdb_get_account_policy(PDB_POLICY_LOCK_ACCOUNT_DURATION,
     248                                            &lockout_duration);
     249                if (!ok) {
     250                        DEBUG(0, ("pdb_try_account_unlock: "
     251                                  "pdb_get_account_policy failed.\n"));
     252                        return false;
     253                }
     254
     255                if (lockout_duration == (uint32_t) -1 ||
     256                    lockout_duration == 0) {
     257                        DEBUG(9, ("pdb_try_account_unlock: No reset duration, "
     258                                  "can't reset autolock\n"));
     259                        return false;
     260                }
     261                lockout_duration *= 60;
     262
     263                bad_password_time = pdb_get_bad_password_time(sampass);
     264                if (bad_password_time == (time_t) 0) {
     265                        DEBUG(2, ("pdb_try_account_unlock: Account %s "
     266                                  "administratively locked out "
     267                                  "with no bad password "
     268                                  "time. Leaving locked out.\n",
     269                                  pdb_get_username(sampass)));
     270                        return true;
     271                }
     272
     273                if ((bad_password_time +
     274                     convert_uint32_t_to_time_t(lockout_duration)) < now) {
     275                        NTSTATUS status;
     276
     277                        pdb_set_acct_ctrl(sampass, acb_info & ~ACB_AUTOLOCK,
     278                                          PDB_CHANGED);
     279                        pdb_set_bad_password_count(sampass, 0, PDB_CHANGED);
     280                        pdb_set_bad_password_time(sampass, 0, PDB_CHANGED);
     281
     282                        become_root();
     283                        status = pdb_update_sam_account(sampass);
     284                        unbecome_root();
     285                        if (!NT_STATUS_IS_OK(status)) {
     286                                DEBUG(0, ("_samr_OpenUser: Couldn't "
     287                                          "update account %s - %s\n",
     288                                          pdb_get_username(sampass),
     289                                          nt_errstr(status)));
     290                                return false;
     291                        }
     292                }
     293        }
     294
     295        return true;
     296}
     297
     298/**
     299 * @brief Get a sam user structure by the given username.
     300 *
     301 * This functions also checks if the account has been automatically locked out
     302 * and unlocks it if a lockout duration time has been defined and the time has
     303 * elapsed.
     304 *
     305 * @param[in]  sam_acct  The sam user structure to fill.
     306 *
     307 * @param[in]  username  The username to look for.
     308 *
     309 * @return               True on success, false on error.
     310 */
    219311bool pdb_getsampwnam(struct samu *sam_acct, const char *username)
    220312{
     
    222314        struct samu *for_cache;
    223315        const struct dom_sid *user_sid;
    224 
    225         if (!NT_STATUS_IS_OK(pdb->getsampwnam(pdb, sam_acct, username))) {
    226                 return False;
     316        NTSTATUS status;
     317        bool ok;
     318
     319        status = pdb->getsampwnam(pdb, sam_acct, username);
     320        if (!NT_STATUS_IS_OK(status)) {
     321                return false;
     322        }
     323
     324        ok = pdb_try_account_unlock(sam_acct);
     325        if (!ok) {
     326                DEBUG(1, ("pdb_getsampwnam: Failed to unlock account %s\n",
     327                          username));
    227328        }
    228329
     
    249350**********************************************************************/
    250351
    251 bool guest_user_info( struct samu *user )
     352static bool guest_user_info( struct samu *user )
    252353{
    253354        struct passwd *pwd;
     
    255356        const char *guestname = lp_guestaccount();
    256357
    257         if ( !(pwd = Get_Pwnam_alloc(talloc_autofree_context(), guestname ) ) ) {
     358        pwd = Get_Pwnam_alloc(talloc_tos(), guestname);
     359        if (pwd == NULL) {
    258360                DEBUG(0,("guest_user_info: Unable to locate guest account [%s]!\n",
    259361                        guestname));
     
    268370}
    269371
    270 /**********************************************************************
    271 **********************************************************************/
    272 
    273 bool pdb_getsampwsid(struct samu *sam_acct, const DOM_SID *sid)
    274 {
    275         struct pdb_methods *pdb = pdb_get_methods();
    276         uint32 rid;
     372/**
     373 * @brief Get a sam user structure by the given username.
     374 *
     375 * This functions also checks if the account has been automatically locked out
     376 * and unlocks it if a lockout duration time has been defined and the time has
     377 * elapsed.
     378 *
     379 *
     380 * @param[in]  sam_acct  The sam user structure to fill.
     381 *
     382 * @param[in]  sid       The user SDI to look up.
     383 *
     384 * @return               True on success, false on error.
     385 */
     386bool pdb_getsampwsid(struct samu *sam_acct, const struct dom_sid *sid)
     387{
     388        struct pdb_methods *pdb = pdb_get_methods();
     389        uint32_t rid;
    277390        void *cache_data;
     391        bool ok = false;
    278392
    279393        /* hard code the Guest RID of 501 */
     
    282396                return False;
    283397
    284         if ( rid == DOMAIN_USER_RID_GUEST ) {
     398        if ( rid == DOMAIN_RID_GUEST ) {
    285399                DEBUG(6,("pdb_getsampwsid: Building guest account\n"));
    286400                return guest_user_info( sam_acct );
     
    296410                        cache_data, struct samu);
    297411
    298                 return pdb_copy_sam_account(sam_acct, cache_copy);
    299         }
    300 
    301         return NT_STATUS_IS_OK(pdb->getsampwsid(pdb, sam_acct, sid));
     412                ok = pdb_copy_sam_account(sam_acct, cache_copy);
     413        } else {
     414                ok = NT_STATUS_IS_OK(pdb->getsampwsid(pdb, sam_acct, sid));
     415        }
     416
     417        if (!ok) {
     418                return false;
     419        }
     420
     421        ok = pdb_try_account_unlock(sam_acct);
     422        if (!ok) {
     423                DEBUG(1, ("pdb_getsampwsid: Failed to unlock account %s\n",
     424                          sam_acct->username));
     425        }
     426
     427        return true;
    302428}
    303429
    304430static NTSTATUS pdb_default_create_user(struct pdb_methods *methods,
    305431                                        TALLOC_CTX *tmp_ctx, const char *name,
    306                                         uint32 acb_info, uint32 *rid)
     432                                        uint32_t acb_info, uint32_t *rid)
    307433{
    308434        struct samu *sam_pass;
     
    354480
    355481                pwd = Get_Pwnam_alloc(tmp_ctx, name);
     482
     483                if(pwd == NULL) {
     484                        DEBUG(3, ("Could not find user %s, add script did not work\n", name));
     485                        return NT_STATUS_NO_SUCH_USER;
     486                }
    356487        }
    357488
     
    390521}
    391522
    392 NTSTATUS pdb_create_user(TALLOC_CTX *mem_ctx, const char *name, uint32 flags,
    393                          uint32 *rid)
     523NTSTATUS pdb_create_user(TALLOC_CTX *mem_ctx, const char *name, uint32_t flags,
     524                         uint32_t *rid)
    394525{
    395526        struct pdb_methods *pdb = pdb_get_methods();
     
    538669}
    539670
    540 bool pdb_getgrsid(GROUP_MAP *map, DOM_SID sid)
     671bool pdb_getgrsid(GROUP_MAP *map, struct dom_sid sid)
    541672{
    542673        struct pdb_methods *pdb = pdb_get_methods();
     
    559690                                             TALLOC_CTX *mem_ctx,
    560691                                             const char *name,
    561                                              uint32 *rid)
    562 {
    563         DOM_SID group_sid;
     692                                             uint32_t *rid)
     693{
     694        struct dom_sid group_sid;
    564695        struct group *grp;
    565696        fstring tmp;
     
    596727
    597728NTSTATUS pdb_create_dom_group(TALLOC_CTX *mem_ctx, const char *name,
    598                               uint32 *rid)
     729                              uint32_t *rid)
    599730{
    600731        struct pdb_methods *pdb = pdb_get_methods();
     
    604735static NTSTATUS pdb_default_delete_dom_group(struct pdb_methods *methods,
    605736                                             TALLOC_CTX *mem_ctx,
    606                                              uint32 rid)
    607 {
    608         DOM_SID group_sid;
     737                                             uint32_t rid)
     738{
     739        struct dom_sid group_sid;
    609740        GROUP_MAP map;
    610741        NTSTATUS status;
     
    653784}
    654785
    655 NTSTATUS pdb_delete_dom_group(TALLOC_CTX *mem_ctx, uint32 rid)
     786NTSTATUS pdb_delete_dom_group(TALLOC_CTX *mem_ctx, uint32_t rid)
    656787{
    657788        struct pdb_methods *pdb = pdb_get_methods();
     
    671802}
    672803
    673 NTSTATUS pdb_delete_group_mapping_entry(DOM_SID sid)
     804NTSTATUS pdb_delete_group_mapping_entry(struct dom_sid sid)
    674805{
    675806        struct pdb_methods *pdb = pdb_get_methods();
     
    677808}
    678809
    679 bool pdb_enum_group_mapping(const DOM_SID *sid, enum lsa_SidType sid_name_use, GROUP_MAP **pp_rmap,
     810bool pdb_enum_group_mapping(const struct dom_sid *sid, enum lsa_SidType sid_name_use, GROUP_MAP **pp_rmap,
    680811                            size_t *p_num_entries, bool unix_only)
    681812{
     
    686817
    687818NTSTATUS pdb_enum_group_members(TALLOC_CTX *mem_ctx,
    688                                 const DOM_SID *sid,
    689                                 uint32 **pp_member_rids,
     819                                const struct dom_sid *sid,
     820                                uint32_t **pp_member_rids,
    690821                                size_t *p_num_members)
    691822{
     
    699830
    700831        if ( !NT_STATUS_IS_OK( result ) ) {
    701                 uint32 rid;
     832                uint32_t rid;
    702833
    703834                sid_peek_rid( sid, &rid );
    704835
    705                 if ( rid == DOMAIN_GROUP_RID_USERS ) {
     836                if ( rid == DOMAIN_RID_USERS ) {
    706837                        *p_num_members = 0;
    707838                        *pp_member_rids = NULL;
     
    715846
    716847NTSTATUS pdb_enum_group_memberships(TALLOC_CTX *mem_ctx, struct samu *user,
    717                                     DOM_SID **pp_sids, gid_t **pp_gids,
    718                                     size_t *p_num_groups)
     848                                    struct dom_sid **pp_sids, gid_t **pp_gids,
     849                                    uint32_t *p_num_groups)
    719850{
    720851        struct pdb_methods *pdb = pdb_get_methods();
     
    757888
    758889static bool pdb_user_in_group(TALLOC_CTX *mem_ctx, struct samu *account,
    759                               const DOM_SID *group_sid)
    760 {
    761         DOM_SID *sids;
     890                              const struct dom_sid *group_sid)
     891{
     892        struct dom_sid *sids;
    762893        gid_t *gids;
    763         size_t i, num_groups;
     894        uint32_t i, num_groups;
    764895
    765896        if (!NT_STATUS_IS_OK(pdb_enum_group_memberships(mem_ctx, account,
     
    770901
    771902        for (i=0; i<num_groups; i++) {
    772                 if (sid_equal(group_sid, &sids[i])) {
     903                if (dom_sid_equal(group_sid, &sids[i])) {
    773904                        return True;
    774905                }
     
    779910static NTSTATUS pdb_default_add_groupmem(struct pdb_methods *methods,
    780911                                         TALLOC_CTX *mem_ctx,
    781                                          uint32 group_rid,
    782                                          uint32 member_rid)
    783 {
    784         DOM_SID group_sid, member_sid;
     912                                         uint32_t group_rid,
     913                                         uint32_t member_rid)
     914{
     915        struct dom_sid group_sid, member_sid;
    785916        struct samu *account = NULL;
    786917        GROUP_MAP map;
     
    835966}
    836967
    837 NTSTATUS pdb_add_groupmem(TALLOC_CTX *mem_ctx, uint32 group_rid,
    838                           uint32 member_rid)
     968NTSTATUS pdb_add_groupmem(TALLOC_CTX *mem_ctx, uint32_t group_rid,
     969                          uint32_t member_rid)
    839970{
    840971        struct pdb_methods *pdb = pdb_get_methods();
     
    844975static NTSTATUS pdb_default_del_groupmem(struct pdb_methods *methods,
    845976                                         TALLOC_CTX *mem_ctx,
    846                                          uint32 group_rid,
    847                                          uint32 member_rid)
    848 {
    849         DOM_SID group_sid, member_sid;
     977                                         uint32_t group_rid,
     978                                         uint32_t member_rid)
     979{
     980        struct dom_sid group_sid, member_sid;
    850981        struct samu *account = NULL;
    851982        GROUP_MAP map;
     
    8971028}
    8981029
    899 NTSTATUS pdb_del_groupmem(TALLOC_CTX *mem_ctx, uint32 group_rid,
    900                           uint32 member_rid)
     1030NTSTATUS pdb_del_groupmem(TALLOC_CTX *mem_ctx, uint32_t group_rid,
     1031                          uint32_t member_rid)
    9011032{
    9021033        struct pdb_methods *pdb = pdb_get_methods();
     
    9041035}
    9051036
    906 NTSTATUS pdb_create_alias(const char *name, uint32 *rid)
     1037NTSTATUS pdb_create_alias(const char *name, uint32_t *rid)
    9071038{
    9081039        struct pdb_methods *pdb = pdb_get_methods();
     
    9101041}
    9111042
    912 NTSTATUS pdb_delete_alias(const DOM_SID *sid)
     1043NTSTATUS pdb_delete_alias(const struct dom_sid *sid)
    9131044{
    9141045        struct pdb_methods *pdb = pdb_get_methods();
     
    9161047}
    9171048
    918 NTSTATUS pdb_get_aliasinfo(const DOM_SID *sid, struct acct_info *info)
     1049NTSTATUS pdb_get_aliasinfo(const struct dom_sid *sid, struct acct_info *info)
    9191050{
    9201051        struct pdb_methods *pdb = pdb_get_methods();
     
    9221053}
    9231054
    924 NTSTATUS pdb_set_aliasinfo(const DOM_SID *sid, struct acct_info *info)
     1055NTSTATUS pdb_set_aliasinfo(const struct dom_sid *sid, struct acct_info *info)
    9251056{
    9261057        struct pdb_methods *pdb = pdb_get_methods();
     
    9281059}
    9291060
    930 NTSTATUS pdb_add_aliasmem(const DOM_SID *alias, const DOM_SID *member)
     1061NTSTATUS pdb_add_aliasmem(const struct dom_sid *alias, const struct dom_sid *member)
    9311062{
    9321063        struct pdb_methods *pdb = pdb_get_methods();
     
    9341065}
    9351066
    936 NTSTATUS pdb_del_aliasmem(const DOM_SID *alias, const DOM_SID *member)
     1067NTSTATUS pdb_del_aliasmem(const struct dom_sid *alias, const struct dom_sid *member)
    9371068{
    9381069        struct pdb_methods *pdb = pdb_get_methods();
     
    9401071}
    9411072
    942 NTSTATUS pdb_enum_aliasmem(const DOM_SID *alias, TALLOC_CTX *mem_ctx,
    943                            DOM_SID **pp_members, size_t *p_num_members)
     1073NTSTATUS pdb_enum_aliasmem(const struct dom_sid *alias, TALLOC_CTX *mem_ctx,
     1074                           struct dom_sid **pp_members, size_t *p_num_members)
    9441075{
    9451076        struct pdb_methods *pdb = pdb_get_methods();
     
    9491080
    9501081NTSTATUS pdb_enum_alias_memberships(TALLOC_CTX *mem_ctx,
    951                                     const DOM_SID *domain_sid,
    952                                     const DOM_SID *members, size_t num_members,
    953                                     uint32 **pp_alias_rids,
     1082                                    const struct dom_sid *domain_sid,
     1083                                    const struct dom_sid *members, size_t num_members,
     1084                                    uint32_t **pp_alias_rids,
    9541085                                    size_t *p_num_alias_rids)
    9551086{
     
    9621093}
    9631094
    964 NTSTATUS pdb_lookup_rids(const DOM_SID *domain_sid,
     1095NTSTATUS pdb_lookup_rids(const struct dom_sid *domain_sid,
    9651096                         int num_rids,
    966                          uint32 *rids,
     1097                         uint32_t *rids,
    9671098                         const char **names,
    9681099                         enum lsa_SidType *attrs)
     
    9841115 */
    9851116#if 0
    986 NTSTATUS pdb_lookup_names(const DOM_SID *domain_sid,
     1117NTSTATUS pdb_lookup_names(const struct dom_sid *domain_sid,
    9871118                          int num_names,
    9881119                          const char **names,
    989                           uint32 *rids,
     1120                          uint32_t *rids,
    9901121                          enum lsa_SidType *attrs)
    9911122{
     
    10251156}
    10261157
    1027 bool pdb_uid_to_sid(uid_t uid, DOM_SID *sid)
     1158bool pdb_uid_to_sid(uid_t uid, struct dom_sid *sid)
    10281159{
    10291160        struct pdb_methods *pdb = pdb_get_methods();
     
    10311162}
    10321163
    1033 bool pdb_gid_to_sid(gid_t gid, DOM_SID *sid)
     1164bool pdb_gid_to_sid(gid_t gid, struct dom_sid *sid)
    10341165{
    10351166        struct pdb_methods *pdb = pdb_get_methods();
     
    10371168}
    10381169
    1039 bool pdb_sid_to_id(const DOM_SID *sid, union unid_t *id,
     1170bool pdb_sid_to_id(const struct dom_sid *sid, union unid_t *id,
    10401171                   enum lsa_SidType *type)
    10411172{
     
    10571188********************************************************************/
    10581189
    1059 bool pdb_new_rid(uint32 *rid)
     1190bool pdb_new_rid(uint32_t *rid)
    10601191{
    10611192        struct pdb_methods *pdb = pdb_get_methods();
    10621193        const char *name = NULL;
    10631194        enum lsa_SidType type;
    1064         uint32 allocated_rid = 0;
     1195        uint32_t allocated_rid = 0;
    10651196        int i;
    10661197        TALLOC_CTX *ctx;
     
    11371268}
    11381269
    1139 static NTSTATUS pdb_default_getsampwsid(struct pdb_methods *my_methods, struct samu * user, const DOM_SID *sid)
     1270static NTSTATUS pdb_default_getsampwsid(struct pdb_methods *my_methods, struct samu * user, const struct dom_sid *sid)
    11401271{
    11411272        return NT_STATUS_NO_SUCH_USER;
     
    11861317
    11871318static bool pdb_default_uid_to_sid(struct pdb_methods *methods, uid_t uid,
    1188                                    DOM_SID *sid)
     1319                                   struct dom_sid *sid)
    11891320{
    11901321        struct samu *sampw = NULL;
     
    12251356
    12261357static bool pdb_default_gid_to_sid(struct pdb_methods *methods, gid_t gid,
    1227                                    DOM_SID *sid)
     1358                                   struct dom_sid *sid)
    12281359{
    12291360        GROUP_MAP map;
     
    12381369
    12391370static bool pdb_default_sid_to_id(struct pdb_methods *methods,
    1240                                   const DOM_SID *sid,
     1371                                  const struct dom_sid *sid,
    12411372                                  union unid_t *id, enum lsa_SidType *type)
    12421373{
     
    12441375        bool ret = False;
    12451376        const char *name;
    1246         uint32 rid;
     1377        uint32_t rid;
    12471378
    12481379        mem_ctx = talloc_new(NULL);
     
    13111442}
    13121443
    1313 static bool get_memberuids(TALLOC_CTX *mem_ctx, gid_t gid, uid_t **pp_uids, size_t *p_num)
     1444static bool get_memberuids(TALLOC_CTX *mem_ctx, gid_t gid, uid_t **pp_uids, uint32_t *p_num)
    13141445{
    13151446        struct group *grp;
     
    13681499static NTSTATUS pdb_default_enum_group_members(struct pdb_methods *methods,
    13691500                                               TALLOC_CTX *mem_ctx,
    1370                                                const DOM_SID *group,
    1371                                                uint32 **pp_member_rids,
     1501                                               const struct dom_sid *group,
     1502                                               uint32_t **pp_member_rids,
    13721503                                               size_t *p_num_members)
    13731504{
    13741505        gid_t gid;
    13751506        uid_t *uids;
    1376         size_t i, num_uids;
     1507        uint32_t i, num_uids;
    13771508
    13781509        *pp_member_rids = NULL;
     
    13881519                return NT_STATUS_OK;
    13891520
    1390         *pp_member_rids = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_uids);
     1521        *pp_member_rids = TALLOC_ZERO_ARRAY(mem_ctx, uint32_t, num_uids);
    13911522
    13921523        for (i=0; i<num_uids; i++) {
    1393                 DOM_SID sid;
     1524                struct dom_sid sid;
    13941525
    13951526                uid_to_sid(&sid, uids[i]);
     
    14111542                                                   TALLOC_CTX *mem_ctx,
    14121543                                                   struct samu *user,
    1413                                                    DOM_SID **pp_sids,
     1544                                                   struct dom_sid **pp_sids,
    14141545                                                   gid_t **pp_gids,
    1415                                                    size_t *p_num_groups)
     1546                                                   uint32_t *p_num_groups)
    14161547{
    14171548        size_t i;
     
    14401571        }
    14411572
    1442         *pp_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *p_num_groups);
     1573        *pp_sids = TALLOC_ARRAY(mem_ctx, struct dom_sid, *p_num_groups);
    14431574
    14441575        if (*pp_sids == NULL) {
     
    14581589 ********************************************************************/
    14591590
    1460 static bool lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid,
     1591static bool lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32_t rid,
    14611592                                  const char **name,
    14621593                                  enum lsa_SidType *psid_name_use,
     
    14661597        GROUP_MAP map;
    14671598        bool ret;
    1468         DOM_SID sid;
     1599        struct dom_sid sid;
    14691600
    14701601        *psid_name_use = SID_NAME_UNKNOWN;
     
    14731604                 (unsigned int)rid));
    14741605
    1475         sid_copy(&sid, get_global_sam_sid());
    1476         sid_append_rid(&sid, rid);
     1606        sid_compose(&sid, get_global_sam_sid(), rid);
    14771607
    14781608        /* see if the passdb can help us with the name of the user */
     
    14821612        }
    14831613
    1484         /* BEING ROOT BLLOCK */
     1614        /* BEING ROOT BLOCK */
    14851615        become_root();
    14861616        if (pdb_getsampwsid(sam_account, &sid)) {
     
    15381668        }
    15391669
    1540         if ( rid == DOMAIN_GROUP_RID_USERS ) {
     1670        if ( rid == DOMAIN_RID_USERS ) {
    15411671                *name = talloc_strdup(mem_ctx, "None" );
    15421672                *psid_name_use = SID_NAME_DOM_GRP;
     
    15491679
    15501680static NTSTATUS pdb_default_lookup_rids(struct pdb_methods *methods,
    1551                                         const DOM_SID *domain_sid,
     1681                                        const struct dom_sid *domain_sid,
    15521682                                        int num_rids,
    1553                                         uint32 *rids,
     1683                                        uint32_t *rids,
    15541684                                        const char **names,
    15551685                                        enum lsa_SidType *attrs)
     
    16131743#if 0
    16141744static NTSTATUS pdb_default_lookup_names(struct pdb_methods *methods,
    1615                                          const DOM_SID *domain_sid,
     1745                                         const struct dom_sid *domain_sid,
    16161746                                         int num_names,
    16171747                                         const char **names,
    1618                                          uint32 *rids,
     1748                                         uint32_t *rids,
    16191749                                         enum lsa_SidType *attrs)
    16201750{
     
    16271757
    16281758                for (i=0; i<num_names; i++) {
    1629                         uint32 rid;
     1759                        uint32_t rid;
    16301760
    16311761                        if (lookup_builtin_name(names[i], &rid)) {
     
    17051835}
    17061836
    1707 static void fill_displayentry(TALLOC_CTX *mem_ctx, uint32 rid,
    1708                               uint16 acct_flags,
     1837static void fill_displayentry(TALLOC_CTX *mem_ctx, uint32_t rid,
     1838                              uint16_t acct_flags,
    17091839                              const char *account_name,
    17101840                              const char *fullname,
     
    17401870{
    17411871        struct group_search *state = (struct group_search *)s->private_data;
    1742         uint32 rid;
     1872        uint32_t rid;
    17431873        GROUP_MAP *map = &state->groups[state->current_group];
    17441874
     
    17621892
    17631893static bool pdb_search_grouptype(struct pdb_search *search,
    1764                                  const DOM_SID *sid, enum lsa_SidType type)
     1894                                 const struct dom_sid *sid, enum lsa_SidType type)
    17651895{
    17661896        struct group_search *state;
     
    17931923static bool pdb_default_search_aliases(struct pdb_methods *methods,
    17941924                                       struct pdb_search *search,
    1795                                        const DOM_SID *sid)
     1925                                       const struct dom_sid *sid)
    17961926{
    17971927
     
    18001930
    18011931static struct samr_displayentry *pdb_search_getentry(struct pdb_search *search,
    1802                                                      uint32 idx)
     1932                                                     uint32_t idx)
    18031933{
    18041934        if (idx < search->num_entries)
     
    18251955}
    18261956
    1827 struct pdb_search *pdb_search_users(TALLOC_CTX *mem_ctx, uint32 acct_flags)
     1957struct pdb_search *pdb_search_users(TALLOC_CTX *mem_ctx, uint32_t acct_flags)
    18281958{
    18291959        struct pdb_methods *pdb = pdb_get_methods();
     
    18591989}
    18601990
    1861 struct pdb_search *pdb_search_aliases(TALLOC_CTX *mem_ctx, const DOM_SID *sid)
     1991struct pdb_search *pdb_search_aliases(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
    18621992{
    18631993        struct pdb_methods *pdb = pdb_get_methods();
     
    18782008}
    18792009
    1880 uint32 pdb_search_entries(struct pdb_search *search,
    1881                           uint32 start_idx, uint32 max_entries,
     2010uint32_t pdb_search_entries(struct pdb_search *search,
     2011                          uint32_t start_idx, uint32_t max_entries,
    18822012                          struct samr_displayentry **result)
    18832013{
    18842014        struct samr_displayentry *end_entry;
    1885         uint32 end_idx = start_idx+max_entries-1;
     2015        uint32_t end_idx = start_idx+max_entries-1;
    18862016
    18872017        /* The first entry needs to be searched after the last. Otherwise the
     
    19052035 *******************************************************************/
    19062036
    1907 bool pdb_get_trusteddom_pw(const char *domain, char** pwd, DOM_SID *sid,
     2037bool pdb_get_trusteddom_pw(const char *domain, char** pwd, struct dom_sid *sid,
    19082038                           time_t *pass_last_set_time)
    19092039{
     
    19142044
    19152045bool pdb_set_trusteddom_pw(const char* domain, const char* pwd,
    1916                            const DOM_SID *sid)
     2046                           const struct dom_sid *sid)
    19172047{
    19182048        struct pdb_methods *pdb = pdb_get_methods();
     
    19262056}
    19272057
    1928 NTSTATUS pdb_enum_trusteddoms(TALLOC_CTX *mem_ctx, uint32 *num_domains,
     2058NTSTATUS pdb_enum_trusteddoms(TALLOC_CTX *mem_ctx, uint32_t *num_domains,
    19292059                              struct trustdom_info ***domains)
    19302060{
     
    19422072                                          const char *domain,
    19432073                                          char** pwd,
    1944                                           DOM_SID *sid,
     2074                                          struct dom_sid *sid,
    19452075                                          time_t *pass_last_set_time)
    19462076{
     
    19532083                                          const char* domain,
    19542084                                          const char* pwd,
    1955                                           const DOM_SID *sid)
     2085                                          const struct dom_sid *sid)
    19562086{
    19572087        return secrets_store_trusted_domain_password(domain, pwd, sid);
     
    19662096static NTSTATUS pdb_default_enum_trusteddoms(struct pdb_methods *methods,
    19672097                                             TALLOC_CTX *mem_ctx,
    1968                                              uint32 *num_domains,
     2098                                             uint32_t *num_domains,
    19692099                                             struct trustdom_info ***domains)
    19702100{
    19712101        return secrets_trusted_domains(mem_ctx, num_domains, domains);
     2102}
     2103
     2104/*******************************************************************
     2105 trusted_domain methods
     2106 *******************************************************************/
     2107
     2108NTSTATUS pdb_get_trusted_domain(TALLOC_CTX *mem_ctx, const char *domain,
     2109                                struct pdb_trusted_domain **td)
     2110{
     2111        struct pdb_methods *pdb = pdb_get_methods();
     2112        return pdb->get_trusted_domain(pdb, mem_ctx, domain, td);
     2113}
     2114
     2115NTSTATUS pdb_get_trusted_domain_by_sid(TALLOC_CTX *mem_ctx, struct dom_sid *sid,
     2116                                struct pdb_trusted_domain **td)
     2117{
     2118        struct pdb_methods *pdb = pdb_get_methods();
     2119        return pdb->get_trusted_domain_by_sid(pdb, mem_ctx, sid, td);
     2120}
     2121
     2122NTSTATUS pdb_set_trusted_domain(const char* domain,
     2123                                const struct pdb_trusted_domain *td)
     2124{
     2125        struct pdb_methods *pdb = pdb_get_methods();
     2126        return pdb->set_trusted_domain(pdb, domain, td);
     2127}
     2128
     2129NTSTATUS pdb_del_trusted_domain(const char *domain)
     2130{
     2131        struct pdb_methods *pdb = pdb_get_methods();
     2132        return pdb->del_trusted_domain(pdb, domain);
     2133}
     2134
     2135NTSTATUS pdb_enum_trusted_domains(TALLOC_CTX *mem_ctx, uint32_t *num_domains,
     2136                                  struct pdb_trusted_domain ***domains)
     2137{
     2138        struct pdb_methods *pdb = pdb_get_methods();
     2139        return pdb->enum_trusted_domains(pdb, mem_ctx, num_domains, domains);
     2140}
     2141
     2142static NTSTATUS pdb_default_get_trusted_domain(struct pdb_methods *methods,
     2143                                               TALLOC_CTX *mem_ctx,
     2144                                               const char *domain,
     2145                                               struct pdb_trusted_domain **td)
     2146{
     2147        return NT_STATUS_NOT_IMPLEMENTED;
     2148}
     2149
     2150static NTSTATUS pdb_default_get_trusted_domain_by_sid(struct pdb_methods *methods,
     2151                                                      TALLOC_CTX *mem_ctx,
     2152                                                      struct dom_sid *sid,
     2153                                                      struct pdb_trusted_domain **td)
     2154{
     2155        return NT_STATUS_NOT_IMPLEMENTED;
     2156}
     2157
     2158static NTSTATUS pdb_default_set_trusted_domain(struct pdb_methods *methods,
     2159                                               const char* domain,
     2160                                               const struct pdb_trusted_domain *td)
     2161{
     2162        return NT_STATUS_NOT_IMPLEMENTED;
     2163}
     2164
     2165static NTSTATUS pdb_default_del_trusted_domain(struct pdb_methods *methods,
     2166                                               const char *domain)
     2167{
     2168        return NT_STATUS_NOT_IMPLEMENTED;
     2169}
     2170
     2171static NTSTATUS pdb_default_enum_trusted_domains(struct pdb_methods *methods,
     2172                                                 TALLOC_CTX *mem_ctx,
     2173                                                 uint32_t *num_domains,
     2174                                                 struct pdb_trusted_domain ***domains)
     2175{
     2176        return NT_STATUS_NOT_IMPLEMENTED;
    19722177}
    19732178
     
    19892194        /* allocate memory for the structure as its own talloc CTX */
    19902195
    1991         *methods = talloc_zero(talloc_autofree_context(), struct pdb_methods);
     2196        *methods = talloc_zero(NULL, struct pdb_methods);
    19922197        if (*methods == NULL) {
    19932198                return NT_STATUS_NO_MEMORY;
     
    20432248        (*methods)->enum_trusteddoms  = pdb_default_enum_trusteddoms;
    20442249
     2250        (*methods)->get_trusted_domain = pdb_default_get_trusted_domain;
     2251        (*methods)->get_trusted_domain_by_sid = pdb_default_get_trusted_domain_by_sid;
     2252        (*methods)->set_trusted_domain = pdb_default_set_trusted_domain;
     2253        (*methods)->del_trusted_domain = pdb_default_del_trusted_domain;
     2254        (*methods)->enum_trusted_domains = pdb_default_enum_trusted_domains;
     2255
    20452256        return NT_STATUS_OK;
    20462257}
  • 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}
  • trunk/server/source3/passdb/pdb_nds.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "passdb.h"
    2223
    2324#include <lber.h>
  • trunk/server/source3/passdb/pdb_smbpasswd.c

    r596 r745  
    2222
    2323#include "includes.h"
     24#include "passdb.h"
     25#include "system/passwd.h"
     26#include "system/filesys.h"
     27#include "../librpc/gen_ndr/samr.h"
     28#include "../libcli/security/security.h"
    2429
    2530#undef DBGC_CLASS
     
    3136   stored by an smbpasswd entry
    3237 */
    33  
     38
    3439struct smb_passwd
    3540{
     
    4045        const unsigned char *smb_nt_passwd; /* Null if no password */
    4146
    42         uint16 acct_ctrl;             /* account info (ACB_xxxx bit-mask) */
     47        uint16_t acct_ctrl;             /* account info (ACB_xxxx bit-mask) */
    4348        time_t pass_last_set_time;    /* password last set time */
    4449};
     
    4853        /* used for maintain locks on the smbpasswd file */
    4954        int     pw_file_lock_depth;
    50        
     55
    5156        /* Global File pointer */
    5257        FILE    *pw_file;
    53        
     58
    5459        /* formerly static variables */
    5560        struct smb_passwd pw_buf;
     
    7075****************************************************************/
    7176
    72 static void gotalarm_sig(void)
     77static void gotalarm_sig(int signum)
    7378{
    7479        gotalarm = 1;
     
    8792
    8893        gotalarm = 0;
    89         oldsig_handler = CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
     94        oldsig_handler = CatchSignal(SIGALRM, gotalarm_sig);
    9095
    9196        lock.l_type = type;
     
    99104        ret = fcntl(fd, SMB_F_SETLKW, &lock);
    100105        alarm(0);
    101         CatchSignal(SIGALRM, SIGNAL_CAST oldsig_handler);
     106        CatchSignal(SIGALRM, oldsig_handler);
    102107
    103108        if (gotalarm && ret == -1) {
     
    169174                return;
    170175        ZERO_STRUCTP (user);
    171        
     176
    172177        user->pass_last_set_time = (time_t)0;
    173178}
     
    224229                                break;
    225230                        }
    226         }
    227                        
     231                default:
     232                        DEBUG(10, ("Invalid open mode: %d\n", type));
     233                        return NULL;
     234        }
     235
    228236        for(race_loop = 0; race_loop < 5; race_loop++) {
    229237                DEBUG(10, ("startsmbfilepwent_internal: opening file %s\n", pfile));
     
    621629        slprintf((char *)p, new_entry_length - 1 - (p - new_entry),  "%s:LCT-%08X:\n",
    622630                pdb_encode_acct_ctrl(newpwd->acct_ctrl, NEW_PW_FORMAT_SPACE_PADDED_LEN),
    623                 (uint32)newpwd->pass_last_set_time);
     631                (uint32_t)newpwd->pass_last_set_time);
    624632
    625633        return new_entry;
     
    10101018                        sizeof(ascii_p16)-(strlen(ascii_p16)+1),
    10111019                        "%s:LCT-%08X:",
    1012                         encode_bits, (uint32)pwd->pass_last_set_time );
     1020                        encode_bits, (uint32_t)pwd->pass_last_set_time );
    10131021                wr_len = strlen(ascii_p16);
    10141022        }
     
    11741182         * Do an atomic rename - then release the locks.
    11751183         */
     1184
    11761185#ifdef __OS2__
    11771186        endsmbfilepwent(fp, &smbpasswd_state->pw_file_lock_depth);
    11781187        endsmbfilepwent(fp_write,&pfile2_lockdepth);
    11791188#endif
    1180 
    11811189        if(rename(pfile2,pfile) != 0) {
    11821190                unlink(pfile2);
     
    11981206static bool build_smb_pass (struct smb_passwd *smb_pw, const struct samu *sampass)
    11991207{
    1200         uint32 rid;
     1208        uint32_t rid;
    12011209
    12021210        if (sampass == NULL)
     
    12061214        if (!IS_SAM_DEFAULT(sampass, PDB_USERSID)) {
    12071215                rid = pdb_get_user_rid(sampass);
    1208                
     1216
    12091217                /* If the user specified a RID, make sure its able to be both stored and retreived */
    1210                 if (rid == DOMAIN_USER_RID_GUEST) {
     1218                if (rid == DOMAIN_RID_GUEST) {
    12111219                        struct passwd *passwd = Get_Pwnam_alloc(NULL, lp_guestaccount());
    12121220                        if (!passwd) {
    1213                                 DEBUG(0, ("Could not find guest account via getpwnam()! (%s)\n", lp_guestaccount()));
     1221                                DEBUG(0, ("Could not find guest account via Get_Pwnam_alloc()! (%s)\n", lp_guestaccount()));
    12141222                                return False;
    12151223                        }
     
    12431251{
    12441252        struct passwd *pwfile;
    1245        
     1253
    12461254        if ( !sam_pass ) {
    12471255                DEBUG(5,("build_sam_account: struct samu is NULL\n"));
     
    12561264                        return False;
    12571265        }
    1258        
     1266
    12591267        if ( !NT_STATUS_IS_OK( samu_set_unix(sam_pass, pwfile )) )
    12601268                return False;
    1261                
     1269
    12621270        TALLOC_FREE(pwfile);
    12631271
    12641272        /* set remaining fields */
    1265                
     1273
    12661274        if (!pdb_set_nt_passwd (sam_pass, pw_buf->smb_nt_passwd, PDB_SET))
    12671275                return False;
     
    12711279        pdb_set_pass_last_set_time (sam_pass, pw_buf->pass_last_set_time, PDB_SET);
    12721280        pdb_set_pass_can_change_time (sam_pass, pw_buf->pass_last_set_time, PDB_SET);
    1273        
     1281
    12741282        return True;
    12751283}
     
    13071315        while ( ((smb_pw=getsmbfilepwent(smbpasswd_state, fp)) != NULL)&& (!strequal(smb_pw->smb_name, username)) )
    13081316                /* do nothing....another loop */ ;
    1309        
     1317
    13101318        endsmbfilepwent(fp, &(smbpasswd_state->pw_file_lock_depth));
    13111319
     
    13141322        if (smb_pw == NULL)
    13151323                return nt_status;
    1316        
     1324
    13171325        DEBUG(10, ("getsampwnam (smbpasswd): found by name: %s\n", smb_pw->smb_name));
    13181326
     
    13211329                return nt_status;
    13221330        }
    1323                
     1331
    13241332        /* now build the struct samu */
    13251333        if (!build_sam_account(smbpasswd_state, sam_acct, smb_pw))
     
    13301338}
    13311339
    1332 static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, struct samu *sam_acct, const DOM_SID *sid)
     1340static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, struct samu *sam_acct, const struct dom_sid *sid)
    13331341{
    13341342        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
     
    13361344        struct smb_passwd *smb_pw;
    13371345        FILE *fp = NULL;
    1338         uint32 rid;
    1339        
     1346        uint32_t rid;
     1347
    13401348        DEBUG(10, ("smbpasswd_getsampwrid: search by sid: %s\n",
    13411349                   sid_string_dbg(sid)));
     
    13451353
    13461354        /* More special case 'guest account' hacks... */
    1347         if (rid == DOMAIN_USER_RID_GUEST) {
     1355        if (rid == DOMAIN_RID_GUEST) {
    13481356                const char *guest_account = lp_guestaccount();
    13491357                if (!(guest_account && *guest_account)) {
     
    13711379        if (smb_pw == NULL)
    13721380                return nt_status;
    1373        
     1381
    13741382        DEBUG(10, ("getsampwrid (smbpasswd): found by name: %s\n", smb_pw->smb_name));
    1375                
     1383
    13761384        if (!sam_acct) {
    13771385                DEBUG(10,("getsampwrid: (smbpasswd) struct samu is NULL\n"));
     
    13841392
    13851393        /* build_sam_account might change the SID on us, if the name was for the guest account */
    1386         if (NT_STATUS_IS_OK(nt_status) && !sid_equal(pdb_get_user_sid(sam_acct), sid)) {
     1394        if (NT_STATUS_IS_OK(nt_status) && !dom_sid_equal(pdb_get_user_sid(sam_acct), sid)) {
    13871395                DEBUG(1, ("looking for user with sid %s instead returned %s "
    13881396                          "for account %s!?!\n", sid_string_dbg(sid),
     
    14001408        struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data;
    14011409        struct smb_passwd smb_pw;
    1402        
     1410
    14031411        /* convert the struct samu */
    14041412        if (!build_smb_pass(&smb_pw, sampass)) {
    14051413                return NT_STATUS_UNSUCCESSFUL;
    14061414        }
    1407        
     1415
    14081416        /* add the entry */
    14091417        return add_smbfilepwd_entry(smbpasswd_state, &smb_pw);
     
    14141422        struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data;
    14151423        struct smb_passwd smb_pw;
    1416        
     1424
    14171425        /* convert the struct samu */
    14181426        if (!build_smb_pass(&smb_pw, sampass)) {
     
    14201428                return NT_STATUS_UNSUCCESSFUL;
    14211429        }
    1422        
     1430
    14231431        /* update the entry */
    14241432        if(!mod_smbfilepwd_entry(smbpasswd_state, &smb_pw)) {
     
    14261434                return NT_STATUS_UNSUCCESSFUL;
    14271435        }
    1428        
     1436
    14291437        return NT_STATUS_OK;
    14301438}
     
    14581466                return NT_STATUS_NO_MEMORY;
    14591467        }
    1460        
     1468
    14611469        if ( !pdb_copy_sam_account( new_acct, old_acct )
    14621470                || !pdb_set_username(new_acct, newname, PDB_CHANGED))
     
    15291537        if (new_acct)
    15301538                TALLOC_FREE(new_acct);
    1531        
     1539
    15321540        return (ret);   
    15331541}
     
    15411549{
    15421550        struct smbpasswd_privates **privates = (struct smbpasswd_privates**)vp;
    1543        
     1551
    15441552        endsmbfilepwent((*privates)->pw_file, &((*privates)->pw_file_lock_depth));
    1545        
     1553
    15461554        *privates = NULL;
    15471555        /* No need to free any further, as it is talloc()ed */
     
    17111719                privates->smbpasswd_file = talloc_strdup(*pdb_method, lp_smb_passwd_file());
    17121720        }
    1713        
     1721
    17141722        if (!privates->smbpasswd_file) {
    17151723                DEBUG(0, ("talloc_strdp() failed for storing smbpasswd location!\n"));
  • trunk/server/source3/passdb/pdb_tdb.c

    r657 r745  
    2424
    2525#include "includes.h"
     26#include "system/filesys.h"
     27#include "passdb.h"
     28#include "dbwrap.h"
     29#include "../libcli/security/security.h"
     30#include "util_tdb.h"
    2631
    2732#if 0 /* when made a module use this */
     
    618623
    619624static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods,
    620                                    struct samu * user, const DOM_SID *sid)
     625                                   struct samu * user, const struct dom_sid *sid)
    621626{
    622627        uint32 rid;
  • trunk/server/source3/passdb/pdb_wbc_sam.c

    r414 r745  
    3838
    3939#include "includes.h"
     40#include "passdb.h"
     41#include "lib/winbind_util.h"
    4042
    4143/***************************************************************************
     
    5153                return NT_STATUS_NO_SUCH_USER;
    5254
    53         memset(user, 0, sizeof(user));
     55        ZERO_STRUCTP(user);
    5456
    5557        /* Can we really get away with this little of information */
     
    6567}
    6668
    67 static NTSTATUS pdb_wbc_sam_getsampwsid(struct pdb_methods *methods, struct samu *user, const DOM_SID *sid)
     69static NTSTATUS pdb_wbc_sam_getsampwsid(struct pdb_methods *methods, struct samu *user, const struct dom_sid *sid)
    6870{
    6971        return _pdb_wbc_sam_getsampw(methods, user, winbind_getpwsid(sid));
     
    7173
    7274static bool pdb_wbc_sam_uid_to_sid(struct pdb_methods *methods, uid_t uid,
    73                                    DOM_SID *sid)
     75                                   struct dom_sid *sid)
    7476{
    7577        return winbind_uid_to_sid(sid, uid);
     
    7779
    7880static bool pdb_wbc_sam_gid_to_sid(struct pdb_methods *methods, gid_t gid,
    79                                    DOM_SID *sid)
     81                                   struct dom_sid *sid)
    8082{
    8183        return winbind_gid_to_sid(sid, gid);
     
    8486static NTSTATUS pdb_wbc_sam_enum_group_members(struct pdb_methods *methods,
    8587                                               TALLOC_CTX *mem_ctx,
    86                                                const DOM_SID *group,
     88                                               const struct dom_sid *group,
    8789                                               uint32 **pp_member_rids,
    8890                                               size_t *p_num_members)
     
    9496                                                   TALLOC_CTX *mem_ctx,
    9597                                                   struct samu *user,
    96                                                    DOM_SID **pp_sids,
     98                                                   struct dom_sid **pp_sids,
    9799                                                   gid_t **pp_gids,
    98                                                    size_t *p_num_groups)
     100                                                   uint32_t *p_num_groups)
    99101{
    100102        size_t i;
     
    111113        }
    112114
    113         *pp_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *p_num_groups);
     115        *pp_sids = TALLOC_ARRAY(mem_ctx, struct dom_sid, *p_num_groups);
    114116
    115117        if (*pp_sids == NULL) {
     
    126128
    127129static NTSTATUS pdb_wbc_sam_lookup_rids(struct pdb_methods *methods,
    128                                         const DOM_SID *domain_sid,
     130                                        const struct dom_sid *domain_sid,
    129131                                        int num_rids,
    130132                                        uint32 *rids,
     
    186188static bool pdb_wbc_sam_search_aliases(struct pdb_methods *methods,
    187189                                       struct pdb_search *search,
    188                                        const DOM_SID *sid)
     190                                       const struct dom_sid *sid)
    189191{
    190192
     
    195197                                          const char *domain,
    196198                                          char **pwd,
    197                                           DOM_SID *sid,
     199                                          struct dom_sid *sid,
    198200                                          time_t *pass_last_set_time)
    199201{
     
    205207                                          const char *domain,
    206208                                          const char *pwd,
    207                                           const DOM_SID *sid)
     209                                          const struct dom_sid *sid)
    208210{
    209211        return false;
     
    224226}
    225227
    226 static bool _make_group_map(struct pdb_methods *methods, const char *domain, const char *name, enum lsa_SidType name_type, gid_t gid, DOM_SID *sid, GROUP_MAP *map)
     228static bool _make_group_map(struct pdb_methods *methods, const char *domain, const char *name, enum lsa_SidType name_type, gid_t gid, struct dom_sid *sid, GROUP_MAP *map)
    227229{
    228230        snprintf(map->nt_name, sizeof(map->nt_name), "%s%c%s",
     
    235237
    236238static NTSTATUS pdb_wbc_sam_getgrsid(struct pdb_methods *methods, GROUP_MAP *map,
    237                                  DOM_SID sid)
     239                                 struct dom_sid sid)
    238240{
    239241        NTSTATUS result = NT_STATUS_OK;
     
    279281        char *name = NULL;
    280282        char *domain = NULL;
    281         DOM_SID sid;
     283        struct dom_sid sid;
    282284        enum lsa_SidType name_type;
    283285
     
    318320        NTSTATUS result = NT_STATUS_OK;
    319321        const char *domain = "";
    320         DOM_SID sid;
     322        struct dom_sid sid;
    321323        gid_t gid;
    322324        enum lsa_SidType name_type;
     
    351353
    352354static NTSTATUS pdb_wbc_sam_enum_group_mapping(struct pdb_methods *methods,
    353                                            const DOM_SID *sid, enum lsa_SidType sid_name_use,
     355                                           const struct dom_sid *sid, enum lsa_SidType sid_name_use,
    354356                                           GROUP_MAP **pp_rmap, size_t *p_num_entries,
    355357                                           bool unix_only)
     
    359361
    360362static NTSTATUS pdb_wbc_sam_get_aliasinfo(struct pdb_methods *methods,
    361                                    const DOM_SID *sid,
     363                                   const struct dom_sid *sid,
    362364                                   struct acct_info *info)
    363365{
     
    366368
    367369static NTSTATUS pdb_wbc_sam_enum_aliasmem(struct pdb_methods *methods,
    368                                           const DOM_SID *alias,
     370                                          const struct dom_sid *alias,
    369371                                          TALLOC_CTX *mem_ctx,
    370                                           DOM_SID **pp_members,
     372                                          struct dom_sid **pp_members,
    371373                                          size_t *p_num_members)
    372374{
     
    376378static NTSTATUS pdb_wbc_sam_alias_memberships(struct pdb_methods *methods,
    377379                                       TALLOC_CTX *mem_ctx,
    378                                        const DOM_SID *domain_sid,
    379                                        const DOM_SID *members,
     380                                       const struct dom_sid *domain_sid,
     381                                       const struct dom_sid *members,
    380382                                       size_t num_members,
    381383                                       uint32 **pp_alias_rids,
  • trunk/server/source3/passdb/secrets.c

    r480 r745  
    2424
    2525#include "includes.h"
     26#include "system/filesys.h"
     27#include "passdb.h"
    2628#include "../libcli/auth/libcli_auth.h"
    2729#include "librpc/gen_ndr/ndr_secrets.h"
     30#include "secrets.h"
     31#include "dbwrap.h"
     32#include "../libcli/security/security.h"
     33#include "util_tdb.h"
    2834
    2935#undef DBGC_CLASS
     
    3137
    3238static struct db_context *db_ctx;
    33 
    34 /* Urrrg. global.... */
    35 bool global_machine_password_needs_changing;
    3639
    3740/**
     
    171174
    172175/**
    173  * Form a key for fetching the domain sid
    174  *
    175  * @param domain domain name
    176  *
    177  * @return keystring
    178  **/
    179 static const char *domain_sid_keystr(const char *domain)
    180 {
    181         char *keystr;
    182 
    183         keystr = talloc_asprintf_strupper_m(talloc_tos(), "%s/%s",
    184                                             SECRETS_DOMAIN_SID, domain);
    185         SMB_ASSERT(keystr != NULL);
    186         return keystr;
    187 }
    188 
    189 bool secrets_store_domain_sid(const char *domain, const DOM_SID *sid)
    190 {
    191         bool ret;
    192 
    193         ret = secrets_store(domain_sid_keystr(domain), sid, sizeof(DOM_SID));
    194 
    195         /* Force a re-query, in case we modified our domain */
    196         if (ret)
    197                 reset_global_sam_sid();
    198         return ret;
    199 }
    200 
    201 bool secrets_fetch_domain_sid(const char *domain, DOM_SID *sid)
    202 {
    203         DOM_SID *dyn_sid;
    204         size_t size = 0;
    205 
    206         dyn_sid = (DOM_SID *)secrets_fetch(domain_sid_keystr(domain), &size);
    207 
    208         if (dyn_sid == NULL)
    209                 return False;
    210 
    211         if (size != sizeof(DOM_SID)) {
    212                 SAFE_FREE(dyn_sid);
    213                 return False;
    214         }
    215 
    216         *sid = *dyn_sid;
    217         SAFE_FREE(dyn_sid);
    218         return True;
    219 }
    220 
    221 bool secrets_store_domain_guid(const char *domain, struct GUID *guid)
    222 {
    223         fstring key;
    224 
    225         slprintf(key, sizeof(key)-1, "%s/%s", SECRETS_DOMAIN_GUID, domain);
    226         strupper_m(key);
    227         return secrets_store(key, guid, sizeof(struct GUID));
    228 }
    229 
    230 bool secrets_fetch_domain_guid(const char *domain, struct GUID *guid)
    231 {
    232         struct GUID *dyn_guid;
    233         fstring key;
    234         size_t size = 0;
    235         struct GUID new_guid;
    236 
    237         slprintf(key, sizeof(key)-1, "%s/%s", SECRETS_DOMAIN_GUID, domain);
    238         strupper_m(key);
    239         dyn_guid = (struct GUID *)secrets_fetch(key, &size);
    240 
    241         if (!dyn_guid) {
    242                 if (lp_server_role() == ROLE_DOMAIN_PDC) {
    243                         new_guid = GUID_random();
    244                         if (!secrets_store_domain_guid(domain, &new_guid))
    245                                 return False;
    246                         dyn_guid = (struct GUID *)secrets_fetch(key, &size);
    247                 }
    248                 if (dyn_guid == NULL) {
    249                         return False;
    250                 }
    251         }
    252 
    253         if (size != sizeof(struct GUID)) {
    254                 DEBUG(1,("UUID size %d is wrong!\n", (int)size));
    255                 SAFE_FREE(dyn_guid);
    256                 return False;
    257         }
    258 
    259         *guid = *dyn_guid;
    260         SAFE_FREE(dyn_guid);
    261         return True;
    262 }
    263 
    264 bool secrets_store_local_schannel_key(uint8_t schannel_key[16])
    265 {
    266         return secrets_store(SECRETS_LOCAL_SCHANNEL_KEY, schannel_key, 16);
    267 }
    268 
    269 bool secrets_fetch_local_schannel_key(uint8_t schannel_key[16])
    270 {
    271         size_t size = 0;
    272         uint8_t *key;
    273 
    274         key = (uint8_t *)secrets_fetch(SECRETS_LOCAL_SCHANNEL_KEY, &size);
    275         if (key == NULL) {
    276                 return false;
    277         }
    278 
    279         if (size != 16) {
    280                 SAFE_FREE(key);
    281                 return false;
    282         }
    283 
    284         memcpy(schannel_key, key, 16);
    285         SAFE_FREE(key);
    286         return true;
    287 }
    288 
    289 /**
    290  * Form a key for fetching the machine trust account sec channel type
    291  *
    292  * @param domain domain name
    293  *
    294  * @return keystring
    295  **/
    296 static const char *machine_sec_channel_type_keystr(const char *domain)
    297 {
    298         char *keystr;
    299 
    300         keystr = talloc_asprintf_strupper_m(talloc_tos(), "%s/%s",
    301                                             SECRETS_MACHINE_SEC_CHANNEL_TYPE,
    302                                             domain);
    303         SMB_ASSERT(keystr != NULL);
    304         return keystr;
    305 }
    306 
    307 /**
    308  * Form a key for fetching the machine trust account last change time
    309  *
    310  * @param domain domain name
    311  *
    312  * @return keystring
    313  **/
    314 static const char *machine_last_change_time_keystr(const char *domain)
    315 {
    316         char *keystr;
    317 
    318         keystr = talloc_asprintf_strupper_m(talloc_tos(), "%s/%s",
    319                                             SECRETS_MACHINE_LAST_CHANGE_TIME,
    320                                             domain);
    321         SMB_ASSERT(keystr != NULL);
    322         return keystr;
    323 }
    324 
    325 
    326 /**
    327  * Form a key for fetching the machine previous trust account password
    328  *
    329  * @param domain domain name
    330  *
    331  * @return keystring
    332  **/
    333 static const char *machine_prev_password_keystr(const char *domain)
    334 {
    335         char *keystr;
    336 
    337         keystr = talloc_asprintf_strupper_m(talloc_tos(), "%s/%s",
    338                                             SECRETS_MACHINE_PASSWORD_PREV, domain);
    339         SMB_ASSERT(keystr != NULL);
    340         return keystr;
    341 }
    342 
    343 /**
    344  * Form a key for fetching the machine trust account password
    345  *
    346  * @param domain domain name
    347  *
    348  * @return keystring
    349  **/
    350 static const char *machine_password_keystr(const char *domain)
    351 {
    352         char *keystr;
    353 
    354         keystr = talloc_asprintf_strupper_m(talloc_tos(), "%s/%s",
    355                                             SECRETS_MACHINE_PASSWORD, domain);
    356         SMB_ASSERT(keystr != NULL);
    357         return keystr;
    358 }
    359 
    360 /**
    361  * Form a key for fetching the machine trust account password
    362  *
    363  * @param domain domain name
    364  *
    365  * @return stored password's key
    366  **/
    367 static const char *trust_keystr(const char *domain)
    368 {
    369         char *keystr;
    370 
    371         keystr = talloc_asprintf_strupper_m(talloc_tos(), "%s/%s",
    372                                             SECRETS_MACHINE_ACCT_PASS, domain);
    373         SMB_ASSERT(keystr != NULL);
    374         return keystr;
    375 }
    376 
    377 /**
    378176 * Form a key for fetching a trusted domain password
    379177 *
     
    394192
    395193/************************************************************************
    396  Lock the trust password entry.
    397 ************************************************************************/
    398 
    399 void *secrets_get_trust_account_lock(TALLOC_CTX *mem_ctx, const char *domain)
    400 {
    401         if (!secrets_init()) {
    402                 return NULL;
    403         }
    404 
    405         return db_ctx->fetch_locked(
    406                 db_ctx, mem_ctx, string_term_tdb_data(trust_keystr(domain)));
    407 }
    408 
    409 /************************************************************************
    410  Routine to get the default secure channel type for trust accounts
    411 ************************************************************************/
    412 
    413 enum netr_SchannelType get_default_sec_channel(void)
    414 {
    415         if (lp_server_role() == ROLE_DOMAIN_BDC ||
    416             lp_server_role() == ROLE_DOMAIN_PDC) {
    417                 return SEC_CHAN_BDC;
    418         } else {
    419                 return SEC_CHAN_WKSTA;
    420         }
    421 }
    422 
    423 /************************************************************************
    424  Routine to get the trust account password for a domain.
    425  This only tries to get the legacy hashed version of the password.
    426  The user of this function must have locked the trust password file using
    427  the above secrets_lock_trust_account_password().
    428 ************************************************************************/
    429 
    430 bool secrets_fetch_trust_account_password_legacy(const char *domain,
    431                                                  uint8 ret_pwd[16],
    432                                                  time_t *pass_last_set_time,
    433                                                  enum netr_SchannelType *channel)
    434 {
    435         struct machine_acct_pass *pass;
    436         size_t size = 0;
    437 
    438         if (!(pass = (struct machine_acct_pass *)secrets_fetch(
    439                       trust_keystr(domain), &size))) {
    440                 DEBUG(5, ("secrets_fetch failed!\n"));
    441                 return False;
    442         }
    443 
    444         if (size != sizeof(*pass)) {
    445                 DEBUG(0, ("secrets were of incorrect size!\n"));
    446                 SAFE_FREE(pass);
    447                 return False;
    448         }
    449 
    450         if (pass_last_set_time) {
    451                 *pass_last_set_time = pass->mod_time;
    452         }
    453         memcpy(ret_pwd, pass->hash, 16);
    454 
    455         if (channel) {
    456                 *channel = get_default_sec_channel();
    457         }
    458 
    459         /* Test if machine password has expired and needs to be changed */
    460         if (lp_machine_password_timeout()) {
    461                 if (pass->mod_time > 0 && time(NULL) > (pass->mod_time +
    462                                 (time_t)lp_machine_password_timeout())) {
    463                         global_machine_password_needs_changing = True;
    464                 }
    465         }
    466 
    467         SAFE_FREE(pass);
    468         return True;
    469 }
    470 
    471 /************************************************************************
    472  Routine to get the trust account password for a domain.
    473  The user of this function must have locked the trust password file using
    474  the above secrets_lock_trust_account_password().
    475 ************************************************************************/
    476 
    477 bool secrets_fetch_trust_account_password(const char *domain, uint8 ret_pwd[16],
    478                                           time_t *pass_last_set_time,
    479                                           enum netr_SchannelType *channel)
    480 {
    481         char *plaintext;
    482 
    483         plaintext = secrets_fetch_machine_password(domain, pass_last_set_time,
    484                                                    channel);
    485         if (plaintext) {
    486                 DEBUG(4,("Using cleartext machine password\n"));
    487                 E_md4hash(plaintext, ret_pwd);
    488                 SAFE_FREE(plaintext);
    489                 return True;
    490         }
    491 
    492         return secrets_fetch_trust_account_password_legacy(domain, ret_pwd,
    493                                                            pass_last_set_time,
    494                                                            channel);
    495 }
    496 
    497 /************************************************************************
    498194 Routine to get account password to trusted domain
    499195************************************************************************/
    500196
    501197bool secrets_fetch_trusted_domain_password(const char *domain, char** pwd,
    502                                            DOM_SID *sid, time_t *pass_last_set_time)
     198                                           struct dom_sid *sid, time_t *pass_last_set_time)
    503199{
    504200        struct TRUSTED_DOM_PASS pass;
     
    516212
    517213        /* unpack trusted domain password */
    518         ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), NULL, &pass,
     214        ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &pass,
    519215                        (ndr_pull_flags_fn_t)ndr_pull_TRUSTED_DOM_PASS);
     216
     217        SAFE_FREE(blob.data);
     218
    520219        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    521220                return false;
    522221        }
    523222
    524         SAFE_FREE(blob.data);
    525223
    526224        /* the trust's password */
     
    552250
    553251bool secrets_store_trusted_domain_password(const char* domain, const char* pwd,
    554                                            const DOM_SID *sid)
     252                                           const struct dom_sid *sid)
    555253{
    556254        bool ret;
     
    575273        sid_copy(&pass.domain_sid, sid);
    576274
    577         ndr_err = ndr_push_struct_blob(&blob, talloc_tos(), NULL, &pass,
     275        ndr_err = ndr_push_struct_blob(&blob, talloc_tos(), &pass,
    578276                        (ndr_push_flags_fn_t)ndr_push_TRUSTED_DOM_PASS);
    579277        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    584282
    585283        data_blob_free(&blob);
    586 
    587         return ret;
    588 }
    589 
    590 /************************************************************************
    591  Routine to delete the old plaintext machine account password if any
    592 ************************************************************************/
    593 
    594 static bool secrets_delete_prev_machine_password(const char *domain)
    595 {
    596         char *oldpass = (char *)secrets_fetch(machine_prev_password_keystr(domain), NULL);
    597         if (oldpass == NULL) {
    598                 return true;
    599         }
    600         SAFE_FREE(oldpass);
    601         return secrets_delete(machine_prev_password_keystr(domain));
    602 }
    603 
    604 /************************************************************************
    605  Routine to delete the plaintext machine account password and old
    606  password if any
    607 ************************************************************************/
    608 
    609 bool secrets_delete_machine_password(const char *domain)
    610 {
    611         if (!secrets_delete_prev_machine_password(domain)) {
    612                 return false;
    613         }
    614         return secrets_delete(machine_password_keystr(domain));
    615 }
    616 
    617 /************************************************************************
    618  Routine to delete the plaintext machine account password, old password,
    619  sec channel type and last change time from secrets database
    620 ************************************************************************/
    621 
    622 bool secrets_delete_machine_password_ex(const char *domain)
    623 {
    624         if (!secrets_delete_prev_machine_password(domain)) {
    625                 return false;
    626         }
    627         if (!secrets_delete(machine_password_keystr(domain))) {
    628                 return false;
    629         }
    630         if (!secrets_delete(machine_sec_channel_type_keystr(domain))) {
    631                 return false;
    632         }
    633         return secrets_delete(machine_last_change_time_keystr(domain));
    634 }
    635 
    636 /************************************************************************
    637  Routine to delete the domain sid
    638 ************************************************************************/
    639 
    640 bool secrets_delete_domain_sid(const char *domain)
    641 {
    642         return secrets_delete(domain_sid_keystr(domain));
    643 }
    644 
    645 /************************************************************************
    646  Routine to store the previous machine password (by storing the current password
    647  as the old)
    648 ************************************************************************/
    649 
    650 static bool secrets_store_prev_machine_password(const char *domain)
    651 {
    652         char *oldpass;
    653         bool ret;
    654 
    655         oldpass = (char *)secrets_fetch(machine_password_keystr(domain), NULL);
    656         if (oldpass == NULL) {
    657                 return true;
    658         }
    659         ret = secrets_store(machine_prev_password_keystr(domain), oldpass, strlen(oldpass)+1);
    660         SAFE_FREE(oldpass);
    661         return ret;
    662 }
    663 
    664 /************************************************************************
    665  Routine to set the plaintext machine account password for a realm
    666  the password is assumed to be a null terminated ascii string.
    667  Before storing
    668 ************************************************************************/
    669 
    670 bool secrets_store_machine_password(const char *pass, const char *domain,
    671                                     enum netr_SchannelType sec_channel)
    672 {
    673         bool ret;
    674         uint32 last_change_time;
    675         uint32 sec_channel_type;
    676 
    677         if (!secrets_store_prev_machine_password(domain)) {
    678                 return false;
    679         }
    680 
    681         ret = secrets_store(machine_password_keystr(domain), pass, strlen(pass)+1);
    682         if (!ret)
    683                 return ret;
    684 
    685         SIVAL(&last_change_time, 0, time(NULL));
    686         ret = secrets_store(machine_last_change_time_keystr(domain), &last_change_time, sizeof(last_change_time));
    687 
    688         SIVAL(&sec_channel_type, 0, sec_channel);
    689         ret = secrets_store(machine_sec_channel_type_keystr(domain), &sec_channel_type, sizeof(sec_channel_type));
    690 
    691         return ret;
    692 }
    693 
    694 
    695 /************************************************************************
    696  Routine to fetch the previous plaintext machine account password for a realm
    697  the password is assumed to be a null terminated ascii string.
    698 ************************************************************************/
    699 
    700 char *secrets_fetch_prev_machine_password(const char *domain)
    701 {
    702         return (char *)secrets_fetch(machine_prev_password_keystr(domain), NULL);
    703 }
    704 
    705 /************************************************************************
    706  Routine to fetch the plaintext machine account password for a realm
    707  the password is assumed to be a null terminated ascii string.
    708 ************************************************************************/
    709 
    710 char *secrets_fetch_machine_password(const char *domain,
    711                                      time_t *pass_last_set_time,
    712                                      enum netr_SchannelType *channel)
    713 {
    714         char *ret;
    715         ret = (char *)secrets_fetch(machine_password_keystr(domain), NULL);
    716 
    717         if (pass_last_set_time) {
    718                 size_t size;
    719                 uint32 *last_set_time;
    720                 last_set_time = (unsigned int *)secrets_fetch(machine_last_change_time_keystr(domain), &size);
    721                 if (last_set_time) {
    722                         *pass_last_set_time = IVAL(last_set_time,0);
    723                         SAFE_FREE(last_set_time);
    724                 } else {
    725                         *pass_last_set_time = 0;
    726                 }
    727         }
    728 
    729         if (channel) {
    730                 size_t size;
    731                 uint32 *channel_type;
    732                 channel_type = (unsigned int *)secrets_fetch(machine_sec_channel_type_keystr(domain), &size);
    733                 if (channel_type) {
    734                         *channel = IVAL(channel_type,0);
    735                         SAFE_FREE(channel_type);
    736                 } else {
    737                         *channel = get_default_sec_channel();
    738                 }
    739         }
    740284
    741285        return ret;
     
    863407        blob = data_blob_const(rec->value.dptr, rec->value.dsize);
    864408
    865         ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), NULL, &pass,
     409        ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &pass,
    866410                        (ndr_pull_flags_fn_t)ndr_pull_TRUSTED_DOM_PASS);
    867411        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    905449        struct list_trusted_domains_state state;
    906450
    907         secrets_init();
    908 
    909         if (db_ctx == NULL) {
     451        if (!secrets_init()) {
    910452                return NT_STATUS_ACCESS_DENIED;
    911453        }
     
    1064606
    1065607        if (( ! owner) || ( ! key)) {
    1066                 DEBUG(1, ("Invalid Paramters"));
     608                DEBUG(1, ("Invalid Parameters"));
    1067609                return NULL;
    1068610        }
Note: See TracChangeset for help on using the changeset viewer.