diff options
author | Christian Ambach <ambi@samba.org> | 2011-10-20 18:39:30 +0200 |
---|---|---|
committer | Christian Ambach <ambi@samba.org> | 2011-10-21 16:30:56 +0200 |
commit | 0a85d1c8916a953edd00235f0701ab7d52868de7 (patch) | |
tree | 531f63e22e80093aec6d187188ec2c2b31b35251 /source3/winbindd | |
parent | 8d9aea2a66f83f109aba9e2fc2106c0b3fc4bf88 (diff) | |
download | samba-0a85d1c8916a953edd00235f0701ab7d52868de7.tar.gz samba-0a85d1c8916a953edd00235f0701ab7d52868de7.tar.bz2 samba-0a85d1c8916a953edd00235f0701ab7d52868de7.zip |
s3:idmap_autorid: move HWM initialization into a function
we will need some more HWM soon, so move out initialization and
optimize the logic using the new interface of dbwrap_fetch_uint32
Diffstat (limited to 'source3/winbindd')
-rw-r--r-- | source3/winbindd/idmap_autorid.c | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/source3/winbindd/idmap_autorid.c b/source3/winbindd/idmap_autorid.c index 45a9d353fb..503f8748b7 100644 --- a/source3/winbindd/idmap_autorid.c +++ b/source3/winbindd/idmap_autorid.c @@ -330,12 +330,35 @@ static NTSTATUS idmap_autorid_sids_to_unixids(struct idmap_domain *dom, } +/* initialize the given HWM to 0 if it does not exist yet */ +static NTSTATUS idmap_autorid_init_hwm(const char *hwm) { + + NTSTATUS status; + uint32_t hwmval; + + status = dbwrap_fetch_uint32(autorid_db, hwm, &hwmval); + if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) { + status = dbwrap_trans_store_int32(autorid_db, hwm, 0); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, + ("Unable to initialise HWM (%s) in autorid " + "database: %s\n", hwm, nt_errstr(status))); + return NT_STATUS_INTERNAL_DB_ERROR; + } + } else if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("unable to fetch HWM (%s) from autorid " + "database: %s\n", hwm, nt_errstr(status))); + return status; + } + + return NT_STATUS_OK; +} + /* * open and initialize the database which stores the ranges for the domains */ static NTSTATUS idmap_autorid_db_init(void) { - int32_t hwm; NTSTATUS status; if (autorid_db) { @@ -354,22 +377,9 @@ static NTSTATUS idmap_autorid_db_init(void) } /* Initialize high water mark for the currently used range to 0 */ - status = dbwrap_fetch_int32(autorid_db, HWM, &hwm); - if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND) || - (NT_STATUS_IS_OK(status) && (hwm < 0))) - { - status = dbwrap_trans_store_int32(autorid_db, HWM, 0); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, - ("Unable to initialise HWM in autorid " - "database: %s\n", nt_errstr(status))); - return NT_STATUS_INTERNAL_DB_ERROR; - } - } else if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("unable to fetch HWM from autorid database: %s\n", - nt_errstr(status))); - return status; - } + + status = idmap_autorid_init_hwm(HWM); + NT_STATUS_NOT_OK_RETURN(status); return NT_STATUS_OK; } |