1

Is there a way to perform additional tasks every time a new user is created with adduser(8) in FreeBSD?

To be more precise, i'd like to create a directory for every new user and map this user with pdbedit(8) to the SAM database.

Some Linux distributions like debian/ubuntu provide a handy way to solve this problem. If a script called /usr/local/sbin/adduser.local exists, it'll be executed after a new user has been created:

#!/bin/bash
mkdir /srv/samba/$1
chown $1:$2 /srv/samba/$1
chmod 775 /srv/samba/$1

How would I do this using FreeBSD?

  • 2
    Having glanced through the source, the simple answer is probably no. But since adduser(8) is a shell script, you could easily extend it. Alternatively, use your bash script to make a call to adduser(8) or pw(8) first. – Richard Smith May 18 at 15:01
  • 1
    Another way is to write a daemon that would use kevent syscall to monitor changes to /etc/passwd file and react on them. – arrowd May 19 at 7:56
  • On Unix systems, they are "directories" and not the Windows-ism of "folders" which is not the same thing. – Rob May 19 at 10:10
1

I followed Richard Smiths suggestion and solved my problem with a very simple shell script, which calls adduser(8) as well as pdbedit(8) and creates the corresponding directory.

#!/bin/sh

user=$1

# create user and add to SAM database
adduser $user
pdbedit -a $user

# create private samba directory
mkdir /srv/samba/$user
chown $user:$user /srv/samba/$user
chmod 775 /srv/samba/$user
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.