summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorJean-François Micouleau <jfm@samba.org>2001-05-04 15:44:27 +0000
committerJean-François Micouleau <jfm@samba.org>2001-05-04 15:44:27 +0000
commitf35157f39293f9fa240a28642c41708b55d301c8 (patch)
treecd0eb02e9b316899d2cfb9b8cc2784ad739c60a5 /source3/utils
parent1f7a451c1e059b5a86e1e78debd582579aa7bcb7 (diff)
downloadsamba-f35157f39293f9fa240a28642c41708b55d301c8.tar.gz
samba-f35157f39293f9fa240a28642c41708b55d301c8.tar.bz2
samba-f35157f39293f9fa240a28642c41708b55d301c8.zip
Big cleanup of passdb and backends.
I did some basic tests but I have probably broken something. Notably the password changing. So don't cry ;-) J.F. (This used to be commit a4a4c02b12f030a3b9e6225b999c90689dfc4719)
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/pdbedit.c93
-rw-r--r--source3/utils/smbgroupedit.c9
-rw-r--r--source3/utils/smbpasswd.c21
3 files changed, 81 insertions, 42 deletions
diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c
index 6022f9aef2..9a545fbb45 100644
--- a/source3/utils/pdbedit.c
+++ b/source3/utils/pdbedit.c
@@ -113,12 +113,23 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst
**********************************************************/
static int print_user_info (char *username, BOOL verbosity, BOOL smbpwdstyle)
{
- SAM_ACCOUNT *sam_pwent;
+ SAM_ACCOUNT *sam_pwent=NULL;
+ BOOL ret;
+
+ pdb_init_sam(&sam_pwent);
- sam_pwent = pdb_getsampwnam (username);
- if (sam_pwent) return print_sam_info (sam_pwent, verbosity, smbpwdstyle);
- else fprintf (stderr, "Username not found!\n");
- return -1;
+ ret = pdb_getsampwnam (sam_pwent, username);
+
+ if (ret==False) {
+ fprintf (stderr, "Username not found!\n");
+ pdb_clear_sam(sam_pwent);
+ return -1;
+ }
+
+ ret=print_sam_info (sam_pwent, verbosity, smbpwdstyle);
+ pdb_clear_sam(sam_pwent);
+
+ return ret;
}
/*********************************************************
@@ -126,22 +137,26 @@ static int print_user_info (char *username, BOOL verbosity, BOOL smbpwdstyle)
**********************************************************/
static int print_users_list (BOOL verbosity, BOOL smbpwdstyle)
{
- SAM_ACCOUNT *sam_pwent;
+ SAM_ACCOUNT *sam_pwent=NULL;
BOOL ret;
+ pdb_init_sam(&sam_pwent);
+
ret = pdb_setsampwent(False);
if (ret && errno == ENOENT) {
fprintf (stderr,"Password database not found!\n");
+ pdb_clear_sam(sam_pwent);
exit(1);
}
- while ((sam_pwent = pdb_getsampwent ()))
+ while ((ret = pdb_getsampwent (sam_pwent)))
{
if (verbosity) printf ("---------------\n");
print_sam_info (sam_pwent, verbosity, smbpwdstyle);
}
pdb_endsampwent ();
+ pdb_clear_sam(sam_pwent);
return 0;
}
@@ -150,27 +165,33 @@ static int print_users_list (BOOL verbosity, BOOL smbpwdstyle)
**********************************************************/
static int set_user_info (char *username, char *fullname, char *homedir, char *drive, char *script, char *profile)
{
- SAM_ACCOUNT *sam_pwent;
+ SAM_ACCOUNT *sam_pwent=NULL;
+ BOOL ret;
+
+ pdb_init_sam(&sam_pwent);
- sam_pwent = pdb_getsampwnam (username);
- if (!sam_pwent)
+ ret = pdb_getsampwnam (sam_pwent, username);
+ if (ret==False)
{
fprintf (stderr, "Username not found!\n");
+ pdb_clear_sam(sam_pwent);
return -1;
}
- if (fullname) sam_pwent->full_name = fullname;
- if (homedir) sam_pwent->home_dir = homedir;
- if (drive) sam_pwent->dir_drive = drive;
- if (script) sam_pwent->logon_script = script;
- if (profile) sam_pwent->profile_path = profile;
+ if (fullname) pdb_set_fullname(sam_pwent, fullname);
+ if (homedir) pdb_set_homedir(sam_pwent, homedir);
+ if (drive) pdb_set_dir_drive(sam_pwent,drive);
+ if (script) pdb_set_logon_script(sam_pwent, script);
+ if (profile) pdb_set_profile_path (sam_pwent, profile);
if (pdb_update_sam_account (sam_pwent, TRUE)) print_user_info (username, TRUE, FALSE);
else
{
fprintf (stderr, "Unable to modify entry!\n");
+ pdb_clear_sam(sam_pwent);
return -1;
}
+ pdb_clear_sam(sam_pwent);
return 0;
}
@@ -180,6 +201,7 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d
static int new_user (char *username, char *fullname, char *homedir, char *drive, char *script, char *profile)
{
SAM_ACCOUNT sam_pwent;
+ BOOL ret;
struct passwd *pwd = NULL;
uchar new_p16[16];
uchar new_nt_p16[16];
@@ -187,7 +209,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive,
ZERO_STRUCT(sam_pwent);
- if (pdb_getsampwnam (username))
+ if (pdb_getsampwnam (&sam_pwent, username))
{
fprintf (stderr, "Username already exist in database!\n");
return -1;
@@ -208,12 +230,12 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive,
}
nt_lm_owf_gen (password1, new_nt_p16, new_p16);
- sam_pwent.username = username;
- if (fullname) sam_pwent.full_name = fullname;
- if (homedir) sam_pwent.home_dir = homedir;
- if (drive) sam_pwent.dir_drive = drive;
- if (script) sam_pwent.logon_script = script;
- if (profile) sam_pwent.profile_path = profile;
+ pdb_set_username(&sam_pwent, username);
+ if (fullname) pdb_set_fullname(&sam_pwent, fullname);
+ if (homedir) pdb_set_homedir (&sam_pwent, homedir);
+ if (drive) pdb_set_dir_drive (&sam_pwent, drive);
+ if (script) pdb_set_logon_script(&sam_pwent, script);
+ if (profile) pdb_set_profile_path (&sam_pwent, profile);
/* TODO: Check uid not being in MACHINE UID range!! */
sam_pwent.uid = pwd->pw_uid;
@@ -239,6 +261,7 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive,
static int new_machine (char *machinename)
{
SAM_ACCOUNT sam_pwent;
+ SAM_ACCOUNT sam_trust;
uchar new_p16[16];
uchar new_nt_p16[16];
char name[16];
@@ -254,14 +277,17 @@ static int new_machine (char *machinename)
strlower(password);
nt_lm_owf_gen (password, new_nt_p16, new_p16);
- sam_pwent.username = name;
+ pdb_set_username(&sam_pwent, name);
+
+ for (uid=BASE_MACHINE_UID; uid<=MAX_MACHINE_UID; uid++)
+ if (!(pdb_getsampwuid (&sam_trust, uid)))
+ break;
- for (uid=BASE_MACHINE_UID; uid<=MAX_MACHINE_UID; uid++) if (!(pdb_getsampwuid (uid))) break;
- if (uid>MAX_MACHINE_UID)
- {
+ if (uid>MAX_MACHINE_UID) {
fprintf (stderr, "No more free UIDs available to Machine accounts!\n");
return -1;
}
+
sam_pwent.uid = uid;
sam_pwent.gid = BASE_MACHINE_UID; /* TODO: set there more appropriate value!! */
sam_pwent.user_rid = pdb_uid_to_user_rid (uid);
@@ -270,9 +296,9 @@ static int new_machine (char *machinename)
sam_pwent.nt_pw = new_nt_p16;
sam_pwent.acct_ctrl = ACB_WSTRUST;
- if (pdb_add_sam_account (&sam_pwent)) print_user_info (name, TRUE, FALSE);
- else
- {
+ if (pdb_add_sam_account (&sam_pwent))
+ print_user_info (name, TRUE, FALSE);
+ else {
fprintf (stderr, "Unable to add machine!\n");
return -1;
}
@@ -309,6 +335,7 @@ static int import_users (char *filename)
{
FILE *fp = NULL;
SAM_ACCOUNT sam_pwent;
+ SAM_ACCOUNT sam_test;
static pstring user_name;
static unsigned char smbpwd[16];
static unsigned char smbntpwd[16];
@@ -360,7 +387,7 @@ static int import_users (char *filename)
line++;
if (linebuf[0] == '#' || linebuf[0] == '\0') continue;
- pdb_init_sam (&sam_pwent);
+ /*pdb_init_sam (&sam_pwent);*/
sam_pwent.acct_ctrl = ACB_NORMAL;
/* Get user name */
@@ -393,8 +420,8 @@ static int import_users (char *filename)
continue;
}
- sam_pwent.username = user_name;
- sam_pwent.uid = uidval;
+ pdb_set_username(&sam_pwent, user_name);
+ pdb_set_uid (&sam_pwent, uidval);
/* Get passwords */
p++;
@@ -503,7 +530,7 @@ static int import_users (char *filename)
{
struct passwd *pwd = NULL;
- if (pdb_getsampwnam (user_name))
+ if (pdb_getsampwnam (&sam_test,user_name))
{
fprintf (stderr, "Error: Username already exist in database!\n");
continue;
diff --git a/source3/utils/smbgroupedit.c b/source3/utils/smbgroupedit.c
index 01ae7091b3..76624312d5 100644
--- a/source3/utils/smbgroupedit.c
+++ b/source3/utils/smbgroupedit.c
@@ -48,7 +48,8 @@ static void usage(void)
printf(" -n group NT group name\n");
printf(" -p privilege only local\n");
printf(" -v list groups\n");
- printf(" -c SID change group\n");
+ printf(" -c SID change group\n");
+ printf(" -u unix group\n");
printf(" -x group delete this group\n");
printf("\n");
printf(" -t[b|d|l] type: builtin, domain, local \n");
@@ -68,7 +69,7 @@ int addgroup(char *group, enum SID_NAME_USE sid_type, char *ntgroup, char *ntcom
/* convert_priv_from_text(&se_priv, privilege);*/
- se_priv=0xff;
+ se_priv=0x0;
gid=nametogid(group);
if (gid==-1)
@@ -87,7 +88,7 @@ int addgroup(char *group, enum SID_NAME_USE sid_type, char *ntgroup, char *ntcom
else
fstrcpy(comment, ntcomment);
- if(!add_initial_entry(gid, string_sid, sid_type, group, comment, se_priv))
+ if(!add_initial_entry(gid, string_sid, sid_type, name, comment, se_priv))
return -1;
return 0;
@@ -176,7 +177,7 @@ int listgroup(enum SID_NAME_USE sid_type)
printf("Unix\tSID\ttype\tnt name\tnt comment\tprivilege\n");
- if (!enum_group_mapping(sid_type, &map, &entries))
+ if (!enum_group_mapping(sid_type, &map, &entries, ENUM_ALL_MAPPED))
return -1;
for (i=0; i<entries; i++) {
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
index 8ddd07a4c5..2131ea0d8f 100644
--- a/source3/utils/smbpasswd.c
+++ b/source3/utils/smbpasswd.c
@@ -412,10 +412,15 @@ static int process_root(int argc, char *argv[])
*/
if(local_flags & LOCAL_ENABLE_USER) {
- SAM_ACCOUNT *sampass = pdb_getsampwnam(user_name);
- if((sampass != NULL) && (pdb_get_lanman_passwd(sampass) != NULL)) {
+ SAM_ACCOUNT *sampass = NULL;
+ BOOL ret;
+
+ pdb_init_sam(&sampass);
+ ret = pdb_getsampwnam(sampass, user_name);
+ if((sampass != False) && (pdb_get_lanman_passwd(sampass) != NULL)) {
new_passwd = xstrdup("XXXX"); /* Don't care. */
}
+ pdb_clear_sam(sampass);
}
if(!new_passwd)
@@ -434,13 +439,19 @@ static int process_root(int argc, char *argv[])
}
if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD))) {
- SAM_ACCOUNT *sampass = pdb_getsampwnam(user_name);
+ SAM_ACCOUNT *sampass = NULL;
+ BOOL ret;
+
+ pdb_init_sam(&sampass);
+ ret = pdb_getsampwnam(sampass, user_name);
+
printf("Password changed for user %s.", user_name );
- if( (sampass != NULL) && (pdb_get_acct_ctrl(sampass)&ACB_DISABLED) )
+ if( (ret != False) && (pdb_get_acct_ctrl(sampass)&ACB_DISABLED) )
printf(" User has disabled flag set.");
- if((sampass != NULL) && (pdb_get_acct_ctrl(sampass) & ACB_PWNOTREQ) )
+ if((ret != False) && (pdb_get_acct_ctrl(sampass) & ACB_PWNOTREQ) )
printf(" User has no password flag set.");
printf("\n");
+ pdb_clear_sam(sampass);
}
done: