static void lazy_initialize_passdb(void)
{
static BOOL initialized = False;
- if(initialized)return;
+ if(initialized) {
+ return;
+ }
static_init_pdb;
initialized = True;
}
if ( pdb && reload ) {
pdb->free_private_data( &(pdb->private_data) );
if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) {
- return NULL;
+ pstring msg;
+ slprintf(msg, sizeof(msg)-1, "pdb_get_methods_reload: failed to get pdb methods for backend %s\n",
+ lp_passdb_backend() );
+ smb_panic(msg);
}
}
if ( !pdb ) {
if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) {
- return NULL;
+ pstring msg;
+ slprintf(msg, sizeof(msg)-1, "pdb_get_methods_reload: failed to get pdb methods for backend %s\n",
+ lp_passdb_backend() );
+ smb_panic(msg);
}
}
BOOL pdb_setsampwent(BOOL update, uint16 acb_mask)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->setsampwent(pdb, update, acb_mask));
}
void pdb_endsampwent(void)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return;
- }
-
pdb->endsampwent(pdb);
}
{
struct pdb_methods *pdb = pdb_get_methods();
- if ( !pdb ) {
- return False;
- }
-
if ( !NT_STATUS_IS_OK(pdb->getsampwent(pdb, user) ) ) {
return False;
}
-
pdb_force_pw_initialization( user );
-
return True;
}
{
struct pdb_methods *pdb = pdb_get_methods();
- if ( !pdb ) {
- return False;
- }
-
if (!NT_STATUS_IS_OK(pdb->getsampwnam(pdb, sam_acct, username))) {
return False;
}
pdb_force_pw_initialization( sam_acct );
- if ( (csamuser = samu_new( NULL )) != NULL ) {
- pdb_copy_sam_account(csamuser, sam_acct);
+ csamuser = samu_new( NULL );
+ if (!csamuser) {
+ return False;
+ }
+
+ if (!pdb_copy_sam_account(csamuser, sam_acct)) {
+ TALLOC_FREE(csamuser);
+ return False;
}
return True;
BOOL pdb_getsampwsid(struct samu *sam_acct, const DOM_SID *sid)
{
- struct pdb_methods *pdb;
+ struct pdb_methods *pdb = pdb_get_methods();
uint32 rid;
- if ( !(pdb = pdb_get_methods()) ) {
- return False;
- }
-
/* hard code the Guest RID of 501 */
if ( !sid_peek_check_rid( get_global_sam_sid(), sid, &rid ) )
if ( !(pwd = Get_Pwnam_alloc(tmp_ctx, name)) ) {
pstring add_script;
int add_ret;
+ fstring name2;
if ((acb_info & ACB_NORMAL) && name[strlen(name)-1] != '$') {
pstrcpy(add_script, lp_adduser_script());
return NT_STATUS_NO_SUCH_USER;
}
- all_string_sub(add_script, "%u", name, sizeof(add_script));
+ /* lowercase the username before creating the Unix account for
+ compatibility with previous Samba releases */
+ fstrcpy( name2, name );
+ strlower_m( name2 );
+ all_string_sub(add_script, "%u", name2, sizeof(add_script));
add_ret = smbrun(add_script,NULL);
DEBUG(add_ret ? 0 : 3, ("_samr_create_user: Running the command `%s' gave %d\n",
add_script, add_ret));
+
+#ifdef ENABLE_BUILD_FARM_HACKS
+ if (add_ret != 0) {
+ DEBUG(1, ("Creating a faked user %s for build farm "
+ "purposes", name));
+ faked_create_user(name);
+ }
+#endif
+
flush_pwnam_cache();
pwd = Get_Pwnam_alloc(tmp_ctx, name);
return NT_STATUS_INTERNAL_ERROR;
}
+ /* Use the username case specified in the original request */
+
+ pdb_set_username( sam_pass, name, PDB_SET );
+
/* Disable the account on creation, it does not have a reasonable password yet. */
acb_info |= ACB_DISABLED;
uint32 *rid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->create_user(pdb, mem_ctx, name, flags, rid);
}
struct samu *sam_acct)
{
NTSTATUS status;
+ fstring username;
status = pdb_delete_sam_account(sam_acct);
if (!NT_STATUS_IS_OK(status)) {
* not necessary present and maybe the sysadmin doesn't want to delete
* the unix side
*/
- smb_delete_user( pdb_get_username(sam_acct) );
+
+ /* always lower case the username before handing it off to
+ external scripts */
+
+ fstrcpy( username, pdb_get_username(sam_acct) );
+ strlower_m( username );
+
+ smb_delete_user( username );
return status;
}
struct pdb_methods *pdb = pdb_get_methods();
uid_t uid = -1;
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* sanity check to make sure we don't delete root */
if ( !sid_to_uid( pdb_get_user_sid(sam_acct), &uid ) ) {
NTSTATUS pdb_add_sam_account(struct samu *sam_acct)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->add_sam_account(pdb, sam_acct);
}
{
struct pdb_methods *pdb = pdb_get_methods();
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
if (csamuser != NULL) {
TALLOC_FREE(csamuser);
csamuser = NULL;
{
struct pdb_methods *pdb = pdb_get_methods();
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
if (csamuser != NULL) {
TALLOC_FREE(csamuser);
csamuser = NULL;
{
struct pdb_methods *pdb = pdb_get_methods();
uid_t uid;
-
- if ( !pdb ) {
- return NT_STATUS_NOT_IMPLEMENTED;
- }
+ NTSTATUS status;
if (csamuser != NULL) {
TALLOC_FREE(csamuser);
return NT_STATUS_ACCESS_DENIED;
}
- return pdb->rename_sam_account(pdb, oldname, newname);
+ status = pdb->rename_sam_account(pdb, oldname, newname);
+
+ /* always flush the cache here just to be safe */
+ flush_pwnam_cache();
+
+ return status;
}
NTSTATUS pdb_update_login_attempts(struct samu *sam_acct, BOOL success)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_NOT_IMPLEMENTED;
- }
-
return pdb->update_login_attempts(pdb, sam_acct, success);
}
BOOL pdb_getgrsid(GROUP_MAP *map, DOM_SID sid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->getgrsid(pdb, map, sid));
}
BOOL pdb_getgrgid(GROUP_MAP *map, gid_t gid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->getgrgid(pdb, map, gid));
}
BOOL pdb_getgrnam(GROUP_MAP *map, const char *name)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->getgrnam(pdb, map, name));
}
uint32 *rid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->create_dom_group(pdb, mem_ctx, name, rid);
}
NTSTATUS pdb_delete_dom_group(TALLOC_CTX *mem_ctx, uint32 rid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->delete_dom_group(pdb, mem_ctx, rid);
}
NTSTATUS pdb_add_group_mapping_entry(GROUP_MAP *map)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->add_group_mapping_entry(pdb, map);
}
NTSTATUS pdb_update_group_mapping_entry(GROUP_MAP *map)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->update_group_mapping_entry(pdb, map);
}
NTSTATUS pdb_delete_group_mapping_entry(DOM_SID sid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->delete_group_mapping_entry(pdb, sid);
}
size_t *p_num_entries, BOOL unix_only)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb-> enum_group_mapping(pdb, sid, sid_name_use,
pp_rmap, p_num_entries, unix_only));
}
struct pdb_methods *pdb = pdb_get_methods();
NTSTATUS result;
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
result = pdb->enum_group_members(pdb, mem_ctx,
sid, pp_member_rids, p_num_members);
size_t *p_num_groups)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->enum_group_memberships(
pdb, mem_ctx, user,
pp_sids, pp_gids, p_num_groups);
NTSTATUS pdb_set_unix_primary_group(TALLOC_CTX *mem_ctx, struct samu *user)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->set_unix_primary_group(pdb, mem_ctx, user);
}
uint32 member_rid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->add_groupmem(pdb, mem_ctx, group_rid, member_rid);
}
uint32 member_rid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->del_groupmem(pdb, mem_ctx, group_rid, member_rid);
}
BOOL pdb_find_alias(const char *name, DOM_SID *sid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->find_alias(pdb, name, sid));
}
NTSTATUS pdb_create_alias(const char *name, uint32 *rid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_NOT_IMPLEMENTED;
- }
-
return pdb->create_alias(pdb, name, rid);
}
BOOL pdb_delete_alias(const DOM_SID *sid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->delete_alias(pdb, sid));
}
BOOL pdb_get_aliasinfo(const DOM_SID *sid, struct acct_info *info)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->get_aliasinfo(pdb, sid, info));
}
BOOL pdb_set_aliasinfo(const DOM_SID *sid, struct acct_info *info)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->set_aliasinfo(pdb, sid, info));
}
NTSTATUS pdb_add_aliasmem(const DOM_SID *alias, const DOM_SID *member)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->add_aliasmem(pdb, alias, member);
}
NTSTATUS pdb_del_aliasmem(const DOM_SID *alias, const DOM_SID *member)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
return pdb->del_aliasmem(pdb, alias, member);
}
DOM_SID **pp_members, size_t *p_num_members)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- return pdb->enum_aliasmem(pdb, alias,
- pp_members, p_num_members);
+ return pdb->enum_aliasmem(pdb, alias, pp_members, p_num_members);
}
NTSTATUS pdb_enum_alias_memberships(TALLOC_CTX *mem_ctx,
size_t *p_num_alias_rids)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_NOT_IMPLEMENTED;
- }
-
return pdb->enum_alias_memberships(pdb, mem_ctx,
domain_sid,
members, num_members,
int num_rids,
uint32 *rids,
const char **names,
- uint32 *attrs)
+ enum SID_NAME_USE *attrs)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_NOT_IMPLEMENTED;
- }
-
- return pdb->lookup_rids(pdb, domain_sid,
- num_rids, rids, names, attrs);
+ return pdb->lookup_rids(pdb, domain_sid, num_rids, rids, names, attrs);
}
NTSTATUS pdb_lookup_names(const DOM_SID *domain_sid,
int num_names,
const char **names,
uint32 *rids,
- uint32 *attrs)
+ enum SID_NAME_USE *attrs)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return NT_STATUS_NOT_IMPLEMENTED;
- }
-
- return pdb->lookup_names(pdb, domain_sid,
- num_names, names, rids, attrs);
+ return pdb->lookup_names(pdb, domain_sid, num_names, names, rids, attrs);
}
BOOL pdb_get_account_policy(int policy_index, uint32 *value)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->get_account_policy(pdb, policy_index, value));
}
BOOL pdb_set_account_policy(int policy_index, uint32 value)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->set_account_policy(pdb, policy_index, value));
}
BOOL pdb_get_seq_num(time_t *seq_num)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return NT_STATUS_IS_OK(pdb->get_seq_num(pdb, seq_num));
}
BOOL pdb_uid_to_rid(uid_t uid, uint32 *rid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return pdb->uid_to_rid(pdb, uid, rid);
}
BOOL pdb_gid_to_sid(gid_t gid, DOM_SID *sid)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return pdb->gid_to_sid(pdb, gid, sid);
}
enum SID_NAME_USE *type)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return pdb->sid_to_id(pdb, sid, id, type);
}
BOOL pdb_rid_algorithm(void)
{
struct pdb_methods *pdb = pdb_get_methods();
-
- if ( !pdb ) {
- return False;
- }
-
return pdb->rid_algorithm(pdb);
}
int i;
TALLOC_CTX *ctx;
- if ( !pdb ) {
- return False;
- }
-
if (pdb_rid_algorithm()) {
DEBUG(0, ("Trying to allocate a RID when algorithmic RIDs "
"are active\n"));
unbecome_root(); /* -----> EXIT BECOME_ROOT() */
*name = talloc_strdup(mem_ctx, pdb_get_username(sam_account));
+ if (!*name) {
+ TALLOC_FREE(sam_account);
+ return False;
+ }
+
*psid_name_use = SID_NAME_USER;
TALLOC_FREE(sam_account);
int num_rids,
uint32 *rids,
const char **names,
- uint32 *attrs)
+ enum SID_NAME_USE *attrs)
{
int i;
NTSTATUS result;
int num_names,
const char **names,
uint32 *rids,
- uint32 *attrs)
+ enum SID_NAME_USE *attrs)
{
int i;
NTSTATUS result;
static BOOL next_entry_users(struct pdb_search *s,
struct samr_displayentry *entry)
{
- struct user_search *state = s->private_data;
+ struct user_search *state = (struct user_search *)s->private_data;
struct samu *user = NULL;
next:
static BOOL next_entry_groups(struct pdb_search *s,
struct samr_displayentry *entry)
{
- struct group_search *state = s->private_data;
+ struct group_search *state = (struct group_search *)s->private_data;
uint32 rid;
GROUP_MAP *map = &state->groups[state->current_group];
static void search_end_groups(struct pdb_search *search)
{
- struct group_search *state = search->private_data;
+ struct group_search *state =
+ (struct group_search *)search->private_data;
SAFE_FREE(state->groups);
}
struct pdb_methods *pdb = pdb_get_methods();
struct pdb_search *result;
- if (pdb == NULL) return NULL;
-
result = pdb_search_init(PDB_USER_SEARCH);
- if (result == NULL) return NULL;
+ if (result == NULL) {
+ return NULL;
+ }
if (!pdb->search_users(pdb, result, acct_flags)) {
talloc_destroy(result->mem_ctx);
struct pdb_methods *pdb = pdb_get_methods();
struct pdb_search *result;
- if (pdb == NULL) return NULL;
-
result = pdb_search_init(PDB_GROUP_SEARCH);
- if (result == NULL) return NULL;
+ if (result == NULL) {
+ return NULL;
+ }
if (!pdb->search_groups(pdb, result)) {
talloc_destroy(result->mem_ctx);