static struct db_context *db_sam;
static char *tdbsam_filename;
+static bool map_builtin;
struct tdbsam_convert_state {
int32_t from;
switch (state->from) {
case 0:
ret = init_samu_from_buffer(user, SAMU_BUFFER_V0,
- (uint8 *)value.dptr,
+ (uint8_t *)value.dptr,
value.dsize);
break;
case 1:
ret = init_samu_from_buffer(user, SAMU_BUFFER_V1,
- (uint8 *)value.dptr,
+ (uint8_t *)value.dptr,
value.dsize);
break;
case 2:
ret = init_samu_from_buffer(user, SAMU_BUFFER_V2,
- (uint8 *)value.dptr,
+ (uint8_t *)value.dptr,
value.dsize);
break;
case 3:
ret = init_samu_from_buffer(user, SAMU_BUFFER_V3,
- (uint8 *)value.dptr,
+ (uint8_t *)value.dptr,
value.dsize);
break;
case 4:
ret = init_samu_from_buffer(user, SAMU_BUFFER_V4,
- (uint8 *)value.dptr,
+ (uint8_t *)value.dptr,
value.dsize);
break;
default:
tmp_db = db_open(NULL, tmp_fname, 0,
TDB_DEFAULT, O_CREAT|O_RDWR, 0600,
- DBWRAP_LOCK_ORDER_1);
+ DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
if (tmp_db == NULL) {
DEBUG(0, ("tdbsam_convert_backup: Failed to create backup TDB passwd "
"[%s]\n", tmp_fname));
orig_db = db_open(NULL, dbname, 0,
TDB_DEFAULT, O_CREAT|O_RDWR, 0600,
- DBWRAP_LOCK_ORDER_1);
+ DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
if (orig_db == NULL) {
DEBUG(0, ("tdbsam_convert_backup: Failed to re-open "
"converted passdb TDB [%s]\n", dbname));
static bool tdbsam_upgrade_next_rid(struct db_context *db)
{
TDB_CONTEXT *tdb;
- uint32 rid;
+ uint32_t rid;
bool ok = false;
NTSTATUS status;
+ char *db_path;
status = dbwrap_fetch_uint32_bystring(db, NEXT_RID_STRING, &rid);
if (NT_STATUS_IS_OK(status)) {
return true;
}
- tdb = tdb_open_log(state_path("winbindd_idmap.tdb"), 0,
- TDB_DEFAULT, O_RDONLY, 0644);
+ db_path = state_path(talloc_tos(), "winbindd_idmap.tdb");
+ if (db_path == NULL) {
+ return false;
+ }
+ tdb = tdb_open_log(db_path, 0,
+ TDB_DEFAULT, O_RDONLY, 0644);
+ TALLOC_FREE(db_path);
if (tdb) {
ok = tdb_fetch_uint32(tdb, "RID_COUNTER", &rid);
if (!ok) {
rid = BASE_RID;
}
- status = dbwrap_store_uint32(db, NEXT_RID_STRING, rid);
+ status = dbwrap_store_uint32_bystring(db, NEXT_RID_STRING, rid);
if (!NT_STATUS_IS_OK(status)) {
return false;
}
return true;
}
-static bool tdbsam_convert(struct db_context **pp_db, const char *name, int32 from)
+static bool tdbsam_convert(struct db_context **pp_db, const char *name, int32_t from)
{
struct tdbsam_convert_state state;
struct db_context *db = NULL;
static bool tdbsam_open( const char *name )
{
- int32 version;
- int32 minor_version;
+ int32_t version;
+ int32_t minor_version;
NTSTATUS status;
/* check if we are already open */
/* Try to open tdb passwd. Create a new one if necessary */
db_sam = db_open(NULL, name, 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0600,
- DBWRAP_LOCK_ORDER_1);
+ DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
if (db_sam == NULL) {
DEBUG(0, ("tdbsam_open: Failed to open/create TDB passwd "
"[%s]\n", name));
/* Data is stored in all lower-case */
fstrcpy(name, sname);
- strlower_m(name);
+ if (!strlower_m(name)) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
/* set search key */
- slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
+ fstr_sprintf(keystr, "%s%s", USERPREFIX, name);
/* open the database */
return NT_STATUS_NO_SUCH_USER;
}
+ if (data.dsize == 0) {
+ DEBUG(5, ("%s: Got 0-sized record for key %s\n", __func__,
+ keystr));
+ return NT_STATUS_NO_SUCH_USER;
+ }
+
/* unpack the buffer */
if (!init_samu_from_buffer(user, SAMU_BUFFER_LATEST, data.dptr, data.dsize)) {
DEBUG(0,("pdb_getsampwent: Bad struct samu entry returned from TDB!\n"));
- SAFE_FREE(data.dptr);
+ TALLOC_FREE(data.dptr);
return NT_STATUS_NO_MEMORY;
}
**************************************************************************/
static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods,
- struct samu *user, uint32 rid)
+ struct samu *user, uint32_t rid)
{
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
TDB_DATA data;
/* set search key */
- slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid);
+ fstr_sprintf(keystr, "%s%.8x", RIDPREFIX, rid);
/* open the database */
static NTSTATUS tdbsam_getsampwsid(struct pdb_methods *my_methods,
struct samu * user, const struct dom_sid *sid)
{
- uint32 rid;
+ uint32_t rid;
if ( !sid_peek_check_rid(get_global_sam_sid(), sid, &rid) )
return NT_STATUS_UNSUCCESSFUL;
NTSTATUS status;
fstrcpy(name, pdb_get_username(sam_pass));
- strlower_m(name);
+ if (!strlower_m(name)) {
+ return false;
+ }
/* set the search key */
- slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
+ fstr_sprintf(keystr, "%s%s", USERPREFIX, name);
/* it's outaa here! 8^) */
if ( !tdbsam_open( tdbsam_filename ) ) {
{
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
fstring keystr;
- uint32 rid;
+ uint32_t rid;
fstring name;
/* open the database */
}
fstrcpy(name, pdb_get_username(sam_pass));
- strlower_m(name);
+ if (!strlower_m(name)) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
/* set the search key */
- slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
+ fstr_sprintf(keystr, "%s%s", USERPREFIX, name);
rid = pdb_get_user_rid(sam_pass);
/* set the search key */
- slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX, rid);
+ fstr_sprintf(keystr, "%s%.8x", RIDPREFIX, rid);
/* it's outaa here! 8^) */
static bool tdb_update_samacct_only( struct samu* newpwd, int flag )
{
TDB_DATA data;
- uint8 *buf = NULL;
+ uint8_t *buf = NULL;
fstring keystr;
fstring name;
bool ret = false;
data.dptr = buf;
fstrcpy(name, pdb_get_username(newpwd));
- strlower_m(name);
+ if (!strlower_m(name)) {
+ goto done;
+ }
DEBUG(5, ("Storing %saccount %s with RID %d\n",
flag == TDB_INSERT ? "(new) " : "", name,
pdb_get_user_rid(newpwd)));
/* setup the USER index key */
- slprintf(keystr, sizeof(keystr)-1, "%s%s", USERPREFIX, name);
+ fstr_sprintf(keystr, "%s%s", USERPREFIX, name);
/* add the account */
NTSTATUS status;
fstrcpy(name, pdb_get_username(newpwd));
- strlower_m(name);
+ if (!strlower_m(name)) {
+ return false;
+ }
/* setup RID data */
data = string_term_tdb_data(name);
/* setup the RID index key */
- slprintf(keystr, sizeof(keystr)-1, "%s%.8x", RIDPREFIX,
- pdb_get_user_rid(newpwd));
+ fstr_sprintf(keystr, "%s%.8x", RIDPREFIX, pdb_get_user_rid(newpwd));
/* add the reference */
status = dbwrap_store_bystring(db_sam, keystr, data, flag);
/* Delete old RID key */
DEBUG(10, ("tdb_update_sam: Deleting key for RID %u\n", oldrid));
- slprintf(keystr, sizeof(keystr) - 1, "%s%.8x", RIDPREFIX, oldrid);
+ fstr_sprintf(keystr, "%s%.8x", RIDPREFIX, oldrid);
if (!NT_STATUS_IS_OK(dbwrap_delete_bystring(db_sam, keystr))) {
DEBUG(0, ("tdb_update_sam: Can't delete %s\n", keystr));
goto cancel;
return NT_STATUS_NO_MEMORY;
}
- rename_script = talloc_strdup(new_acct, lp_renameuser_script());
+ rename_script = lp_rename_user_script(new_acct);
if (!rename_script) {
TALLOC_FREE(new_acct);
return NT_STATUS_NO_MEMORY;
so that we lower case the posix name but preserve the case in passdb */
fstrcpy( oldname_lower, pdb_get_username(old_acct) );
- strlower_m( oldname_lower );
+ if (!strlower_m( oldname_lower )) {
+ goto cancel;
+ }
fstrcpy( newname_lower, newname );
- strlower_m( newname_lower );
+ if (!strlower_m( newname_lower )) {
+ goto cancel;
+ }
rename_script = talloc_string_sub2(new_acct,
rename_script,
if (!rename_script) {
goto cancel;
}
- rename_ret = smbrun(rename_script, NULL);
+ rename_ret = smbrun(rename_script, NULL, NULL);
DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n",
rename_script, rename_ret));
return PDB_CAP_STORE_RIDS;
}
-static bool tdbsam_new_rid(struct pdb_methods *methods, uint32 *prid)
+static bool tdbsam_new_rid(struct pdb_methods *methods, uint32_t *prid)
{
- uint32 rid;
+ uint32_t rid;
NTSTATUS status;
rid = BASE_RID; /* Default if not set */
return false;
}
- status = dbwrap_trans_change_uint32_atomic(db_sam, NEXT_RID_STRING,
- &rid, 1);
+ status = dbwrap_trans_change_uint32_atomic_bystring(
+ db_sam, NEXT_RID_STRING, &rid, 1);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("tdbsam_new_rid: Failed to increase %s: %s\n",
NEXT_RID_STRING, nt_errstr(status)));
struct tdbsam_search_state *state = talloc_get_type_abort(
private_data, struct tdbsam_search_state);
size_t prefixlen = strlen(RIDPREFIX);
- uint32 rid;
+ uint32_t rid;
TDB_DATA key;
key = dbwrap_record_get_key(rec);
rid = strtoul((char *)key.dptr+prefixlen, NULL, 16);
- ADD_TO_LARGE_ARRAY(state, uint32, rid, &state->rids, &state->num_rids,
+ ADD_TO_LARGE_ARRAY(state, uint32_t, rid, &state->rids, &state->num_rids,
&state->array_size);
return 0;
}
if (state->current == state->num_rids) {
+ TALLOC_FREE(user);
return false;
}
static bool tdbsam_search_users(struct pdb_methods *methods,
struct pdb_search *search,
- uint32 acct_flags)
+ uint32_t acct_flags)
{
struct tdbsam_search_state *state;
return true;
}
+static bool tdbsam_is_responsible_for_builtin(struct pdb_methods *m)
+{
+ return map_builtin;
+}
+
/*********************************************************************
Initialize the tdb sam backend. Setup the dispath table of methods,
open the tdb, etc...
(*pdb_method)->capabilities = tdbsam_capabilities;
(*pdb_method)->new_rid = tdbsam_new_rid;
+ (*pdb_method)->is_responsible_for_builtin =
+ tdbsam_is_responsible_for_builtin;
+ map_builtin = lp_parm_bool(-1, "tdbsam", "map builtin", true);
+
/* save the path for later */
if (!location) {
return NT_STATUS_OK;
}
-NTSTATUS pdb_tdbsam_init(void)
+NTSTATUS pdb_tdbsam_init(TALLOC_CTX *ctx)
{
return smb_register_passdb(PASSDB_INTERFACE_VERSION, "tdbsam", pdb_init_tdbsam);
}