Adding a new user - modified smbpasschange.c

don_mccall at hp.com don_mccall at hp.com
Fri Mar 3 17:03:25 GMT 2000


Hello dshedd;

dshedd wrote:
 "I'm new to samba.
 I use SWAT to administer samba on a Mac OS X server.
 I was able to add a couple of users, but now when a click on the Add User
 button I get the following message back.
 "User new-name does not exist in system password file (usually /etc/passwd).
 Cannot add account without a valid local system user. " how to I get around
 this?"

Simple answer - you can write a unix script to add a unix user to your
/etc/passwd file whenever a pc user tries to connect to your machine with a
username that is NOT mapped to an existing unix user name;  the smb.conf 
'add user script' parameter enables this.  Problem with this is you really have
little control over users being added to your unix passwd file; it happens
without any intervention on your part (though you can of course do some creative
scripting to mask out 'undesirables'...)

For my own use,

I put together a quick hack based on the 2.0.6 version that will create an entry
in your /etc/passwd file of the form:

  <username from SWAT>:*:16838:20:Samba User added by SWAT:/tmp:/bin/sh

if you hit the add user button in the password management section of Swat and
there is NOT a  matching user defined in unix, and then go ahead and do the
adding of the user and password to the smbpasswd file as well.

It's not pretty (I didn't create any wrappers in the system.c for the system
calls I used - it's not configurable, etc) but I have tested it here on my HP-UX
11.0 system using standard /etc/passwd (NOT NIS) user authentication, and it
works. The hack is to the smbpasschange.c module for 2.0.6 version of Samba,
and I include the diff output for the changes here.
If the Samba team think this functionality would be of more general use, I'd be
glad to pretty it up and submit it. It IS kinda nice to not have to do two
separate operations if your unix machine is pretty well dedicated to SAMBA
anyway...


diff smbpasschange.original.c smbpasschange.c
64a65,68
> /*********************************Added by DCM:3/3/2000*****************/
>       struct passwd newpwd;
>       FILE *passwdfile;
> /*********************************endAdd by DCM:3/3/2000*****************/
79a84,98
> /*********************************Added by DCM:3/3/2000*****************/
>                 newpwd.pw_name= user_name;
>                 newpwd.pw_passwd = "*";
>               newpwd.pw_uid = rand();
>                 while (getpwuid(newpwd.pw_uid)!= 0){
>               newpwd.pw_uid = rand();
>               }
>                 newpwd.pw_gid = 20;
>               newpwd.pw_age = 0;
>               newpwd.pw_gecos = "Samba User added by SWAT";
>               newpwd.pw_dir = "/tmp";
>               newpwd.pw_shell = "/bin/sh";
>                 passwdfile = fopen("/etc/passwd","ab");
>                 putpwent(&newpwd,passwdfile);
> /*********************************EndAdd by DCM:3/3/2000*****************/
82,83c101
< account without a valid local system user.\n", user_name);
<               return False;
---
> account without a valid local system user. Therefore, added user %s to /etc/pa
sswd file.\n", user_name,user_name);

Hope this helps,
Don McCall


More information about the samba mailing list