LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Forward slash (/) in filenames. (https://www.linuxquestions.org/questions/linux-software-2/forward-slash-in-filenames-665010/)

Oxagast 08-24-2008 10:02 AM

Forward slash (/) in filenames.
 
Hi,
I was wondering if it was at all possible to have a forward slash in a filename under linux or any other unix/unixbased operating system. For obvious reasons it would be illadvised, considering the way directories are separated in linux/unix, but I was just wondering if there was any way to force it, and what might happen if you did.

Thanks,
Marshall

matthewg42 08-24-2008 10:05 AM

No, it is not possible.

Oxagast 08-24-2008 10:12 AM

What would happen if you tried to download a file named as such from a operating system with a filesystem that supported such a name? Would the linux/unix system automatically rename it or crash or try to put it in a directory or what?

matthewg42 08-24-2008 10:36 AM

Lets say the file name is "test/file".

If an application tried to open such a file to write it using the system call open, it would be interpretted as an attempt to open the file "file" in the directory "test".

If the directory "test" exists and is writable, then I guess "file" would be created inside "test". If "test" does not exist or it is not possible to create a file within it (e.g. because of the permissions on the directory), the open system call will fail, and the application (if it is written properly) should notify the user of the failure.

In some cases I would imagine applications would spot a problem, e.g. in some file selectors where the path and the file name are separate, I would guess some file selectors would simple concatenate the two with a '/' between then - in this case the behavior described above would occur. Some might spot that the file name contains a '/' and complain. That's down to the application and/or GUI framework which is big used.

PTrenholme 08-24-2008 11:24 AM

There's more than one way to skin a cat:
Code:

$ touch test∕file

$ file test∕file
test∕file: empty

$ echo Test >test∕file

$ ls -l$ ls -l
total 64
drwxr-xr-x 60 Peter Peter  4096 2008-08-19 08:28 Books
drwxr-xr-x  2 Peter Peter  4096 2008-08-18 03:31 Desktop
drwxr-xr-x  2 Peter Peter  4096 2008-08-19 08:28 Documents
drwxr-xr-x  9 Peter Peter  4096 2008-08-20 15:00 Downloads
drwxrwxr-x  5 Peter Peter  4096 2008-08-19 15:10 iMacros
-rw-rw-r--  1 Peter Peter 11927 2008-08-22 06:10 maxout.gnuplot_pipes
drwxr-xr-x  6 Peter Peter  4096 2008-08-19 08:29 Pictures
drwxrwxr-x  3 Peter Peter  4096 2008-08-20 11:41 Scripts
-rw-rw-r--  1 Peter Peter    5 2008-08-24 09:30 test∕file
drwxr-xr-x  2 Peter Peter 20480 2008-08-19 08:29 Wallpapers

$ file test∕file
test∕file: ASCII text

$ ls test
ls: cannot access test: No such file or directory

My secret? That's not a /, it's a unicode character that displays as a /.

matthewg42 08-24-2008 11:40 AM

unicode is cheating. :p

Oxagast 08-24-2008 02:21 PM

I suppose the unicode trick wouldn't work because it's not a litteral forward slash. I was actually trying to find a way to say do:

Quote:

$ ls -al blah.sh
-rwsr-xr-x 1 root root 16 2008-08-24 11:08 blah.sh
$ cat blah.sh
#!/bin/bash
$ id
uid=1000(oxagast) gid=100(users)
$ cat "#!/bin/bash"
/bin/bash -p
$ ./"#!/bin/bash"
$ id
uid=1000(oxagast) gid=100(users) euid=0(root)
or something to that effect.

Or for example, what stops me from writing a "interpreter" such as perl, bash, awk, whatever owned by my user (because they are not set suid by default anyway) that interprets any suid/sgid script (or even binary) as a command that runs "bash -p" or whatever in suid?

Mr. C. 08-24-2008 05:08 PM

Slash is an illegal character for a file name, period. It is *the* path component separator in all *nix systems. This is hard coded into the kernel, and utilities, which adhere to this restriction. Ultimately, all pathnames are passed to system calls, where the kernel does path component splitting using forward slashes as the separator.

PTrenholme 08-26-2008 08:20 AM

Quote:

Originally Posted by Oxagast (Post 3258188)
<snip>Or for example, what stops me from writing a "interpreter" such as perl, bash, awk, whatever owned by my user (because they are not set suid by default anyway) that interprets any suid/sgid script (or even binary) as a command that runs "bash -p" or whatever in suid?

If that's all you wanted to do, look at the chmod command. You can set the s flag on an executable so that executable will run with the permissions of the user setting the flag. So you, as root, could write the interpreter and let your users run it.

Of course your users can't do that since you have to be the user setting the flag. (Without that restriction the permission model would be meaningless.)

So, bottom line, was your question about the *NIX security model? There are books on that subject, and, of course, the NSA-instigated "SELinux" project which can raise the security level of Linux to "military-grade" security if you use it.

Nethac DIU 07-21-2009 06:34 PM

I wondered the same...

at Dolphin when I make a folder with a slash as part of a filename it automatically converts it to a fraction slash (Unicode 0x2044).*Any other attempt of forcing a folder with a solidus as part of its name (renaming a folder, having a folder with the three different kinds of slashes as name) will throw some error.

GaijinPunch 07-21-2009 09:04 PM

Quote:

and what might happen if you did.
You would be, at minimum, laughed at by your peers.


All times are GMT -5. The time now is 04:34 PM.