LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-28-2014, 07:31 AM   #1
jan78
LQ Newbie
 
Registered: Apr 2014
Posts: 4

Rep: Reputation: Disabled
Case insensitive file names with samba for windows compatibility


I have Linux box and samba share for win users.
Is there a way to forbid creation of similar file names like File.txt and fILE.txt in same directory?
I know Linux can handle that, but Windows can not.
So, how about some compatibility enforcing methods, any ideas?
P.S. Files can be copied over network or created by Linux programs.
 
Old 04-28-2014, 08:18 AM   #2
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
Set the Directive in smb.conf
Quote:
case sensitive = yes/no
It controls whether filenames are case sensitive. If they aren't then Samba must do a filename search and match on passed names. Default no.
Restart samba.
 
Old 04-29-2014, 02:38 AM   #3
jan78
LQ Newbie
 
Registered: Apr 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for reply!
But this works only for samba, my problem is, that users can save files in that folder using Linux programs as well.
In my case it is third party CMS (Apache + PHP + ionCube) I can not touch.
Samba user save Image1.jpg
CMS user save image1.jpg
And now samba user have problems...
Maybe if php have something similar, we cud combine the two methods.
 
Old 04-29-2014, 05:42 AM   #4
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
If your php programs are creating files in a specific directory, Your developers should use strtolower() and strtoupper() functions to avoid conflicts.
When a php program is going to create a file in any direcotry, use strtolower function. It returns string with all alphabetic characters converted to lowercase.
It avoids lower case upper case conflict between files.

I am giving you a example of this, here is a php programs. it creates file testfile.txt in /tmp directory
Code:
<?php
$ourFileName = "/tmp/TeStFile.Txt";
$ourFileName = strtolower($ourFileName );
if (file_exists("$ourFileName")) {
    echo "The file exists";
} else {
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
echo "file created";
}
?>
I have defined that file should be created as TeStFile.Txt in /tmp directory
$ourFileName = "/tmp/TeStFile.Txt";
but in very next line, I have defined that all letters of filename should be converted into lower case
$ourFileName = strtolower($ourFileName );
So if you have filename TEStFile.TXT, TEStFilE.Txt, TESTFILE.TXT or anything including capital letters in the code, it will convert it into lower case letters.

If you do not have this file in directory, it will create the file in /tmp and next time when you run the script again, it will give the "file already exists". The program will not create same file name with different case.
 
Old 04-29-2014, 08:01 AM   #5
jan78
LQ Newbie
 
Registered: Apr 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
The problem is, that php code is locked using ionCube and I cannot modify code itself, only php and apache config.
 
Old 04-29-2014, 08:30 AM   #6
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
Quote:
Originally Posted by jan78 View Post
The problem is, that php code is locked using ionCube and I cannot modify code itself, only php and apache config.
I am not sure there is an option in apache config file so because of this php code would create files in lower case letters.
There are lots of options for url case sensitivity in Apache but I am not sure about this.

If you can rename the file name in lower case letters and if they are not dependent, I mean if renaming will not break anything else, you can set cron for it. It will rename all files of a directory in lower case after defined time period but you have to give the option in script that filename matches, it should change it according to it.

Suppose there are five files in the directory i.e. Filename.txt, filenamE2.Txt, ImaGe.jpG, IMage.jpg and Image.gif
When the cron will rename the files, there will be no problem in file 1,2,3 & 5 but when it will rename 4th, it will not be able to because it will try to rename it image.jpg and the file already exists that's why you have to take care about this condition, IF YOU ARE SETTING CRON FOR IT.
 
Old 04-29-2014, 12:38 PM   #7
jan78
LQ Newbie
 
Registered: Apr 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Unfortunately files in that folder are used by web page, and changing name after creation will break things.
I already gave image1.jpg in one page and Image1.jpg in another.
Worst thing is, that there is some creative users who abuse system and create those deliberately, only because somebody figured out, if they can not save file, they can save file by changing case of some letters. And everybody likes to name there photos for web page image1.jpg
...
Maybe someone know if there is some resident program or driver or something like that that would throw file creation exception on system level.
 
Old 04-30-2014, 02:36 AM   #8
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
If you are accessing files using web page, use the directive in apache configuration file
Quote:
CheckCaseOnly On
or use .htaccess file to redirect uppercase url to lowercase. Now when you will try to access http://example.com/Image.jpg, it will be redirected into http://example.com/image.jpg, if the file is available, it will open it otherwise it will show 404.

It will not prevent users to create filename with uppercase in the directory but if they want to see there files in browser, they have to give filename in lowercase. Although their files will be in the directory with uppercase name but they can not open it using urls because url will always be in lowercase and if filename contains uppercase, it redirects it to the lowercase filename.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Case insensitive Sharath Ravi Linux - Newbie 7 04-22-2014 02:51 AM
case insensitive file systems... [possibly] nublet Linux - Newbie 5 10-09-2009 07:28 AM
How to stop Linux changing the case of my file (build in Windows) names? zwtang Linux - Newbie 2 06-26-2008 06:00 AM
Copying files from case-sensitive Linux to case-insensitive Windows via CIFS? SlowCoder Linux - General 4 05-07-2008 07:03 PM
output the path for files whose names include string "string" (case insensitive) sean_zhang Linux - Newbie 1 03-04-2008 11:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration