static NTSTATUS auth_get_sam_account(const char *user, struct samu **account)
{
BOOL pdb_ret;
- NTSTATUS nt_status;
+ NTSTATUS nt_status = NT_STATUS_NO_SUCH_USER;
if ( !(*account = samu_new( NULL )) ) {
return NT_STATUS_NO_MEMORY;
pdb_ret = pdb_getsampwnam(*account, user);
unbecome_root();
- if (!pdb_ret) {
-
- struct passwd *pass = Get_Pwnam(user);
- if (!pass)
- return NT_STATUS_NO_SUCH_USER;
+ if (!pdb_ret)
+ {
+ struct passwd *pass;
- if (!NT_STATUS_IS_OK(nt_status = pdb_fill_sam_pw(*account, pass))) {
- return nt_status;
+ if ( !(pass = Get_Pwnam( user )) ) {
+ return NT_STATUS_NO_SUCH_USER;
}
+
+ nt_status = samu_set_unix( *account, pass );
}
- return NT_STATUS_OK;
+
+ return nt_status;
}
/****************************************************************************
/* Can't use the talloc version here, because the returned struct gets
kept on the server_info */
- if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(&sampass))) {
- return nt_status;
+
+ if ( !(sampass = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
}
/* get the account information */
**/
static BOOL update_smbpassword_file(const char *user, const char *password)
{
- struct samu *sampass = NULL;
+ struct samu *sampass;
BOOL ret;
- pdb_init_sam(&sampass);
+ if ( !(sampass = samu_new( NULL )) ) {
+ return False;
+ }
become_root();
ret = pdb_getsampwnam(sampass, user);
and let the "passdb backend" handle unknown users. */
if ( !is_trusted_domain(domain) && !strequal(domain, get_global_sam_name()) )
- domain = get_default_sam_name();
+ domain = my_sam_name();
/* we know that it is a trusted domain (and we are allowing them) or it is our domain */
if ( token )
return token;
- if ( !(pw = getpwnam( "root" )) ) {
+ if ( !(pw = sys_getpwnam( "root" )) ) {
DEBUG(0,("get_root_nt_token: getpwnam\"root\") failed!\n"));
return NULL;
}
struct samu *sam_acct = NULL;
- result = pdb_init_sam_talloc(tmp_ctx, &sam_acct);
- if (!NT_STATUS_IS_OK(result)) {
+ if ( !(sam_acct = samu_new( tmp_ctx )) ) {
goto done;
}
fstring dom_name;
auth_serversupplied_info *result;
- status = pdb_init_sam_pw(&sampass, pwd);
-
- if (!NT_STATUS_IS_OK(status)) {
+ if ( !(sampass = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ status = samu_set_unix( sampass, pwd );
+ if ( !NT_STATUS_IS_OK(status) ) {
return status;
}
gid_t *gids;
auth_serversupplied_info *result;
- status = pdb_init_sam_pw(&sampass, pwd);
-
+ if ( !(sampass = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ status = samu_set_unix( sampass, pwd );
if (!NT_STATUS_IS_OK(status)) {
return status;
}
BOOL ret;
static const char zeros[16];
- status = pdb_init_sam(&sampass);
-
- if (!NT_STATUS_IS_OK(status)) {
- return status;
+ if ( !(sampass = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
}
sid_copy(&guest_sid, get_global_sam_sid());
const char *username,
char **found_username,
uid_t *uid, gid_t *gid,
- struct samu **sam_account)
+ struct samu *account)
{
NTSTATUS nt_status;
fstring dom_user, lower_username;
*found_username = talloc_strdup( mem_ctx, real_username );
- DEBUG(5,("fill_sam_account: located username was [%s]\n",
- *found_username));
+ DEBUG(5,("fill_sam_account: located username was [%s]\n", *found_username));
- nt_status = pdb_init_sam_pw(sam_account, passwd);
+ nt_status = samu_set_unix( account, passwd );
+
TALLOC_FREE(passwd);
+
return nt_status;
}
char *found_username;
const char *nt_domain;
const char *nt_username;
-
struct samu *sam_account = NULL;
DOM_SID user_sid;
DOM_SID group_sid;
that is how the current code is designed. Making the change here
is the least disruptive place. -- jerry */
+ if ( !(sam_account = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
nt_status = fill_sam_account(mem_ctx, nt_domain, sent_nt_username,
- &found_username, &uid, &gid,
- &sam_account);
+ &found_username, &uid, &gid, sam_account);
if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_SUCH_USER)) {
DEBUG(3,("User %s does not exist, trying to add it\n",
internal_username));
smb_create_user( nt_domain, sent_nt_username, NULL);
- nt_status = fill_sam_account( mem_ctx, nt_domain,
- sent_nt_username,
- &found_username, &uid, &gid,
- &sam_account );
+ nt_status = fill_sam_account( mem_ctx, nt_domain, sent_nt_username,
+ &found_username, &uid, &gid, sam_account );
}
/* if we still don't have a valid unix account check for
'map to gues = bad uid' */
if (!NT_STATUS_IS_OK(nt_status)) {
+ TALLOC_FREE( sam_account );
if ( lp_map_to_guest() == MAP_TO_GUEST_ON_BAD_UID ) {
make_server_info_guest(server_info);
return NT_STATUS_OK;
}
-
- DEBUG(0, ("make_server_info_info3: pdb_init_sam failed!\n"));
return nt_status;
}
}
/* Get the user's record. */
- pdb_init_sam(&sampass);
- pdb_getsampwnam(sampass, name );
- if (!sampass) {
+ if ( (sampass = samu_new( NULL )) != NULL ) {
+ pdb_getsampwnam(sampass, name );
+ }
+
+ /* check for lookup failure */
+ if ( !sampass || !strlen(pdb_get_username(sampass)) ) {
CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
return PAM_USER_UNKNOWN;
}
AUTH_RETURN;
}
- pdb_init_sam(&sampass);
+ sampass = samu_new( NULL );
found = pdb_getsampwnam( sampass, name );
char *pass_old;
char *pass_new;
- NTSTATUS nt_status;
-
/* Samba initialization. */
setup_logging( "pam_smbpass", False );
in_client = True;
}
/* obtain user record */
- if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(&sampass))) {
+ if ( !(sampass = samu_new( NULL )) ) {
CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler);
- return nt_status_to_pam(nt_status);
+ return nt_status_to_pam(NT_STATUS_NO_MEMORY);
}
if (!pdb_getsampwnam(sampass,user)) {
Password and authentication handling
Copyright (C) Jeremy Allison 1996-2001
Copyright (C) Luke Kenneth Casson Leighton 1996-1998
- Copyright (C) Gerald (Jerry) Carter 2000-2001
+ Copyright (C) Gerald (Jerry) Carter 2000-2006
Copyright (C) Andrew Bartlett 2001-2002
Copyright (C) Simo Sorce 2003
Copyright (C) Volker Lendecke 2006
standalone box will map to WKS\user.
******************************************************************/
-const char *get_default_sam_name(void)
+const char *my_sam_name(void)
{
/* standalone servers can only use the local netbios name */
if ( lp_server_role() == ROLE_STANDALONE )
Fill the struct samu with default values.
***********************************************************/
-void pdb_fill_default_sam(struct samu *user)
+static void samu_init( struct samu *user )
{
/* no initial methods */
user->methods = NULL;
user->logon_time = (time_t)0;
user->pass_last_set_time = (time_t)0;
user->pass_can_change_time = (time_t)0;
- user->logoff_time =
- user->kickoff_time =
+ user->logoff_time = get_time_t_max();
+ user->kickoff_time = get_time_t_max();
user->pass_must_change_time = get_time_t_max();
user->fields_present = 0x00ffffff;
user->logon_divs = 168; /* hours per week */
return 0;
}
-/**********************************************************************
-***********************************************************************/
-
-BOOL samu_init( struct samu *user )
-{
- pdb_fill_default_sam( user );
-
- return True;
-}
-
/**********************************************************************
generate a new struct samuser
***********************************************************************/
return NULL;
}
- if ( !samu_init( user ) ) {
- DEBUG(0,("samuser_new: initialization failed!\n"));
- TALLOC_FREE( user );
- return NULL;
- }
+ samu_init( user );
talloc_set_destructor( user, samu_destroy );
return user;
}
-/**********************************************************************
- Allocates memory and initialises a struct sam_passwd on supplied mem_ctx.
-***********************************************************************/
-
-NTSTATUS pdb_init_sam_talloc(TALLOC_CTX *mem_ctx, struct samu **user)
-{
- if ( !*user )
- return NT_STATUS_UNSUCCESSFUL;
-
- *user = samu_new( mem_ctx );
- return *user ? NT_STATUS_OK : NT_STATUS_NO_MEMORY;
-}
-
-
-/*************************************************************
- Allocates memory and initialises a struct sam_passwd.
- ************************************************************/
-
-NTSTATUS pdb_init_sam(struct samu **user)
-{
- *user = samu_new( NULL );
- return *user ? NT_STATUS_OK : NT_STATUS_NO_MEMORY;
-}
-
/**************************************************************************
* This function will take care of all the steps needed to correctly
* allocate and set the user SID, please do use this function to create new
Initialises a struct sam_passwd with sane values.
************************************************************/
-NTSTATUS pdb_fill_sam_pw(struct samu *sam_account, const struct passwd *pwd)
+NTSTATUS samu_set_unix(struct samu *sam_account, const struct passwd *pwd)
{
NTSTATUS ret;
- if (!pwd) {
- return NT_STATUS_UNSUCCESSFUL;
+ if ( !pwd ) {
+ return NT_STATUS_NO_SUCH_USER;
}
- pdb_fill_default_sam(sam_account);
-
pdb_set_username(sam_account, pwd->pw_name, PDB_SET);
pdb_set_fullname(sam_account, pwd->pw_gecos, PDB_SET);
-
pdb_set_unix_homedir(sam_account, pwd->pw_dir, PDB_SET);
-
pdb_set_domain (sam_account, get_global_sam_name(), PDB_DEFAULT);
/* When we get a proper uid -> SID and SID -> uid allocation
*/
ret = pdb_set_sam_sids(sam_account, pwd);
- if (!NT_STATUS_IS_OK(ret)) return ret;
+ if (!NT_STATUS_IS_OK(ret))
+ return ret;
/* check if this is a user account or a machine account */
if (pwd->pw_name[strlen(pwd->pw_name)-1] != '$')
return NT_STATUS_OK;
}
-
-/*************************************************************
- Initialises a struct sam_passwd with sane values.
- ************************************************************/
-
-NTSTATUS pdb_init_sam_pw(struct samu **new_sam_acct, const struct passwd *pwd)
-{
- NTSTATUS nt_status;
-
- if (!pwd) {
- new_sam_acct = NULL;
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(new_sam_acct))) {
- new_sam_acct = NULL;
- return nt_status;
- }
-
- if (!NT_STATUS_IS_OK(nt_status = pdb_fill_sam_pw(*new_sam_acct, pwd))) {
- TALLOC_FREE(new_sam_acct);
- new_sam_acct = NULL;
- return nt_status;
- }
-
- return NT_STATUS_OK;
-}
-
-
/*************************************************************
Initialises a struct samu ready to add a new account, based
- on the UNIX user. Pass in a RID if you have one
+ on the UNIX user.
************************************************************/
NTSTATUS pdb_init_sam_new(struct samu **new_sam_acct, const char *username)
return NT_STATUS_NO_MEMORY;
}
- pwd = Get_Pwnam_alloc(mem_ctx, username);
-
- if (pwd == NULL) {
+ if ( !(pwd = Get_Pwnam_alloc(mem_ctx, username)) ) {
DEBUG(10, ("Could not find user %s\n", username));
result = NT_STATUS_NO_SUCH_USER;
goto done;
}
- result = pdb_init_sam_pw(new_sam_acct, pwd);
+ if ( !(*new_sam_acct = samu_new( NULL )) ) {
+ result = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ result = samu_set_unix( *new_sam_acct, pwd );
+
if (!NT_STATUS_IS_OK(result)) {
- DEBUG(10, ("pdb_init_sam_pw failed: %s\n", nt_errstr(result)));
+ DEBUG(10, ("samu_set_unix failed: %s\n", nt_errstr(result)));
goto done;
}
struct samu *sam_account = NULL;
DOM_SID user_sid;
- if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_account))) {
+ if ( !(sam_account = samu_new( NULL )) ) {
return False;
}
*msg_str = '\0';
/* Get the smb passwd entry for this user */
- pdb_init_sam(&sam_pass);
+
+ if ( !(sam_pass = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
become_root();
if(!pdb_getsampwnam(sam_pass, user_name)) {
result = pdb_init_sam_new(&sam_pass, user_name);
DEBUGLEVEL = tmp_debug;
- if (NT_STATUS_EQUAL(result,
- NT_STATUS_INVALID_PRIMARY_GROUP)) {
+ if (NT_STATUS_EQUAL(result, NT_STATUS_INVALID_PRIMARY_GROUP)) {
return result;
}
uint8 *buf;
int len;
- if ((*dst == NULL) && (!NT_STATUS_IS_OK(pdb_init_sam(dst))))
+ if ( !*dst && !(*dst = samu_new(NULL)) )
return False;
len = init_buffer_from_sam_v2(&buf, src, False);
BOOL guest_user_info( struct samu *user )
{
struct passwd *pwd;
- NTSTATUS ntstatus;
+ NTSTATUS result;
const char *guestname = lp_guestaccount();
if ( !(pwd = getpwnam_alloc( NULL, guestname ) ) ) {
return False;
}
- /* fill in from the users information */
-
- ntstatus = pdb_fill_sam_pw( user, pwd );
-
- return NT_STATUS_IS_OK(ntstatus);
+ result = samu_set_unix(user, pwd);
+
+ TALLOC_FREE( pwd );
+
+ return NT_STATUS_IS_OK( result );
}
struct passwd *pwd;
const char *group_name;
uid_t uid;
- NTSTATUS status;
sid_compose(&group_sid, get_global_sam_sid(), group_rid);
sid_compose(&member_sid, get_global_sam_sid(), member_rid);
return NT_STATUS_NO_MEMORY;
}
- if (!NT_STATUS_IS_OK(status = pdb_init_sam(&account))) {
- return status;
+ if ( !(account = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
}
if (!pdb_getsampwsid(account, &member_sid) ||
struct passwd *pwd;
const char *group_name;
uid_t uid;
- NTSTATUS status;
sid_compose(&group_sid, get_global_sam_sid(), group_rid);
sid_compose(&member_sid, get_global_sam_sid(), member_rid);
return NT_STATUS_NO_MEMORY;
}
- if (!NT_STATUS_IS_OK(status = pdb_init_sam(&account))) {
- return status;
+ if ( !(account = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
}
if (!pdb_getsampwsid(account, &member_sid) ||
return False;
}
- if ( !NT_STATUS_IS_OK(pdb_init_sam(&sampw)) ) {
- DEBUG(0,("pdb_default_uid_to_rid: failed to allocate "
- "struct samu object\n"));
+ if ( !(sampw = samu_new( NULL )) ) {
+ DEBUG(0,("pdb_default_uid_to_rid: samu_new() failed!\n"));
return False;
}
-
+
become_root();
ret = NT_STATUS_IS_OK(
methods->getsampwnam(methods, sampw, unix_pw->pw_name ));
sid_append_rid(&sid, rid);
/* see if the passdb can help us with the name of the user */
- if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_account))) {
+
+ if ( !(sam_account = samu_new( NULL )) ) {
return False;
}
{
struct user_search *state = s->private_data;
struct samu *user = NULL;
- NTSTATUS status;
next:
- status = pdb_init_sam(&user);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("Could not pdb_init_sam\n"));
+ if ( !(user = samu_new( NULL )) ) {
+ DEBUG(0, ("next_entry_users: samu_new() failed!\n"));
return False;
}
{
struct passwd *pwfile;
- if (sam_pass==NULL) {
+ if ( !sam_pass ) {
DEBUG(5,("build_sam_account: struct samu is NULL\n"));
return False;
}
return False;
}
- if (!NT_STATUS_IS_OK(pdb_fill_sam_pw(sam_pass, pwfile)))
+ if ( !NT_STATUS_IS_OK( samu_set_unix(sam_pass, pwfile)) )
return False;
TALLOC_FREE(pwfile);
struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data;
struct smb_passwd *pw_buf=NULL;
BOOL done = False;
+
DEBUG(5,("pdb_getsampwent\n"));
- if (user==NULL) {
+ if ( !user ) {
DEBUG(5,("pdb_getsampwent (smbpasswd): user is NULL\n"));
-#if 0
- smb_panic("NULL pointer passed to getsampwent (smbpasswd)\n");
-#endif
return nt_status;
}
if (!sam_acct) {
DEBUG(10,("getsampwnam (smbpasswd): struct samu is NULL\n"));
-#if 0
- smb_panic("NULL pointer passed to pdb_getsampwnam\n");
-#endif
return nt_status;
}
if (!sam_acct) {
DEBUG(10,("getsampwrid: (smbpasswd) struct samu is NULL\n"));
-#if 0
- smb_panic("NULL pointer passed to pdb_getsampwrid\n");
-#endif
return nt_status;
}
}
/* unpack the buffer from the former format */
- pdb_init_sam( &user );
+ if ( !(user = samu_new( NULL )) ) {
+ DEBUG(0,("tdbsam_convert: samu_new() failed!\n"));
+ SAFE_FREE( data.dptr );
+ return False;
+ }
DEBUG(10,("tdbsam_convert: Try unpacking a record with (key:%s) (version:%d)\n", key.dptr, from));
switch (from) {
case 0:
}
#endif /* 0 */
- if(!NT_STATUS_IS_OK(pdb_init_sam(&sampass)))
+ if ( !(sampass = samu_new( NULL )) ) {
return False;
+ }
/* JRA. This is ok as it is only used for generating the challenge. */
become_root();
secrets_store_schannel_session_info(p->pipe_state_mem_ctx,
remote_machine,
p->dc);
- pdb_init_sam(&sampass);
- ret=pdb_getsampwnam(sampass, p->dc->mach_acct);
+ if ( (sampass = samu_new( NULL )) != NULL ) {
+ ret = pdb_getsampwnam(sampass, p->dc->mach_acct);
+ }
unbecome_root();
+ if ( !sampass )
+ return NT_STATUS_NO_MEMORY;
+
/* Ensure the account exists and is a machine account. */
acct_ctrl = pdb_get_acct_ctrl(sampass);
if ( !NT_STATUS_IS_OK(nt_status) )
return nt_status;
- nt_status = pdb_init_sam_talloc(p->mem_ctx, &sampass);
-
- if (!NT_STATUS_IS_OK(nt_status))
- return nt_status;
+ if ( !(sampass = samu_new( p->mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
/* append the user's RID to it */
{
struct samu *smbpass=NULL;
BOOL ret;
- NTSTATUS nt_status;
- nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass);
-
- if (!NT_STATUS_IS_OK(nt_status)) {
- return nt_status;
+ if ( !(smbpass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
}
-
+
become_root();
ret = pdb_getsampwsid(smbpass, user_sid);
unbecome_root();
- if (ret==False) {
+ if ( !ret ) {
DEBUG(4,("User %s not found\n", sid_string_static(user_sid)));
return NT_STATUS_NO_SUCH_USER;
}
{
struct samu *smbpass=NULL;
BOOL ret;
- NTSTATUS nt_status;
-
- nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass);
- if (!NT_STATUS_IS_OK(nt_status)) {
- return nt_status;
+ if ( !(smbpass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
}
become_root();
{
struct samu *smbpass=NULL;
BOOL ret;
- NTSTATUS nt_status;
- nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass);
-
- if (!NT_STATUS_IS_OK(nt_status)) {
- return nt_status;
+ if ( !(smbpass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
}
become_root();
{
struct samu *smbpass=NULL;
BOOL ret;
- NTSTATUS nt_status;
if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
return NT_STATUS_ACCESS_DENIED;
* Do *NOT* do become_root()/unbecome_root() here ! JRA.
*/
- nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass);
-
- if (!NT_STATUS_IS_OK(nt_status)) {
- return nt_status;
+ if ( !(smbpass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
}
ret = pdb_getsampwsid(smbpass, user_sid);
struct samu *sampass=NULL;
BOOL ret;
- pdb_init_sam_talloc(mem_ctx, &sampass);
+ if ( !(sampass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
become_root();
ret = pdb_getsampwsid(sampass, user_sid);
BOOL ret;
NTSTATUS nt_status;
- nt_status = pdb_init_sam_talloc(mem_ctx, &sampass);
- if (!NT_STATUS_IS_OK(nt_status)) {
- return nt_status;
+ if ( !(sampass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
}
become_root();
if (!sid_check_is_in_our_domain(&sid))
return NT_STATUS_OBJECT_TYPE_MISMATCH;
- pdb_init_sam_talloc(p->mem_ctx, &sam_pass);
-
+ if ( !(sam_pass = samu_new( p->mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
become_root();
ret = pdb_getsampwsid(sam_pass, &sid);
unbecome_root();
return NT_STATUS_INVALID_INFO_CLASS;
}
- pdb_init_sam(&pwd);
+ if ( !(pwd = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
become_root();
ret = pdb_getsampwsid(pwd, &sid);
switch_value=ctr->switch_value;
- pdb_init_sam(&pwd);
-
+ if ( !(pwd = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
become_root();
ret = pdb_getsampwsid(pwd, &sid);
unbecome_root();
return NT_STATUS_CANNOT_DELETE;
/* check if the user exists before trying to delete */
- pdb_init_sam(&sam_pass);
+ if ( !(sam_pass = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
if(!pdb_getsampwsid(sam_pass, &user_sid)) {
DEBUG(5,("_samr_delete_dom_user:User %s doesn't exist.\n",
sid_string_static(&user_sid)));
*hnd = NULL;
- pdb_init_sam(&sampass);
+ if ( !(sampass = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
become_root();
ret = pdb_getsampwnam(sampass, user);
goto done;
}
- if (!NT_STATUS_IS_OK(pdb_init_sam_talloc(mem_ctx, &sampw))) {
- DEBUG(10, ("pdb_init_sam_talloc failed\n"));
+ if ( !(sampw = samu_new(mem_ctx)) ) {
+ DEBUG(0, ("samu_new() failed!\n"));
goto done;
}
fstrcpy(account, unistr2_static(&delta->uni_acct_name));
d_printf("Creating account: %s\n", account);
- if (!NT_STATUS_IS_OK(nt_ret = pdb_init_sam(&sam_account)))
- return nt_ret;
+ if ( !(sam_account = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
if (!(passwd = Get_Pwnam(account))) {
/* Create appropriate user */
nt_members = TALLOC_ZERO_ARRAY(t, char *, delta->num_members);
for (i=0; i<delta->num_members; i++) {
- NTSTATUS nt_status;
struct samu *member = NULL;
DOM_SID member_sid;
- if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam_talloc(t, &member))) {
+ if ( !(member = samu_new(t)) ) {
talloc_destroy(t);
- return nt_status;
+ return NT_STATUS_NO_MEMORY;
}
sid_copy(&member_sid, get_global_sam_sid());
return -1;
}
- if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_acct))) {
+ if ( !(sam_acct = samu_new( NULL )) ) {
d_fprintf(stderr, "Internal error\n");
return -1;
}
return -1;
}
- if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_acct))) {
+ if ( !(sam_acct = samu_new( NULL )) ) {
d_fprintf(stderr, "Internal error\n");
return -1;
}
}
- if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_acct))) {
+ if ( !(sam_acct = samu_new( NULL )) ) {
d_fprintf(stderr, "Internal error\n");
return -1;
}
struct samu *sam_pwent=NULL;
BOOL ret;
- if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pwent))) {
+ if ( !(sam_pwent = samu_new( NULL )) ) {
return -1;
}
}
check = True;
- if (!(NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)))) return 1;
+ if ( !(sam_pwent = samu_new( NULL )) ) {
+ return 1;
+ }
while (check && NT_STATUS_IS_OK(in->getsampwent (in, sam_pwent))) {
if (verbosity)
printf ("---------------\n");
print_sam_info (sam_pwent, verbosity, smbpwdstyle);
TALLOC_FREE(sam_pwent);
- check = NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent));
+
+ if ( !(sam_pwent = samu_new( NULL )) ) {
+ check = False;
+ }
}
- if (check) TALLOC_FREE(sam_pwent);
+ if (check)
+ TALLOC_FREE(sam_pwent);
in->endsampwent(in);
return 0;
}
check = True;
- if (!(NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)))) return 1;
+ if ( !(sam_pwent = samu_new( NULL )) ) {
+ return 1;
+ }
while (check && NT_STATUS_IS_OK(in->getsampwent (in, sam_pwent))) {
printf("Updating record for user %s\n", pdb_get_username(sam_pwent));
printf("Update of user %s failed!\n", pdb_get_username(sam_pwent));
}
TALLOC_FREE(sam_pwent);
- check = NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent));
+ if ( !(sam_pwent = samu_new( NULL )) ) {
+ check = False;
+ }
if (!check) {
fprintf(stderr, "Failed to initialise new struct samu structure (out of memory?)\n");
}
}
- if (check) TALLOC_FREE(sam_pwent);
+ if (check)
+ TALLOC_FREE(sam_pwent);
in->endsampwent(in);
return 0;
struct samu *sam_pwent=NULL;
BOOL ret;
- pdb_init_sam(&sam_pwent);
+ if ( !(sam_pwent = samu_new( NULL )) ) {
+ return 1;
+ }
ret = NT_STATUS_IS_OK(in->getsampwnam (in, sam_pwent, username));
if (ret==False) {
fstrcat(machineaccount, "$");
if ((pwd = getpwnam_alloc(NULL, machineaccount))) {
- if (!NT_STATUS_IS_OK(pdb_init_sam_pw( &sam_pwent, pwd))) {
+
+ if ( !(sam_pwent = samu_new( NULL )) ) {
+ fprintf(stderr, "Memory allocation error!\n");
+ TALLOC_FREE(pwd);
+ return -1;
+ }
+
+ if ( !NT_STATUS_IS_OK(samu_set_unix(sam_pwent, pwd)) ) {
fprintf(stderr, "Could not init sam from pw\n");
TALLOC_FREE(pwd);
return -1;
}
+
TALLOC_FREE(pwd);
} else {
- if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pwent))) {
+ if ( !(sam_pwent = samu_new( NULL )) ) {
fprintf(stderr, "Could not init sam from pw\n");
return -1;
}
{
struct samu *samaccount = NULL;
- if (!NT_STATUS_IS_OK(pdb_init_sam (&samaccount))) {
+ if ( !(samaccount = samu_new( NULL )) ) {
return -1;
}
if (name[strlen(name)-1] != '$')
fstrcat (name, "$");
- if (!NT_STATUS_IS_OK(pdb_init_sam (&samaccount))) {
+ if ( !(samaccount = samu_new( NULL )) ) {
return -1;
}
struct samu *sampass = NULL;
BOOL ret;
- pdb_init_sam(&sampass);
+ sampass = samu_new( NULL );
ret = pdb_getsampwnam(sampass, user_name);
if((ret) &&
(pdb_get_lanman_passwd(sampass) == NULL)) {
struct samu *sampass = NULL;
BOOL ret;
- pdb_init_sam(&sampass);
+ sampass = samu_new( NULL );
ret = pdb_getsampwnam(sampass, user_name);
printf("Password changed for user %s.", user_name );