Click here to Skip to main content
12,954,403 members (64,809 online)

please help me program in linux

sara2013 asked:

Open original thread
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


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
Web02 | 2.8.170525.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
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