CS810D Advanced Programming in the UNIX Environment Fall 2008 Quiz 5 FULL NAME ______________________________________ USERNAME ______________________________________ 1) The unlink system call "int unlink(const char *path)" has (possibly amongst others) the following effect: (2 points) A. The file at the given location is removed, making the data blocks the file consumed immediately available. B. The directory in which the given file resides is updated to remove the mapping of inode number to the filename portion of the given pathname. C. The datablocks associated with the inode of the given file are overwritten, allowing only processes with an open filehandle to read the file. D. The given character array is truncated at the directory portion of the pathname. E. All of the above. F. None of the above. Correct answer: (B) 2) What is the prototype of the function used by the parent process to retrieve the child's PID? (2 points) Correct answer: Does not exist. fork(2) returns the pid of the child to the parent. 3) Your process receives the signal SIGSTOP. You can do the following: (2 points) A. Catch it by providing a signal handler and perform some appropriate action. B. Cast it to SIGURG, so that a childs sigaction(2) can be invoked if necessary. C. Ignore the signal. D. All of the above. E. None of the above. Correct answer: (E) 4) Give two examples each (ie four in total) of a syslog facility and a syslog level. (4 points) Facilities: LOG_AUTH, LOG_AUTHPRIV, LOG_CRON, LOG_DAEMON, LOG_FTP, LOG_KERN, LOG_LPR, LOG_MAIL, LOG_NEWS, LOG_SYSLOG, LOG_USER, LOG_UUCP, LOG_LOCAL[0-7] Level: LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG 5) Give two different methods of determining the current size of a file, with brief code examples in C. (3 points for each correct solution) Solution: I) lseek to end of file if ((fdesc = open("/path/to/file", O_RDONLY)) == -1) { fprintf(stderr, "%s: Can't open file: %s\n", argv[0], strerror(errno)); return 1; } if ((n = lseek(fdesc, 0, SEEK_END)) == -1) { fprintf(stderr, "%s: Can't seek to end: %s\n", argv[0], strerror(errno)); return 1; } printf("File contains %d bytes\n", n); II) stat the file: struct stat sb; int n; if ((n = stat("/path/to/file", &sb)) == -1) { fprintf(stderr, "%s: Can't stat the file: %s\n", argv[0], strerror(errno)); return 1; } printf("File contains %d bytes\n", (int)sb.st_size); 6) What are the three essential ares in which encryption techniques can provide security? For each, include a simple english sentence or question describing what feature is provided. Correct answers: Authenticity -- Is the person I'm talking to who I think it is? Accuracy or Integrity -- Is the message I received in fact what was sent? Secrecy or Confidentiality -- Did/could anybody else see the message?