2

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?

3
  • 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. Commented May 18, 2020 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. Commented May 19, 2020 at 7:56
  • On Unix systems, they are "directories" and not the Windows-ism of "folders" which is not the same thing. Commented May 19, 2020 at 10:10

1 Answer 1

3

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 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.