Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
please
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 satis es all of the
following conditions:
- it represents a file which is either a valid absolute pathname or is valid
in the current directory tree
- the fi le 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 fi le 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 e ectively 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 ful lled and which ones are violated.
Posted
Updated 9-Oct-12 0:18am
v2

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then ask a question about it - but do not post your homework question and expect us to do it for you.
 
Share this answer
 
Go here[^] and start learning.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900