Sixth FAQ

for

Project 3 -- POSIX Files, Directories, and Permissions

Q. You have explained clearly on the website on directory synchronization. But can I ask one more question? Do we need to make the time of last modification of each directory (also including their subtree) identical like what we did on filesynchronization. When I run my my program, I found after synchronization (with -r) the content of directory (including subtree) are 100% identical except theirtime.

A. No, you don't have to worry about the time of last modification of the directories, although you are allowed to update those, if you'd like to. However, each ordinary file within each directory and subdirectory must have its time updated.


Q. We just wanted to clear off this doubt about the teamsync function. If I am using the teamsync with two directories,one of mine and the other of my mate. Is that the files that are only in my directory and his dir(which match,i mean same file names)need to be changed?? or and apart from that do all the files that are not present in my directory (extra files he has)need to be get into my account(in that case its really unsafe since i can copy all of his files without his permission,right??? let me know this.

A. All the files in your teammate's directory that are not present in your directory (extra files that your teammate has) need to be copied to your directory.

Is this unsafe? Note that the assignment says, "The teamsync utility will only allow files to be copied from teamsyncdir or directories below teamsyncdir." If your teammate is smart, he or she will only put files that he or she wants you to access in teamsyncdir or directories below teamsyncdir. Those files that he or she doesn't want you to have, he or she will put in other directories. So, if you write teamsync according to the assignment, it can be used safely.


Q. Setting the effective user ID.

Why do we use it?-What is the purpose if the conditions under "If the user running teamsync is listed (by user ID) in syncteam..." exist?

When do we need to use it?

On page 122 in the UNIX book, it says "/* set effective user-id */
status = setuid(newid);
"
Which one are we supposed to use?(setuid or seteuid)

Can you show some syntax on how to use it? The book only gives little information.

A. Wow, talk about the last minute! You have waited until well after the original due date for the project to find out some of the fundamentals of the assignment!

Okay, why do we need to set the effective user ID? Let's think for a minute what we are trying to do with teamsync.

The assignment says that teamsync "will be used to synchronize files and directories belonging to a different users who are members of the same team." Now, if the files and directories were readable and writeable by everyone on the system, we wouldn't need a special program called teamsync -- we could just use fssync (and add a flag so that the copying only goes "one way," which is what those conditions you refer to are doing). Further, I hope everyone in this course has figured out by now that making files and directories readable and writeable by everyone on the system is a very bad idea in general. So, we need some way to prevent just anyone on the system from reading or writing our files, while still allowing our teammates to get the latest versions of the files that we are working on together.

If this sounds familiar, it should. This was all spelled out in FAQ 4 for this assignment. Please read the FAQs!

Okay, so we need to have some way to share the files just with our team members. We could ask the system administrator to create a group for us, then set group read, write, and/or execute permissions on these files. However, this assignment is showing us another way we can do it: We create files and directories that only the owner can read, write, and/or execute, then create a program that can pretend to be the owner of those files when reading them.

This should make the answer to your second question obvious. When do we need to set the effective user ID? When we are reading the files and directories in question.

Should we use setuid() or seteuid()? You are right that the book doesn't say much about these functions. Isn't it nice that we have man pages? As a careful reading of the appropriate man pages indicates, setuid() and seteuid() will function equivalently as long as the effective user ID of the calling process is not the super-user. This means that, when you write and test your code, you won't see any difference, regardless of which of these system calls you choose to use. However, this does not mean that you can just choose either one at random. Instead, you should think about what should happen if the effective user ID of the calling process is the super-user.

If the effective user ID of the calling process is the super-user and you use setuid(), "the real, effective, and saved user IDs are set to the uid argument" (as explained in the man page). If the effective user ID of the calling process is the super-user and you use seteuid(), then the only one of these values that could be changed is the effective user ID. Which would make sense? Reason about this. Think about how teamsync should work for two users who are not the super user, then ensure that same behavior exists when one of the users is the super-user.

As for the syntax on how to use setuid() and seteuid(), this is quite straightforward. The man pages show the syntax as:

    int setuid(uid_t uid);
    int seteuid(uid_t euid); 

You put in for uid or euid the value that you want to change to and get the normal return value of 0 if it succeeds or -1 if it fails.


Q. Our team is trying to figure out what the program should do when the -q flag is set. Some of us think that even if the -i and -c (or even -r) flags are set, the program should not even show the prompts for you to create or overwrite files or directories (just doing it automatically, in other words overriding the -c and -i flags), while some of us think that it should still show prompts and just not show the copying output. We've heard people tell us both ways, so we would appreciate some clarification. Thanks!

A. Whoever is telling you that the -q flag overrides the -c and -i flags hasn't read the assignment carefully.

Note that the description of the -q flag says that it will cause fssync (or teamsync) to "[q]uietly run so as not to print any of the messages specified above." Note the last word of that sentence -- "above." The prompts for the -c and -i flags are messages that are specified in the assignment below the description of the -q flag and therefore would not be included in the messages that -q prevents the utility from printing.

Also, note that the example shows the -q flag being used in conjunction with both the -c and -i flags to invoke fssync and says that this would "quitely, recursively, and interactively invoke fssync." If the -q flag overrode the -c and -i flags, then this example would only quitely and recursively invoke fssync. The fact that it says that it interactively invokes fssync should make it clear that -q does not override -i.