summaryrefslogtreecommitdiff
path: root/source3/winbindd
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2009-02-09 16:51:46 +0100
committerJelmer Vernooij <jelmer@samba.org>2009-02-09 16:51:46 +0100
commit9b366d703210b493aa1389bbdd288a2b00958766 (patch)
tree12acaf89af2c6bd2610018d267e2d8030d9b4bd6 /source3/winbindd
parent6d139ca4680abcbda5110f2f0886aa038ff62088 (diff)
parent1dadf17be847e3f93b72988bcc7e8620a8d5908c (diff)
downloadsamba-9b366d703210b493aa1389bbdd288a2b00958766.tar.gz
samba-9b366d703210b493aa1389bbdd288a2b00958766.tar.bz2
samba-9b366d703210b493aa1389bbdd288a2b00958766.zip
Merge branch 'master' of ssh://git.samba.org/data/git/samba
Diffstat (limited to 'source3/winbindd')
-rw-r--r--source3/winbindd/idmap_tdb.c91
-rw-r--r--source3/winbindd/idmap_tdb2.c90
-rw-r--r--source3/winbindd/winbindd_proto.h21
-rw-r--r--source3/winbindd/winbindd_user.c7
4 files changed, 112 insertions, 97 deletions
diff --git a/source3/winbindd/idmap_tdb.c b/source3/winbindd/idmap_tdb.c
index 481ac1b9ad..3a64979f33 100644
--- a/source3/winbindd/idmap_tdb.c
+++ b/source3/winbindd/idmap_tdb.c
@@ -203,29 +203,21 @@ static bool idmap_tdb_upgrade(struct db_context *db)
return True;
}
-static NTSTATUS idmap_tdb_open_db(TALLOC_CTX *memctx,
- bool check_config,
- struct db_context **dbctx)
+static NTSTATUS idmap_tdb_load_ranges(void)
{
- NTSTATUS ret;
- TALLOC_CTX *ctx;
- char *tdbfile = NULL;
- struct db_context *db = NULL;
- int32_t version;
uid_t low_uid = 0;
uid_t high_uid = 0;
gid_t low_gid = 0;
gid_t high_gid = 0;
- bool config_error = false;
- /* load ranges */
- if (!lp_idmap_uid(&low_uid, &high_uid)
- || !lp_idmap_gid(&low_gid, &high_gid)) {
- DEBUG(1, ("idmap uid or idmap gid missing\n"));
- config_error = true;
- if (check_config) {
- return NT_STATUS_UNSUCCESSFUL;
- }
+ if (!lp_idmap_uid(&low_uid, &high_uid)) {
+ DEBUG(1, ("idmap uid missing\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ if (!lp_idmap_gid(&low_gid, &high_gid)) {
+ DEBUG(1, ("idmap gid missing\n"));
+ return NT_STATUS_UNSUCCESSFUL;
}
idmap_tdb_state.low_uid = low_uid;
@@ -235,29 +227,41 @@ static NTSTATUS idmap_tdb_open_db(TALLOC_CTX *memctx,
if (idmap_tdb_state.high_uid <= idmap_tdb_state.low_uid) {
DEBUG(1, ("idmap uid range missing or invalid\n"));
- config_error = true;
- if (check_config) {
- return NT_STATUS_UNSUCCESSFUL;
- }
+ return NT_STATUS_UNSUCCESSFUL;
}
if (idmap_tdb_state.high_gid <= idmap_tdb_state.low_gid) {
DEBUG(1, ("idmap gid range missing or invalid\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static NTSTATUS idmap_tdb_open_db(TALLOC_CTX *memctx,
+ bool check_config,
+ struct db_context **dbctx)
+{
+ NTSTATUS ret;
+ TALLOC_CTX *ctx;
+ char *tdbfile = NULL;
+ struct db_context *db = NULL;
+ int32_t version;
+ bool config_error = false;
+
+ ret = idmap_tdb_load_ranges();
+ if (!NT_STATUS_IS_OK(ret)) {
config_error = true;
if (check_config) {
- return NT_STATUS_UNSUCCESSFUL;
+ return ret;
}
}
/* use our own context here */
- ctx = talloc_new(memctx);
- if (!ctx) {
- DEBUG(0, ("Out of memory!\n"));
- return NT_STATUS_NO_MEMORY;
- }
+ ctx = talloc_stackframe();
/* use the old database if present */
- tdbfile = talloc_strdup(ctx, state_path("winbindd_idmap.tdb"));
+ tdbfile = state_path("winbindd_idmap.tdb");
if (!tdbfile) {
DEBUG(0, ("Out of memory!\n"));
ret = NT_STATUS_NO_MEMORY;
@@ -402,6 +406,7 @@ static NTSTATUS idmap_tdb_allocate_id(struct unixid *xid)
const char *hwmtype;
uint32_t high_hwm;
uint32_t hwm;
+ int res;
/* Get current high water mark */
switch (xid->type) {
@@ -423,7 +428,14 @@ static NTSTATUS idmap_tdb_allocate_id(struct unixid *xid)
return NT_STATUS_INVALID_PARAMETER;
}
+ res = idmap_alloc_db->transaction_start(idmap_alloc_db);
+ if (res != 0) {
+ DEBUG(1, (__location__ " Failed to start transaction.\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
if ((hwm = dbwrap_fetch_int32(idmap_alloc_db, hwmkey)) == -1) {
+ idmap_alloc_db->transaction_cancel(idmap_alloc_db);
return NT_STATUS_INTERNAL_DB_ERROR;
}
@@ -431,6 +443,7 @@ static NTSTATUS idmap_tdb_allocate_id(struct unixid *xid)
if (hwm > high_hwm) {
DEBUG(1, ("Fatal Error: %s range full!! (max: %lu)\n",
hwmtype, (unsigned long)high_hwm));
+ idmap_alloc_db->transaction_cancel(idmap_alloc_db);
return NT_STATUS_UNSUCCESSFUL;
}
@@ -438,6 +451,7 @@ static NTSTATUS idmap_tdb_allocate_id(struct unixid *xid)
ret = dbwrap_change_uint32_atomic(idmap_alloc_db, hwmkey, &hwm, 1);
if (ret != 0) {
DEBUG(0, ("Fatal error while fetching a new %s value\n!", hwmtype));
+ idmap_alloc_db->transaction_cancel(idmap_alloc_db);
return NT_STATUS_UNSUCCESSFUL;
}
@@ -445,9 +459,16 @@ static NTSTATUS idmap_tdb_allocate_id(struct unixid *xid)
if (hwm > high_hwm) {
DEBUG(1, ("Fatal Error: %s range full!! (max: %lu)\n",
hwmtype, (unsigned long)high_hwm));
+ idmap_alloc_db->transaction_cancel(idmap_alloc_db);
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ res = idmap_alloc_db->transaction_commit(idmap_alloc_db);
+ if (res != 0) {
+ DEBUG(1, (__location__ " Failed to commit transaction.\n"));
return NT_STATUS_UNSUCCESSFUL;
}
-
+
xid->id = hwm;
DEBUG(10,("New %s = %d\n", hwmtype, hwm));
@@ -694,10 +715,10 @@ static NTSTATUS idmap_tdb_sid_to_id(struct idmap_tdb_context *ctx, struct id_map
TDB_DATA data;
char *keystr;
unsigned long rec_id = 0;
- fstring tmp;
+ TALLOC_CTX *tmp_ctx = talloc_stackframe();
- if ((keystr = talloc_asprintf(
- ctx, "%s", sid_to_fstring(tmp, map->sid))) == NULL) {
+ keystr = sid_string_talloc(tmp_ctx, map->sid);
+ if (keystr == NULL) {
DEBUG(0, ("Out of memory!\n"));
ret = NT_STATUS_NO_MEMORY;
goto done;
@@ -706,7 +727,7 @@ static NTSTATUS idmap_tdb_sid_to_id(struct idmap_tdb_context *ctx, struct id_map
DEBUG(10,("Fetching record %s\n", keystr));
/* Check if sid is present in database */
- data = dbwrap_fetch_bystring(ctx->db, NULL, keystr);
+ data = dbwrap_fetch_bystring(ctx->db, tmp_ctx, keystr);
if (!data.dptr) {
DEBUG(10,("Record %s not found\n", keystr));
ret = NT_STATUS_NONE_MAPPED;
@@ -730,8 +751,6 @@ static NTSTATUS idmap_tdb_sid_to_id(struct idmap_tdb_context *ctx, struct id_map
DEBUG(2, ("Found INVALID record %s -> %s\n", keystr, (const char *)data.dptr));
ret = NT_STATUS_INTERNAL_DB_ERROR;
}
-
- TALLOC_FREE(data.dptr);
/* apply filters before returning result */
if ((ctx->filter_low_id && (map->xid.id < ctx->filter_low_id)) ||
@@ -742,7 +761,7 @@ static NTSTATUS idmap_tdb_sid_to_id(struct idmap_tdb_context *ctx, struct id_map
}
done:
- talloc_free(keystr);
+ talloc_free(tmp_ctx);
return ret;
}
diff --git a/source3/winbindd/idmap_tdb2.c b/source3/winbindd/idmap_tdb2.c
index 8bde963c60..fb90dd097e 100644
--- a/source3/winbindd/idmap_tdb2.c
+++ b/source3/winbindd/idmap_tdb2.c
@@ -54,6 +54,43 @@ static struct db_context *idmap_tdb2;
static NTSTATUS idmap_tdb2_alloc_load(void);
+static NTSTATUS idmap_tdb2_load_ranges(void)
+{
+ uid_t low_uid = 0;
+ uid_t high_uid = 0;
+ gid_t low_gid = 0;
+ gid_t high_gid = 0;
+
+ if (!lp_idmap_uid(&low_uid, &high_uid)) {
+ DEBUG(1, ("idmap uid missing\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ if (!lp_idmap_gid(&low_gid, &high_gid)) {
+ DEBUG(1, ("idmap gid missing\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ idmap_tdb2_state.low_uid = low_uid;
+ idmap_tdb2_state.high_uid = high_uid;
+ idmap_tdb2_state.low_gid = low_gid;
+ idmap_tdb2_state.high_gid = high_gid;
+
+ if (idmap_tdb2_state.high_uid <= idmap_tdb2_state.low_uid) {
+ DEBUG(1, ("idmap uid range missing or invalid\n"));
+ DEBUGADD(1, ("idmap will be unable to map foreign SIDs\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ if (idmap_tdb2_state.high_gid <= idmap_tdb2_state.low_gid) {
+ DEBUG(1, ("idmap gid range missing or invalid\n"));
+ DEBUGADD(1, ("idmap will be unable to map foreign SIDs\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ return NT_STATUS_OK;
+}
+
/*
open the permanent tdb
*/
@@ -94,10 +131,7 @@ static NTSTATUS idmap_tdb2_open_db(void)
*/
static NTSTATUS idmap_tdb2_alloc_load(void)
{
- uid_t low_uid = 0;
- uid_t high_uid = 0;
- gid_t low_gid = 0;
- gid_t high_gid = 0;
+ NTSTATUS status;
uint32 low_id;
/* see if a idmap script is configured */
@@ -111,27 +145,15 @@ static NTSTATUS idmap_tdb2_alloc_load(void)
/* load ranges */
- /* Create high water marks for group and user id */
- if (!lp_idmap_uid(&low_uid, &high_uid)
- || !lp_idmap_gid(&low_gid, &high_gid)) {
- DEBUG(1, ("idmap uid or idmap gid missing\n"));
- return NT_STATUS_UNSUCCESSFUL;
+ status = idmap_tdb2_load_ranges();
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
}
- idmap_tdb2_state.low_uid = low_uid;
- idmap_tdb2_state.high_uid = high_uid;
- idmap_tdb2_state.low_gid = low_gid;
- idmap_tdb2_state.high_gid = high_gid;
-
- if (idmap_tdb2_state.high_uid <= idmap_tdb2_state.low_uid) {
- DEBUG(1, ("idmap uid range missing or invalid\n"));
- DEBUGADD(1, ("idmap will be unable to map foreign SIDs\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
+ /* Create high water marks for group and user id */
- if (((low_id = dbwrap_fetch_int32(idmap_tdb2,
- HWM_USER)) == -1) ||
- (low_id < idmap_tdb2_state.low_uid)) {
+ low_id = dbwrap_fetch_int32(idmap_tdb2, HWM_USER);
+ if ((low_id == -1) || (low_id < idmap_tdb2_state.low_uid)) {
if (!NT_STATUS_IS_OK(dbwrap_trans_store_int32(
idmap_tdb2, HWM_USER,
idmap_tdb2_state.low_uid))) {
@@ -141,15 +163,8 @@ static NTSTATUS idmap_tdb2_alloc_load(void)
}
}
- if (idmap_tdb2_state.high_gid <= idmap_tdb2_state.low_gid) {
- DEBUG(1, ("idmap gid range missing or invalid\n"));
- DEBUGADD(1, ("idmap will be unable to map foreign SIDs\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- if (((low_id = dbwrap_fetch_int32(idmap_tdb2,
- HWM_GROUP)) == -1) ||
- (low_id < idmap_tdb2_state.low_gid)) {
+ low_id = dbwrap_fetch_int32(idmap_tdb2, HWM_GROUP);
+ if ((low_id == -1) || (low_id < idmap_tdb2_state.low_gid)) {
if (!NT_STATUS_IS_OK(dbwrap_trans_store_int32(
idmap_tdb2, HWM_GROUP,
idmap_tdb2_state.low_gid))) {
@@ -557,12 +572,13 @@ static NTSTATUS idmap_tdb2_sid_to_id(struct idmap_tdb2_context *ctx, struct id_m
TDB_DATA data;
char *keystr;
unsigned long rec_id = 0;
- NTSTATUS status;
+ TALLOC_CTX *tmp_ctx = talloc_stackframe();
- status = idmap_tdb2_open_db();
- NT_STATUS_NOT_OK_RETURN(status);
+ ret = idmap_tdb2_open_db();
+ NT_STATUS_NOT_OK_RETURN(ret);
- if ((keystr = sid_string_talloc(ctx, map->sid)) == NULL) {
+ keystr = sid_string_talloc(tmp_ctx, map->sid);
+ if (keystr == NULL) {
DEBUG(0, ("Out of memory!\n"));
ret = NT_STATUS_NO_MEMORY;
goto done;
@@ -571,7 +587,7 @@ static NTSTATUS idmap_tdb2_sid_to_id(struct idmap_tdb2_context *ctx, struct id_m
DEBUG(10,("Fetching record %s\n", keystr));
/* Check if sid is present in database */
- data = dbwrap_fetch_bystring(idmap_tdb2, keystr, keystr);
+ data = dbwrap_fetch_bystring(idmap_tdb2, tmp_ctx, keystr);
if (!data.dptr) {
fstring idstr;
@@ -626,7 +642,7 @@ static NTSTATUS idmap_tdb2_sid_to_id(struct idmap_tdb2_context *ctx, struct id_m
}
done:
- talloc_free(keystr);
+ talloc_free(tmp_ctx);
return ret;
}
diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h
index 977ee9c6b1..c302dd1d62 100644
--- a/source3/winbindd/winbindd_proto.h
+++ b/source3/winbindd/winbindd_proto.h
@@ -67,27 +67,6 @@ bool winbindd_setup_sig_term_handler(bool parent);
bool winbindd_setup_sig_hup_handler(const char *lfile);
int main(int argc, char **argv, char **envp);
-/* The following definitions come from winbindd/winbindd_reqtrans.c */
-
-struct async_req *wb_req_read_send(TALLOC_CTX *mem_ctx,
- struct event_context *ev,
- int fd, size_t max_extra_data);
-NTSTATUS wb_req_read_recv(struct async_req *req, TALLOC_CTX *mem_ctx,
- struct winbindd_request **preq);
-struct async_req *wb_req_write_send(TALLOC_CTX *mem_ctx,
- struct event_context *ev, int fd,
- struct winbindd_request *wb_req);
-NTSTATUS wb_req_write_recv(struct async_req *req);
-
-struct async_req *wb_resp_read_send(TALLOC_CTX *mem_ctx,
- struct event_context *ev, int fd);
-NTSTATUS wb_resp_read_recv(struct async_req *req, TALLOC_CTX *mem_ctx,
- struct winbindd_response **presp);
-struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx,
- struct event_context *ev, int fd,
- struct winbindd_response *wb_resp);
-NTSTATUS wb_resp_write_recv(struct async_req *req);
-
/* The following definitions come from winbindd/winbindd_ads.c */
diff --git a/source3/winbindd/winbindd_user.c b/source3/winbindd/winbindd_user.c
index 62fd4d7f07..8b481f972c 100644
--- a/source3/winbindd/winbindd_user.c
+++ b/source3/winbindd/winbindd_user.c
@@ -80,11 +80,12 @@ static bool winbindd_fill_pwent(TALLOC_CTX *ctx, char *dom_name, char *user_name
if (!pw || !dom_name || !user_name)
return False;
- domain = find_domain_from_name_noinit(dom_name);
+ domain = find_domain_from_name(dom_name);
if (domain == NULL) {
- DEBUG(5,("winbindd_fill_pwent: Failed to find domain for %s. "
- "Disabling name alias support\n", dom_name));
+ DEBUG(5,("winbindd_fill_pwent: Failed to find domain for %s.\n",
+ dom_name));
nt_status = NT_STATUS_NO_SUCH_DOMAIN;
+ return false;
}
/* Resolve the uid number */