Setting umask for btsync?

Status
Not open for further replies.

Dan Sherman

Cadet
Joined
Apr 28, 2014
Messages
5
I have a cifs share with 4 users, all in one group. All of the permissions for the share are 660, and everything is great.

I'm trying to add a btsync plugin to sync the share with our laptops. I have it installed and running, and everything works the way it should, except for one debilitating problem: btsync sets the permissions on any file it adds to 644, so users on the LAN using the cifs share can't save changes.

The linux versions of btsync support a umask flag, but the BSD one doesn't yet. I monkeyed around with the rc.d script for btsync, trying to add `umask 002` manually, but it doesn't seem to work. I even installed a debian jail and the linux version of btsync, but that quickly became a huge headache, so I thought I'd ask around.

Am I missing something here?

PS. I saw this: http://forums.freenas.org/index.php?threads/btsync-plugin-permission-issue.18215/, but I can't get btsync to set permissions of 660.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
You could have the CIFS user match the btsync user. The btsync user is 'btsync' UID=817. You would need to a create a user in the FreeNAS userland with a matching UID.
 

Dan Sherman

Cadet
Joined
Apr 28, 2014
Messages
5
Thanks, that did it!


Sent from my iPhone using Tapatalk
 

raidoh

Dabbler
Joined
Jul 2, 2015
Messages
12
You could have the CIFS user match the btsync user. The btsync user is 'btsync' UID=817. You would need to a create a user in the FreeNAS userland with a matching UID.

I see this is an old thread, but I'm having the same problem, and I'm not sure what you mean by your solution, Joshua. I have several CIFS users accessing the files on the server. Are you recommending each user access the share with the same username/password? I can't do that since not all users have access to all datasets/directories, based on group permissions.

On the FreeNAS, I've setup the users, groups, and datasets, including btsync (UID817):btsync(GID817). On the BTSync jail, I also created btsync (UID817):btsync(GID817), as well as all of the groups with access to the datasets using the same GIDs for each one and btsync is a member of each group. In the Jail's /etc/rc.conf, I set btsync_user="btsync" and btsync_group="btsync" . The datasets are shared with the Jail using "Add Storage". As with the OP, everything seems to work, except files added through the BT Sync application are 755 (dirs) or 644 (files) when they would be 770 or 660 if added through the CIFS interface. One thing that does seem to work is that each file and directory has the correct GID (name and numerical ID) I setup for the datasets using find . -type d -exec chmod g+s {} \; from the root of the dataset (also with -type f for files), just not the correct permissions.

Any idea what I'm missing here?

BTW, I also figured out that I had to add btsync to the www group within the Jail in order to get Approval Requests to come through the web app, in case anyone was looking for that.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I see this is an old thread, but I'm having the same problem, and I'm not sure what you mean by your solution, Joshua. I have several CIFS users accessing the files on the server. Are you recommending each user access the share with the same username/password? I can't do that since not all users have access to all datasets/directories, based on group permissions.

On the FreeNAS, I've setup the users, groups, and datasets, including btsync (UID817):btsync(GID817). On the BTSync jail, I also created btsync (UID817):btsync(GID817), as well as all of the groups with access to the datasets using the same GIDs for each one and btsync is a member of each group. In the Jail's /etc/rc.conf, I set btsync_user="btsync" and btsync_group="btsync" . The datasets are shared with the Jail using "Add Storage". As with the OP, everything seems to work, except files added through the BT Sync application are 755 (dirs) or 644 (files) when they would be 770 or 660 if added through the CIFS interface. One thing that does seem to work is that each file and directory has the correct GID (name and numerical ID) I setup for the datasets using find . -type d -exec chmod g+s {} \; from the root of the dataset (also with -type f for files), just not the correct permissions.

Any idea what I'm missing here?

BTW, I also figured out that I had to add btsync to the www group within the Jail in order to get Approval Requests to come through the web app, in case anyone was looking for that.
I don't think you're missing anything here. The solution I presented wouldn't work for you because of the reason you mentioned.
As for setting the permission level btsync writes files as, if that were possible (like it is in transmission / sabnzbd) then you could tweak that and solve your issue, but I don't think it is. So I'm not sure of a solution for your situation.

EDIT

you might want to look into editing the init script /usr/local/etc/rc.d/btsync and setting the umask.
 
Last edited:

raidoh

Dabbler
Joined
Jul 2, 2015
Messages
12
My temporary solution until I can figure this out is that we can't write to those BT Sync directories using CIFS - you have to create a BT Sync share even for local users. I'll check over at the BT Sync forum.

Thanks anyway!
 

raidoh

Dabbler
Joined
Jul 2, 2015
Messages
12
I don't think you're missing anything here. The solution I presented wouldn't work for you because of the reason you mentioned.
As for setting the permission level btsync writes files as, if that were possible (like it is in transmission / sabnzbd) then you could tweak that and solve your issue, but I don't think it is. So I'm not sure of a solution for your situation.

EDIT

you might want to look into editing the init script /usr/local/etc/rc.d/btsync and setting the umask.

Joshua,

Thanks for the idea. I've tried setting the umask in /usr/local/etc/rc.d/btsync with a few syntax variations and restarting the Jail, but it hasn't appeared to affect the permissions of written files.
umask 0007
umask 007
:umask=007

They're all rwx:r--:r-- (644). It looks like there's a :umask=002 setting in /etc/login.conf (within the jail), but adjusting it doesn't seem to do anything either, which is not unexpected since the btsync user doesn't actually login.

The whole "/usr/local/etc/rc.d/btsync" file looks is below. Any idea of the needed syntax or perhaps placement within the file?

#!/bin/sh
#
# $FreeBSD: head/net-p2p/btsync/files/btsync.in 373424 2014-11-25 18:12:17Z crees $
#
# PROVIDE: btsync
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# btsync_enable (bool): Set to NO by default.
# Set it to YES to enable it.
# btsync_user: The user account btsync daemon runs as
# what you want it to be. It uses 'btsync'
# user by default. Do not sets it as empty or it
# will run as root.
# btsync_group: The group account btsync daemon runs as
# what you want it to be. It uses 'btsync'
# group by default. Do not sets it as empty or it
# will run as wheel.

. /etc/rc.subr
name="btsync"
rcvar="${name}_enable"
load_rc_config $name

: ${btsync_enable:="NO"}
: ${btsync_user:="btsync"}
: ${btsync_group:="btsync"}

pidfile="/var/run/btsync/btsync.pid"
command="/usr/pbi/btsync-amd64/bin/btsync"
command_args="--config /usr/pbi/btsync-amd64/etc/btsync.conf"

#added to set permissions on written files
:umask=007

start_precmd=btsync_prestart
btsync_prestart() {
if [ ! -d ${pidfile%/*} ]; then
install -d -o $btsync_user -g $btsync_group ${pidfile%/*}
fi
}

run_rc_command "$1"​
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
try adding the below in the btsync_prestart routine
Code:
umask 007


if that doesn't work perhaps freebsd forums would be a good place to ask.
 

betterfred

Cadet
Joined
Mar 4, 2016
Messages
5
try adding the below in the btsync_prestart routine
Code:
umask 007


if that doesn't work perhaps freebsd forums would be a good place to ask.

What/where is the btsync prestart routine? Did this work for anyone? This question on the FreeBSD forums went no where.

Accessing the CIFs share using the 'btsync' user is a solution, but I was hoping to add 'nobody' to the 'btsync' group to allow anonymous access.

Thanks!
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
What/where is the btsync prestart routine? Did this work for anyone? This question on the FreeBSD forums went no where.

Accessing the CIFs share using the 'btsync' user is a solution, but I was hoping to add 'nobody' to the 'btsync' group to allow anonymous access.

Thanks!
in /usr/local/etc/rc.d/btsync
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I'm not sure then how you could do it. the program is closed source so there's no where else you can really tweak stuff
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
I set a umask by changing the process that the rc script starts to my own script. That script sets the umask and starts btsync. I was unable to find any other method where the umask would apply to the btsync process.
I can post my "proxy" script later today.
 

bandroidx

Cadet
Joined
Oct 30, 2015
Messages
2
I set a umask by changing the process that the rc script starts to my own script. That script sets the umask and starts btsync. I was unable to find any other method where the umask would apply to the btsync process.
I can post my "proxy" script later today.

Hi just following up if you can post how you did this?

I am having a similiar problem except my problem is I am using NFS. Is there another way I could solve this via NFS? My files are being written by btsync as 644 and user 817 as everyone else has mentioned so when i am trying to delete/move files via nfs i get permission issues.
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
I'm setting a reminder to actually post this tonight. Sorry for the delay.
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
First, just enough of the rc script to show what I changed. Basically, just calling my umask script instead of the btsync binary.
Code:
pidfile="/var/run/btsync/btsync.pid"
#command="/usr/local/bin/btsync"
command="/usr/local/custom/btsync/btsync_umask.sh"
command_args="--config /usr/local/etc/btsync.conf"

start_precmd=btsync_prestart
btsync_prestart() {
        if [ ! -d ${pidfile%/*} ]; then
                install -d -o $btsync_user -g $btsync_group ${pidfile%/*}
        fi
}

run_rc_command "$1"


And here is the umask script. For whatever reason just putting the umask line before the binary call doesn't work, but calling both in a script does. It probably has to do with how the environment is set.
Code:
# cat /usr/local/custom/btsync/btsync_umask.sh 
#!/bin/bash

umask 002
/usr/local/bin/btsync "$@"
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
seems linuxy that you called bash. any reason you can't make that just 'sh'?
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
Probably not, just habit? Isn't sh usually just a link to bash anyway?
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
not in freebsd. /bin/bash doesn't even exist

but I guess it doesn't matter. the real mystery is why calling it in the main script doesn't work, lol
 

V.R

Cadet
Joined
Mar 26, 2017
Messages
7
just to ask, im about to try this, the new version of resilio renames the file and gets rid of the btsync_prestart routine, would the script be exactly the same?
 
Status
Not open for further replies.
Top