Click here to Skip to main content

sara2013 asked:

Open original thread
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.
Tags: C++, C, Linux, GimmeCode

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid