[SOLVED] C : How to block opening files "above" a specified directory?
SOLVED: Used
man 3 realpath
Hello Archers,
I have this one problem I've been struggling with. I kind of solved it but the solution's hackish.
My question is how do you prevent the opening of files "above" a specified directory? The reason behind this is that I'm writing a simple sharing server, something like Xyne's quickserve, but in C and with a GTK GUI. I'm using the libmicrohttpd library.
The program works this way: the user selects a port and a directory to be "served", and then he can access the files under the directory he chose. However, there obviously needs to be a way to prevent the user from opening files above the directory by using ".."'s for example.
For now, I simply plan on rejecting all queries containing ".." (http://github.com/houbysoft/quickshare/ … hare.c#L59), but that's obviously very imperfect -- and you could get around it if there is a symlink in the directory for example.
Any pointers will be very appreciated, thanks.
Last edited by y27 (2010-03-17 02:59:14)
tavianator wrote:
man realpath wrote:BUGS
The POSIX.1-2001 standard version of this function is broken by design, since it is impossible to
determine a suitable size for the output buffer, resolved_path. According to POSIX.1-2001 a buffer
of size PATH_MAX suffices, but PATH_MAX need not be a defined constant, and may have to be obtained
using pathconf(3). And asking pathconf(3) does not really help, since, on the one hand POSIX warns
that the result of pathconf(3) may be huge and unsuitable for mallocing memory, and on the other
hand pathconf(3) may return -1 to signify that PATH_MAX is not bounded. The resolved_path == NULL
feature, not standardized in POSIX.1-2001, but standardized in POSIX.1-2008, allows this design
problem to be avoided.
So be careful to either pass resolved_path as NULL and bite the potential unportablilty bullet, or copy canonicalize_file_name or canonicalize_filename_mode from gnulib.
Yeah, I am passing NULL.
Similar Messages
-
How can i open file from adobe reader..i already have adobe read
how can i open file from adobe reader..i already have adobe reader installed and cannot open a
file and i cannot convert my file into pdf..Is the file really a PDF? Where is it? Have you tried opening it from within Reader?
-
How do I open files in InDesign CS5.5 CS5?
How do I open files in InDesign CS5.5 CS5?
Hi, are you trying to open up a CS5.5 document in CS5? If so you need to export the docment while in InDesign CS5.5 to the IDML format.
Please refer to this document: http://help.adobe.com/en_US/indesign/cs/using/WSa285fff53dea4f8617383751001ea8cb3f-6d52a.h tml#WSa285fff53dea4f8617383751001ea8cb3f-6d4da -
How can I OPEN files I just downloaded? They're on the DOWNLOADS screen of Firefox but I can't open them even after double-clicking? And they're not on the FOLDERS as well. Even the right-click is not working ... the "open containing folder" does not work.
== This happened ==
Not sure how often
== ALWAYS! ==
== User Agent ==
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.5; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)Open Containing Folders is never active.
-
How do I open files from an external drive? It's plugged into the second slot to the end. Did I plug it into the right place and how do I find the drive when trying to attach a file in an email?
Files on an external hard drive open just like files on the internal drive - but I get the idea that you are having a problem just finding and seeing those files. Is that correct?
What operating system is running on your MacBook? -
CS6, how do I open files in Bridge directly into Photoshop. The default is File Viewer or there is an option to open in Adobe RAW.
Look at the down pointing arrow to the right of Photoshop CC in the list. Clicking on it shows a list of programs to select from.
Windows OS level or "in Windows" as opposed to "in Bridge".
Gene -
How can I open file; such as create other programme(Dream weaver...etc)?
One of my friend will make website for me soon...(She is not Mac user...I think she will use dream weaver or other tools)
So...I want take that file open in iweb09' is it possible?Imagine iWeb as a database which upon your command creates html files. It's a one-way process. You can generate more html files later but iWeb cannot open them. It only works with the "database" (the domain file).
-
How do I open files made on a Mac on my PC?
How do I open files made on a Mac on my PC? Someone mentioned Platform?
The files should just open. Which Adobe program are you asking about?
-
How to view the file content from the directory? getting Error:ORA-21560
SQL> create directory READ_LOB_DIR as 'D:\Prj\Comm\Data';
CREATE OR REPLACE Procedure READ_FILE_LOB IS
-- Input Directory as specified in create directory
l_dir CONSTANT VARCHAR2(30) := 'READ_LOB_DIR';
-- Input File which is read word by word
l_fil CONSTANT VARCHAR2(30) := 'testfile.txt';
-- Separator Character between words is a BLANK (ascii = 32)
l_seb CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(32));
-- Character at the end of the file is NEWLINE (ascii = 10)
l_sen CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(10));
-- Pointer to the BFILE
l_loc BFILE;
-- Current position in the file (file begins at position 1)
l_pos NUMBER := 1;
-- Amount of characters have been read
l_sum BINARY_INTEGER := 0;
-- Read Buffer
l_buf VARCHAR2(500);
-- End of the current word which will be read
l_end NUMBER;
-- Return value
l_ret BOOLEAN := FALSE;
BEGIN
-- Mapping the physical file with the pointer to the BFILE
l_loc := BFILENAME(l_dir, l_fil);
-- Check if the file exists
l_ret := DBMS_LOB.FILEEXISTS(l_loc) = 1;
IF (l_ret) THEN
dbms_output.put_line('File ' || l_fil || ' in Directory ' || l_dir ||
' exists');
-- Open the file in READ_ONLY mode
DBMS_LOB.OPEN(l_loc, DBMS_LOB.LOB_READONLY);
LOOP
-- Calculate the end of the current word
l_end := DBMS_LOB.INSTR(l_loc, l_seb, l_pos, 1);
-- Process end-of-file
IF (l_end = 0) THEN
l_end := DBMS_LOB.INSTR(l_loc, l_sen, l_pos, 1);
l_sum := l_end - l_pos - 1;
DBMS_LOB.READ(l_loc, l_sum, l_pos, l_buf);
dbms_output.put_line(UTL_RAW.CAST_TO_VARCHAR2(l_buf));
EXIT;
END IF;
-- Read until end-of-file
l_sum := l_end - l_pos;
DBMS_LOB.READ(l_loc, l_sum, l_pos, l_buf);
dbms_output.put_line(UTL_RAW.CAST_TO_VARCHAR2(l_buf));
l_pos := l_pos + l_sum + 1;
END LOOP;
DBMS_LOB.CLOSE(l_loc);
ELSE
dbms_output.put_line('File ' || l_fil || ' in Directory ' || l_dir ||
' does not exist');
END IF;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error:' || SQLERRM);
DBMS_LOB.CLOSE(l_loc);
END;
The Text file content is...
Copyright 1996,2001 Oracle Corporation. All Rights Reserved
This file contains installation instructions for installing the
Oracle8 ODBC Driver software.
It is divided into four parts:
o Part I: Summary of systems supported by Oracle8 ODBC client
software
Lists the platforms on which the Oracle8 ODBC Client software can
be installed.
o Part II: Oracle8 ODBC Driver software.
Describes the files, and installation prerequisites for the Oracle8
ODBC driver software.
o Part III: Exploding the kit onto your system
Describes how to explode the kit onto your system hard drive.
o Part IV: Installation Instructions
Describes how to install the Oracle8 ODBC driver.
Part I: Systems supported by the Oracle8 client software
You can install the ODBC client software on any of the following systems:
o Windows 2000
o Windows NT X86
o Windows 95
o Windows 98
The Oracle8 ODBC Driver provides support for ODBC connections
from Windows 2000, Windows NT, Windows 95, and Windows 98 systems
to Oracle databases.
o Part II: Oracle8 ODBC Driver software.
Refer to the following files for information about the Oracle8 ODBC Driver:
LICENSE.TXT - Oracle8 ODBC Driver License Agreement. Read carefully
before installing and/or using this product. Enclosed in
your software distribution kit.
SQORA.HLP - A Window's Help file which is the primary reference
manual for the Oracle8 ODBC Driver.
ODBCRelnotes.WRI - The release notes for the Oracle8 ODBC Driver
which contains information which may have not been
included in the Help file.
Installation Prerequisites
See the Oracle8 ODBC Driver release notes (ODBCRelnotes.WRI),
for a complete list of software products required and their versions.
Time Required
The installation of the Oracle8 ODBC Driver takes approximately 5
minutes. The actual time may be shorter or longer, depending upon
your hardware configuration.
Disk Space Required
The Oracle8 ODBC driver installation requires approximately 2
megabytes of available storage space. The space required depends upon
what files you already have installed. The installation procedure
checks to see if you have enough available disk space. If you do not,
the installation fails.
Part III: Exploding the Kit onto your system
Expand the self-extracting archive file onto your hard drive.
C:\> ORA8174.EXE
Part IV: Installation Instructions
Oracle8 ODBC Driver 8.1.7.4.0
This section assumes the following:
1. MS Windows 2000, Windows NT, Windows 95 or Windows 98 is running.
2. Oracle Universal Installer shipping with 8.1.7 has already been
installed on your system.
3. Part III has been completed.
Software fixes:
Refer to release notes (ODBCRelnotes.wri) for a complete list of
Software fixes.
Installation Instructions
Once the self-extracting archive file ORA8174.EXE has been
exploded it will create an installable directory structure
onto your hard drive. Run the Oracle Universal Installer from
your local drive.
1. On the screen "File Locations" use the "Browse" button of
the source path to choose the file 'products.jar' from the
folder that ORA8174.EXE was extracted to. Choose 'Next'.
2. You will receive a warning that some of the dependencies of
this product are not found in the staging area. This warning
is OK. The ODBC driver depends on the Net8 Client being already
installed on the system. Answer 'Yes' to continue.
Oracle is a registered trademark of Oracle Corporation.
Microsoft, MS are registered trademarks of Microsoft Corporation.
Microsoft Windows, Windows NT, Windows 95, Windows 98 and Open Database
Connectivity are trademarks of Microsoft Corporation.
All other trademarks and registered trademarks are the property
of their respective owners.
The output was...
File testfile.txt in Directory READ_LOB_DIR exists
Copyright
1996,2001
Oracle
Corporation.
All
Rights
Reserved
This
file
contains
installation
instructions
for
installing
the
Oracle8
ODBC
Driver
software.
It
is
divided
into
four
parts:
o
Part
I:
Summary
of
systems
supported
by
Oracle8
ODBC
client
Error:ORA-21560: argument 2 is null, invalid, or out of range
I want to diplay/view as per file content format from the file under that specified directory.
Have any other method / any help or suggestions would be really appreciated.I changed the code like...
CREATE OR REPLACE Procedure READ_FILE_LOB_tmp IS
-- Input Directory as specified in create directory
l_dir CONSTANT VARCHAR2(30) := 'READ_LOB_DIR';
-- Input File which is read word by word
l_fil CONSTANT VARCHAR2(30) := 'testfile.txt';
-- Separator Character between words is a BLANK (ascii = 32)
l_seb CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(32));
-- Character at the end of the file is NEWLINE (ascii = 10)
l_sen CONSTANT RAW(100) := UTL_RAW.CAST_TO_RAW(CHR(10));
-- Pointer to the BFILE
l_loc BFILE;
-- Current position in the file (file begins at position 1)
l_pos NUMBER := 1;
-- Amount of characters have been read
l_sum BINARY_INTEGER := 0;
-- Read Buffer
l_buf VARCHAR2(4000);
-- End of the current word which will be read
l_end NUMBER;
-- Return value
l_ret BOOLEAN := FALSE;
BEGIN
-- Mapping the physical file with the pointer to the BFILE
l_loc := BFILENAME(l_dir, l_fil);
-- Check if the file exists
l_ret := DBMS_LOB.FILEEXISTS(l_loc) = 1;
IF (l_ret) THEN
dbms_output.put_line('File ' || l_fil || ' in Directory ' || l_dir ||
' exists');
-- Open the file in READ_ONLY mode
DBMS_LOB.OPEN(l_loc, DBMS_LOB.LOB_READONLY);
LOOP
-- Calculate the end of the current word
l_end := DBMS_LOB.INSTR(l_loc, l_sen, l_pos, 1);
-- Process end-of-file
IF (l_end = 0) THEN
EXIT;
END IF;
-- Read until end-of-file
l_sum := l_end - l_pos;
DBMS_LOB.READ(l_loc, l_sum, l_pos, l_buf);
dbms_output.put_line(UTL_RAW.CAST_TO_VARCHAR2(l_buf));
l_pos := l_pos + l_sum + 1;
END LOOP;
DBMS_LOB.CLOSE(l_loc);
ELSE
dbms_output.put_line('File ' || l_fil || ' in Directory ' || l_dir ||
' does not exist');
END IF;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error:' || SQLERRM);
DBMS_LOB.CLOSE(l_loc);
END;
Now its working fine with one addtional line...
The file content is...
This is My Content
This is My Content
This is My Content
This is My Content
This is My Content
But The output was...
File testfile.txt in Directory READ_LOB_DIR exists
This is My Content
This is My Content
This is My Content
This is My Content
This is My Content
here, i want to delete that additonal line...? -
Open files from a specific directory
Dear all,
I have the following source code that simply selects files from a directory.
private void openFile()
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(
JFileChooser.FILES_ONLY );
int result = fileChooser.showOpenDialog( this );
// user clicked Cancel button on dialog
if (result == JFileChooser.CANCEL_OPTION )
return;
File filename = fileChooser.getSelectedFile();
if (filename == null || filename.getName().equals( "" ))
JOptionPane.showMessageDialog( this,
"Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE );
else
// open the file
try
// Open an input stream
FileInputStream fin1 = new FileInputStream(filename);
// Read and print a line of text
BufferedReader d1 = new BufferedReader(new InputStreamReader(fin1));
abs = d1.readLine();
outputArea1.setText("");
outputArea1.append(abs + "\n\n");
outputArea1.setCaretPosition(0);
// Close our input and output stream
fin1.close();
catch (IOException e5) {
JOptionPane.showMessageDialog(this, "Error Opening File", "Error", JOptionPane.ERROR_MESSAGE);
} // end catch
} // end else
} // end private
My question is: Can I force it to open files from a specific directory, and NOT from MyDocuments directory????
thanks,
vxc\r = return
\n = linefeed
\j = illegal escape character
JFileChooser fileChooser = new JFileChooser("C:\j2sdk1.4.2\bin");
You could/should use:
(new File).pathSeparator
or
(new File).pathSeparatorChar
and
(new File).separator
or
(new File).separatorChar
http://java.sun.com/j2se/1.4.1/docs/api/java/io/File.html -
How to print out all files in a specified directory
Now, I have some problem which prints out the entire content of all of the .txt files in a specified directory.
what method i can use?
Can anyone give me some examples?
Many ThanksRead the API for java.io.File, in particular the list and listFiles methods, and java.io.FilenameFilter.
-
How to systematically open file in a folder and process them with a program
Hello,
For my second question of the night.
I am wondering if there is a way to open every file in a folder, run them through a vi, and then append the output to an array or spreadsheet? This would save me lots of time and my wrists.
Thanks
Solved!
Go to Solution.Hi,
Yes you can open a file in the folder by using 'List folder' function (Programming>File I/O>Advvanced File Function>List Folder) which lists all the files and folders in the given path. From that you can build the path and give to 'Open File' function.
Hope this helps you. Let us know this solves your issue -
[Solved][VIM] E484: Can't open file syntax.vim
Hi all,
I've installed Archlinux few days ago on my netbook and yesterday i decided to configure Vim using plugins.
During plugins configuration, i messed up and i decided to revome all Vim files in my ~ folder in order to restart configuration.
However, since I've executed the `rm -R .vim .vimrc .viminfo` command, I can't re-activate Vim's syntax coloration using `syntax on` into my .vimrc file nor into Vim directly.
Here is the error message when I start Vim :
Error detected while processing /home/romain/.vimrc:
line 1:
E484: Can't open file /home/romain/.vim/syntax/syntax.vim
Press ENTER or type command to continue
I've found this topic on BBS which seems to be the same problem as me but reinstalling vim or vi doesn't solve this problem.
I've tried to copy this syntax.vim file from /usr/share/vim/vim73/syntax/syntax.vim but it doesn't solve the problem and I want a clean solution without hacking my ~ folder ; moreover, this bug also appears being root while I haven't configured vim with the root account so it may be a problem into Vim's installation folders or something.
Thanks for your help and sorry I my english contains mistakes,
MicroJoe.
Last edited by MicroJoe (2012-06-14 16:16:45)This is the output :
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jun 7 2012 00:41:40)
Rustines incluses : 1-547
Compilé par ArchLinux
Grosse version sans interface graphique.
Fonctionnalités incluses (+) ou non (-) :
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
+conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs
-dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path
+find_in_path +float +folding -footer +fork() +gettext -hangul_input +iconv
+insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape
+mouse_dec +mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse
+mouse_xterm +mouse_urxvt +multi_byte +multi_lang -mzscheme -netbeans_intg
+path_extra +perl +persistent_undo +postscript +printer -profile -python
-python3 +quickfix +reltime +rightleft -ruby +scrollbind +signs +smartindent
-sniff +startuptime +statusline -sun_workshop +syntax +tag_binary
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
-toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
-xterm_clipboard -xterm_save
fichier vimrc système : "/etc/vimrc"
fichier vimrc utilisateur : "$HOME/.vimrc"
fichier exrc utilisateur : "$HOME/.exrc"
$VIM par défaut : "/usr/share/vim"
Compilation : gcc -c -I. -Iproto -DHAVE_CONFIG_H -I/usr/local/include -march=i686 -mtune=generic -pipe -fstack-protector --param=ssp-buffer-size=4 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Édition de liens : gcc -Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu -L/usr/local/lib -Wl,--as-needed -o vim -lm -lncurses -lacl -lattr -lgpm -ldl -Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,--hash-style=gnu -fstack-protector -L/usr/local/lib -L/usr/lib/perl5/core_perl/CORE -lperl -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
(I've noticed that some part were in French but I hope that it'll not be a problem). -
How can I open files from Appleworks and Pages 4.3 in Mavericks?
I have documents I created in Appleworks and Pages 4.3 that I can't open in Pages 5.1 using Mavericks. How can I open those files?
Mavericks is the Operating System (OSX).
LibreOffice [free] may be able to open your AppleWorks files but probably not perfectly.
Pages '09 should still be in your Applications/iWork folder.
Pages 5 can open Pages '09 files but will alter/damage them.
Peter -
How to find Open Files by a Process Solaris 10
Hi,
Hope you are doing well.
I'm trying to get open files by a process in solaris 10 using "pfiles" with below command:
pfiles -n `ps | grep -i "data -log" | grep -v grep | grep -i uatrate | awk '{print $2}'` | wc –l
When I put this in some shell script like below then this command is not giving any output. Your assistance is required in this. Please guide me so that I can get the Count of Open files by some process.
I made some script, Its working fine but its giving the output for whole processes:
#!/bin/ksh
let "TOTAL_OPENED=0"
for A_PID in `ps | grep -i "data -log" | grep -v grep | grep -i uatrate | awk '{print $1}'`; do
FILES_OPENED=`/usr/proc/bin/pfiles -n $A_PID 2>/dev/null| grep "ino:" | wc -l`
let "TOTAL_OPENED = TOTAL_OPENED + $FILES_OPENED"
done
echo "Opened files = $TOTAL_OPENED"
Many Thanks in advance.
Imran Qasim.Have you tried "man top" to see the documentation for the top command?
How about the following: http://lmgtfy.com/?q=show+memory+with+top+command
The 5th column (VIRT) shows the amount of RAM + swap
The 6th column (RES) shows RAM
The 7th column (SHR) shows memory shared between processes
Maybe you are looking for
-
Aperture library's have stopped showing in iTunes?
I was trying to set-up a share with iTunes to display the images on my large LCD using my Apple TV. But for some reason the new smart albums I am setting up are no longer showing up in my iTunes Photo Sharing Preferences. I have restarted both apps
-
Automatically add files to iTunes not processing mp4 files on Windows 8.1
I have iTunes 12.1.1.4 install on a Windows 8 (x64) system. I have been using iTunes for quite some time and my library is located at c:\Music. On earlier versions (version 10 of iTunes for example) I would drop an MP4 file into c:\Music\Automatica
-
How to get Cube and Dimension ID from SSAS Database programatically
Hi All, I am processing one SSAS cube from SSIS package and processing the cubes dynamically .For this am putting the Cube ID ,Cube name, Dimension ID, Dimension Name in a table and generating the XML programmatically. I can right click the properti
-
ITouch suddenly quit working.
I had been using my Itouch with no problems until I plugged it in one night to sync and it went blank. I did a recovery on it and it went back to the factory settings. Now when I try to sync it I get a message" Ipod may be damaged and cannot be activ
-
Who can fix my VI to work in LV8? please help...
I wrote this VI in LV 7 and it worked great, I was forced to upgrade to LV8 and it no longer works. I will admit my knowledge of LV is marginal at best. The VI is attached, It was using "open create replace file", "write to file", and "close file" Th