472,958 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

"Problem" with navigating in dirs with chdir...

22
I'm developing a very simple file server and client at school and have the following case.

The server maintains a current directory string and also holds a initial dir (which is a record of where the script was started from). The user is able to navigate in files and folders on the server, but should not be able to navigate outside the initDir.

My first idea was to keep the current dir in a temporary variable, change directory and check with strstr that the initDir is contained in the new current dir.

An example:
1. init=/home/user/test curr=/home/user/test => OK
2. inti=/home/user/test curr=/home/user/test/1 => OK
3. /home/user/test curr=/home/user/ => NOT OK
3. /home/user/test curr=/home/user/test/.. => NOT OK
3. /home/user/test curr=/home/user/test/../test => OK

The problem is the '..' which I thought would be gode when changing the dir, so that when you change currentdir with chdir(/home/user/test/../..) the value returned from getcwd would be /home/user/test/../..
Nov 19 '08 #1
3 1675
vmpstr
63
You can use realpath if it is available on your OS.

It takes 2 parameters, one the path you calculated (with, possible, some /.././) and the second is the output where it will store the best path that it can resolve.

Example:
char buf[] = "/local/home/directory/../../bin/";
char output[500];

realpath(buf, output);

printf("%s\n", output);

this will print out:
/local/bin/
Nov 19 '08 #2
krreks
22
You can use realpath if it is available on your OS.
Found the realpath function a little before i got the notification about your reply, but thanks a bunch anyway :)

BTW: Is there a reference on which operating system the different functions/libs is available?
Nov 19 '08 #3
vmpstr
63
Hmm... I was under the impression that the man pages will provide a section specifying which standard the function comes from, but I can't find one...

In my experience, if a function is in the 3rd section of man pages, then it is standard (C89/C99). If it is in the 2nd section, then it is POSIX... I'm more than certain that there are exceptions though.

Anyhoo, if it's in C89/C99, then it is available on all compilers (some don't support all C99 functionality well though). If it's POSIX, then you can expect to find it on most *nix systems (linux, unix), but you might have a harder time on windows.

I know this is a hand-wavey explanation, so hopefully someone has a better one.
Nov 20 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their...
0
by: Miki Tebeka | last post by:
Hello All, The following script "hangs" on win32 system: from Tkinter import * from tkSimpleDialog import askstring root = Tk() root.withdraw() # <<< Problem here askstring("Yap", "What's...
2
by: Alexander Bartzas | last post by:
I'm trying to compile route.cpp part of the NetBench Suite (UCLA) and...: > g++ packet.cpp radix.cpp route.cpp -o route There is no problem in the compilation of the code but when I try to run...
6
by: Fao | last post by:
Hi, I am in my first year of C++ in college and my professor wants me to Write a Program with multiple functions,to input two sets of user-defined data types: One type named 'Sign' declared by...
1
by: Shapper | last post by:
Hello, I am accessing a value in a XML value: news.Load(Server.MapPath("xml/ news.rss")) newslabel.Text = CType(news.SelectSingleNode("rss version=&quot;2.0 &quot;/channel/title").InnerText, String) ...
0
by: Norman Yuan | last post by:
I posted this issue a while ago. After moveing the ASP.NET 1.1 app to a brand new server, the same problem still there. System: Winows2003 server std. .NET 1.1 App: Invoicing system Problem:...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
1
by: eggie5 | last post by:
I am sending and receiving data from my client/server using the JSON format. However, it turns out, a lot of the time, that data has ":" or " ' " characters in it, which causes the the javascript...
3
by: katieh | last post by:
My website is made in flash. I have a dynamic image gallery within. How flash knows what to load into my gallery is it refers to my .xml document. Within flash, it displays the picture, and then in...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.