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?

kundev
  • 51
  • 5
  • 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 '20 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 '20 at 07:56
  • On Unix systems, they are "directories" and not the Windows-ism of "folders" which is not the same thing. – Rob May 19 '20 at 10:10

1 Answers1

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
kundev
  • 51
  • 5