Write a program that sanitises a string in order to be suitable as command
line input to a shell script on Linux machines. The program should accept
an arbitrary string as input and check whether this string satises all of the
- it represents a file which is either a valid absolute pathname or is valid
in the current directory tree
- the file is owned by the same user as the user who executes the pro-
gram (the system call getuid() can be used to ascertain this). If an
argument does not represent a valid path, then the owner check is
obviously not relevant and should be omitted.
- the file is in a subdirectory of the home directory of the user. For this
exercise, you are not required to consider the resolution of symbolic
links, though it is an interesting exercise to do so if you wish (begin
with the system call lstat()).
- the string must not give rise to command execution when used in a
shell script. Hence the characters ; and must occur in this string
only if preceded immediately by the character ' , and the string must
not contain any newline character. In order to eectively test this
requirement, all of your programs command line input must
be enclosed in single quotes (').
- An example call to execute your program might, therefore, look like
hxq@hxq-N150P: ./ex1 /path/to/myfile meaning the input /path/to/-
le will be received by your program. Your program should output which
of these criteria are fullled and which ones are violated.