How to tell Samba not to create a new file when the file being modified is a symbolic link?

I have a file:

/home/elvin/share.xls with the following permission: -rwxrwxr--

I share it with members of my group; they make a symbolic link of the file on their own directory, say:

/home/grpmate1/share.xls -> /home/elvin/share.xls

and the resulting permission is lrwxrwxrwx.

Update of the file is being done on Windows platform thru Samba. The problem is, when grpmate1 updates and saves the file, the symbolic link is replaced by a new file that is resident to his own directory:

/home/grpmate1/share.xls with permission -rwxrwxr--

His modifications will not reflect on my file, because it is no longer linked.

How can I tell Samba that it is a symbolic link and should not be replaced by a new file?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it's because when excel try to save the file into the directory not the file, and the same name appear, so the real file saved into the directory instead.

I will suggest you create another folder said /share and put this file into it and share out for all the group member of grpmate1 this will be more save.


        comment = share folder for grpmate1
        path = /share
        force group = grpmate1
        read only = No
        create mask = 0770
        directory mask = 0770
        guest ok = no

so that all the file here will share in between the same group of grpmate1 and updated when change.
and you could link each person to that share directory, to make it more transparent to them:

cd /home/username
ln -s /share

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elvin226Author Commented:

The configuration for share doesn't work because Samba is using the default setting for homes. In other words, it doesn't override the setting for homes.

  comment = Home Directories
  browseable = no
  read only = no
  force create mode = 0774

I said that because the file permission becomes 0774 instead of 0770 and the owner of the file becomes grpmate1, although the link or sharing still works.

I would like to see the share setting to work before I give the points. :)
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

But I think you can create the /share (or whatever you want to name) directory and share it out through samba, after you create the /share directory and add the share into your /etc/samba/smb.conf as I suggested, than restart your samba service '/etc/rc.d/init.d/smb restart'.

or as majorwoo suggest, you put all the share file(s) into the /share directory and build a symbolic link in eash users directory (those users who will share use the file(s) ), so that you can keep your config as it is (i.e. no need to add any share in your /etc/samba/smb.conf (the samba config file) and restart the samba service ), so that when user(s) login they will get into their home directory and get into the share directory to make change to the file.
The difference bewteen my suggestion and majorwoo.

I used the samba service to share out a share directory so that those users will got 2 shared, one is their home directory, the second one is for comment use between those users, and you need to add group into those users eg.

groupadd share                    < this will add a new group called share into the system
usermod -G share paul          < if user paul alread added, this will make paul become the member of share
useradd  -g paul,share paul   < of user paul not add, this will make paul become the member of his own and share

and I used the create mode 0770, this will only allow the owner and the member of the group can access the files, others can't including read.

majorwoo (I hope I havn't miss understand your meaning), suggest to build the symbolic link, which you no need to add any group, but you need to have the rwxrwxrwx for the /share, and put a symbolic link on each appointed user's home direcotry, eg.

cd /home/paul
ln -s /share share

so when the paul login, he will have a folder like in his home directory called share, but the files paul create/edit may create a admin issue, since the system will put rwxr-xr-x after the file save, but I can't remember the work around for this, I think is something like the 'chroot' can make change on this, but sorry really can't remember how to, majorwoo any idea?
There are a number of ways to do it as suggested.  Personally I use both of those we are talking about here.  I share a folder /share for my users, however some of them have no idea that anything exists outside of their home directory so I put a link to it in their directory.

I would use a group (and I do) for that purpose as Paul showed - it's fairly easy to add a group and add users to the group, although I usually just edit the file directly, it seems quicker to me:

groupadd share
and then edit /etc/group
and add the people you need to it:
elvin226Author Commented:

"the files paul create/edit may create a admin issue, since the system will put rwxr-xr-x after the file save, but I can't remember the work around for this"

That is exactly what I meant when I say:

"the file permission becomes 0774 instead of 0770 and the owner of the file becomes grpmate1"

I have no problems in creating groups, that is no longer my issue.

My problem is since I'm using Samba, and Samba automatically uses the setting for [homes] and ignores the [shared], every file that has been modified becomes owned by the one who saves it. This should not be the case. How can I solve it?

To make things clearer:
paul, major and elvin are members of the group 'ourgroup'.

elvin has a file that he wants to share with paul and major:
-rwxrwxr--    elvin   ourgroup   /home/elvin/shared/myfile.txt

when paul edits the file, it becomes:
-rwxrwxr--    paul   ourgroup   /home/elvin/shared/myfile.txt

when major edits the file, it becomes:
-rwxrwxr--    major   ourgroup   /home/elvin/shared/myfile.txt

So whoever edits the file becomes the owner. I don't want that to happen. Why does Samba do it?
Ahh, ok we were all on different pages here.  This I have never seen before:

can you paste your smb.conf here to lookover (granted it's large)
elvin226Author Commented:
Here it is:

; /etc/smb.conf
; Make sure to restart the server after making any changes.
; /etc/rc.d/init.d/smb stop
; /etc/rc.d/init.d/smb start

; Uncomment this if you want a guest account.
; guest account = nobody
log file = /var/log/samba.log
lock directory = /var/lock/samba
share modes = yes
encrypt passwords = yes
smb passwd file = /etc/smbpasswd

comment = Home Directories
browseable = no
read only = no
force create mode = 0774

comment = Shared Folder
path = /home1/elvin/shared
read only = no
force user = elvin
force create mode = 0770

Note that I defined a user parameter so that everytime the file is saved the owner would be me, granted that my assumption is correct, but as I said [shared] has never been used. It's always [homes].

-rwxrwx---    elvin     ourgroup    /home1/elvin/shared/myfile.txt
-rwxrwxr--    paul     ourgroup     /home1/elvin/shared/myfile.txt
-rwxrwxr--    major   ourgroup    /home1/elvin/shared/myfile.txt

force user (S)
This specifies a UNIX user name that will be assigned as the default user for all users connecting to this service. This is useful for sharing files. You should also use it carefully as using it incorrectly can cause security problems.

This user name only gets used once a connection is established. Thus clients still need to connect as a valid user and supply a valid password. Once connected, all file operations will be performed as the "forced user", no matter what username the client connected as. This can be very useful.

In Samba 2.0.5 and above this parameter also causes the primary group of the forced user to be used as the primary group for all file activity. Prior to 2.0.5 the primary group was left as the primary group of the connecting user (this was a bug).

See also

Default: no forced user

Example: force user = auser

So your file(s) should force to elvin upon you smb.conf.

If you using samba 3.x there is an option called username map have a look below

username map (G)
This option allows you to specify a file containing a mapping of usernames from the clients to the server. This can be used for several purposes. The most common is to map usernames that users use on DOS or Windows machines to those that the UNIX box uses. The other is to map multiple users to a single username so that they can more easily share files.

Have a check on the samba 3.x manual

But I'm still thinking there is bug in samba which make the problem you got.
elvin226Author Commented:
although the problem on file ownership has not been solved yet, the file sharing works--as long as the default permission gives modification privelege to group members.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.