I want to make certain folders read-only for the developers while some subfolders in that folder as write also.
For example, consider the folder structure:
Meeting/Jan/DevInfo/
Meeting/Feb/DevInfo/
Meeting/March/DevInfo/
Meeting/April/DevInfo/
Meeting/May/DevInfo/
I want the developers to have read permission to //Meeting/ but write permission to //Meeting/.../DevInfo/...
Can I use the following code?
read group developers * //Meeting/...
write group developers * //Meeting/.../DevInfo/...
I think it should be correct, but visual in P4 shows that the whole structure of //Meeting/ is write-allowed for developers.
Change the write access line to:
write group developers * //Meeting/*/DevInfo/...
The * character means "all files within the Meeting directory, excluding subdirectories".
The ... entry that you had before means "all files and subdirectories under //Meeting", so it overrode the following DevInfo/... section.
Try running the following to check what the protection levels are:
p4 protects //Meeting/...
Related
In our organization perforce depot user permissions are managed through group text files. For each branch two type of files are maintained to manage the user permission under perforce version control itself. Both Write and Open permission file sample as follows.
ML_PROJECT_APPLICATION_WRITE.txt - For Write permission:-
# //DEPOT/ABCD/PROJECT/Jerd
# Permission: WRITE
dreac.leoson
ritu.bhangale
makyen
markerikson.s
bernardo.pereira
elitezen
ML_PROJECT_APPLICATION_OPEN.txt - For Open permission:-
# //DEPOT/ABCD/PROJECT/Jerd
# Permission: OPEN
areg.vera
bataklik
jeff.B
michael.chel
muthulakshmi.m
With above format we have multiple text files for each branch and now we need to remove the users permission from text file based on branch name list.
Branch name already available in our group text files. Now what is the best method remove the permission for each user? Is there any script to perform this action? since we have multiple users and branches.
I might suggest turning these text files into groups:
Group: ML_PROJECT_APPLICATION_WRITE
Users:
dreac.leoson
ritu.bhangale
makyen
markerikson.s
bernardo.pereira
elitezen
Group: ML_PROJECT_APPLICATION_OPEN
Users:
areg.vera
bataklik
jeff.B
michael.chel
muthulakshmi.m
and then specifying your protections table in terms of those groups:
Protections:
write group ML_PROJECT_APPLICATION_WRITE * //DEPOT/ABCD/PROJECT/Jerd/...
open group ML_PROJECT_APPLICATION_OPEN * //DEPOT/ABCD/PROJECT/Jerd/...
My recommendation would be to just use Perforce's interface directly rather than having your own file format and writing a script that translates it into Perforce commands, but if you do need to write that script it seems like a pretty straightforward pattern matching exercise.
There are tons of posts on the net saying that write permission on directory allows affected user to create/remove/rename files in that directory, but I found that it actually could not be done without execute permission set. I tried calling open/fopen/remove/rename, but without exception, they all failed.
There should be something I missed or something I misunderstood. There are some explanation that operations on directory usually involves with file operation. If it was right, I wonder what operation is involved. If directory maintains mappings from filename to inode, it seems no reason that file operation is involved when renaming.
If unexpected file operation is involved, is it possible to manipulate directory directly, bypassing such operations?
You are right, the net is full of wrong things and especially for unix file permission rules. The first links I found with a common search engine were all wrong. Very interesting!
What file permissions on directories means:
x you have "access" to the files in this directory which means you can use them. If you do not have read access but access rights, you can work with a file which you know but you can't see!
mkdir one
touch one/x.h
chmod -r one
ls one // fails!
cat one/x.h // works!
and write permission is used for changing the content of the directory. So adding and removing files from the dir is only possible if you have write permission on that dir!
Because it is impossible to read/write/execute a file which is inside a dir which you can't access, you always need access rights for the dir to work with the files inside.
Sounds a bit strange, but is simply implemented that way.
I have a few applications on Perforce and each application has a few branches. Right now only the latest branch is in actual use, the old ones are there for backtracking and debugging purposes.
Is there a way that I can disable the old branches so that no one can branch/use them?
Removing permissions to them is the best option. Since you want them to remain accessible as a historical reference, but NOT permit new changes, you'll want to remove the "write" level of permission but leave the "read" level:
write user * * -//depot/oldbranch/...
read user * * //depot/oldbranch/...
If only some groups have permissions to these branches in the first place you'd need to be careful of the placement of those lines to make sure you don't accidentally grant "read" permission to the other groups; that might mean doing something more like:
write group * * -//depot/oldbranch/...
read group dev * //depot/oldbranch/...
Or you could use the "=write" syntax instead:
=write group * * -//depot/oldbranch/...
You can also use "=branch" to prevent the old branch from being used as the source for new branches (the "=branch" permission is included with the "read" level unless you explicitly exclude it like this):
=branch group * * -//depot/oldbranch/...
For more on setting up permissions: http://www.perforce.com/perforce/r15.1/manuals/p4sag/chapter.protections.html
When I tried to simulate the permission system under Linux, some strange things came about.
I created a directory 'main' by user 'normal', and created directory 'aha' which permission is 700 using root.
so the owner of 'main' is 'normal', if the permission is 755, I can delete 'aha' just using 'normal' user although its owner is root.
but when i put a file in 'aha', everything is changed. I can not remove 'aha' due to there's still a file in it.
so, my question is, since 'aha' is 700 by root, how can 'normal' know it's empty or not?
My further question is : what does read permission of a directory really mean?
Think of a UNIX directory as a drawer of index cards in the library catalog.
In order to know what books there are, you need read permission on the "drawer". In order to create or remove new "books", you need write permissions (which give you ability to put new cards, or remove existing cards from the drawer). In order to "traverse" the directory to a lower level "sub-drawer", you need execute permission on the drawer itself.
If you already know that book /foo/bar/baz exists, you don't need read permissions on /, /foo or /foo/bar, but you do need execute permissions on all of them.
A given book could be referenced by multiple "cards" in the same or separate "drawer" (that's hard links).
A "card" can reference another card (that's symlinks). Symlinks could became "dangling" (if the other card is removed).
When a book is not referenced by any card in any of the drawers, it "evaporates" from the library.
since 'aha' is 700 by root, how can 'normal' know it's empty or not
Well, one way is to try to remove it. If you succeed, it must have been empty. If it was not empty, "normal" can't find out anymore than that, since "normal" can't read the directory, and therefore can't find how many cards are in that "drawer", or what they are called.
Update:
why do you need execute permissions to traverse a directory.
Because that's the definition of the eXecutable bit for directories. Since you can't reasonably execute a directory, that bit would be wasted otherwise. No, the . and .. files have nothing to to do with the execute bit.
very basically a file/dir permission of 700 is not seven hundred but actually
owner = 7
group = 0
everyone = 0
the numbers pertain to a permission level
0 = no permission
1 = allow to execute (run file or access directory)
2 = allow to write (manipulate)
4 = allow to read (see)
you add the permissions levels up to assign more then one permission for example
$ chmod 754 foo
gives full access to the owner (1+2+4), execute 'n' read to the group (1+4), and read to everyone (4) look at
http://www.linuxclues.com/articles/16.htm
http://www.tuxfiles.org/linuxhelp/filepermissions.html
for more info
My system administrators advice me to be careful when setting access control to files and directories. He gave me an example and I got confused, here it is:
a file with protection mode 644 (octal) contained in a directory with protection mode 730.
so it means:
File: 110 100 100 (owner, group, other: rw- r-- r--)
Directory: 111 011 000 (owner, group, other: rwx -wx ---)
How can file be compromised in this case?
It depends on what you mean by 'compromise' and it depends on who belongs to the group.
The directory permissions are critical. Since members of the group can access the directory ('x') and can modify the directory ('w'), even though they cannot list the directory (no 'r'), it means that if a member of the group knows the name of the file, that person can also remove it because removing a file requires permission to write to the directory - the file permissions are immaterial (even though commands such as 'rm' let you know when you don't have write permission on the file, that is a courtesy, because it doesn't matter to the 'unlink()' system call).
So, a member of your group (or, more precisely, a member of the group to which the directory belongs) can remove the file if they know its name. They can also read the file if they know its name, and they can create a file of the same name if the original is already missing. It appears from the file permissions that being able to read the file is not compromise - you would have denied group read access (and public read access) if that mattered.
Note that although your group members cannot modify the file, because they can delete the file and create a new one with the same name, the result is basically the same as being able to modify the file. One key difference is that you'd know which user did the mischief because that user would own the file. (Well, someone with access to that user ID did the mischief.)
Since the directory can be written to, the file could simply be overwritten with another if the attacker is in the directory owner's group.