Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C Linux GimmeCode
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 8-Oct-12 22:53pm
Edited 9-Oct-12 1:18am
markkuk11.9K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Go here[^] and start learning.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 340
2 Richard MacCutchan 265
3 BillWoodruff 225
4 Mathew Soji 155
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100