static ubi_dlList stat_cache = { NULL, (ubi_dlNodePtr)&stat_cache, 0};
-/****************************************************************************
- Compare two names in the stat cache - to check if we already have such an
- entry.
-*****************************************************************************/
-
-static BOOL stat_name_equal( char *s1, char *s2)
-{
- return (case_sensitive ? (strcmp( s1, s2) == 0) : (StrCaseCmp(s1, s2) == 0));
-}
-
/****************************************************************************
Compare a pathname to a name in the stat cache - of a given length.
Note - this code always checks that the next character in the pathname
is either a '/' character, or a '\0' character - to ensure we only
- match *full* pathname components.
+ match *full* pathname components. Note we don't need to handle case
+ here, if we're case insensitive the stat cache orig names are all upper
+ case.
*****************************************************************************/
static BOOL stat_name_equal_len( char *stat_name, char *orig_name, int len)
{
- BOOL matched = (case_sensitive ? (strncmp( stat_name, orig_name, len) == 0) :
- (StrnCaseCmp(stat_name, orig_name, len) == 0));
+ BOOL matched = (memcmp( stat_name, orig_name, len) == 0);
if(orig_name[len] != '/' && orig_name[len] != '\0')
return False;
/*
* Don't cache trivial valid directory entries.
*/
- if(strequal(full_orig_name, ".") || strequal(full_orig_name, ".."))
+ if((*full_orig_name == '\0') || (strcmp(full_orig_name, ".") == 0) ||
+ (strcmp(full_orig_name, "..") == 0))
return;
/*
*/
StrnCpy(orig_name, full_orig_name, namelen);
+ if(!case_sensitive)
+ strupper( orig_name );
/*
* Check this name doesn't exist in the cache before we
for( scp = (stat_cache_entry *)ubi_dlFirst( &stat_cache); scp;
scp = (stat_cache_entry *)ubi_dlNext( scp )) {
- if(stat_name_equal( scp->orig_name, orig_name) &&
+ if((strcmp( scp->orig_name, orig_name) == 0) &&
(strcmp( scp->translated_name, translated_path) == 0)) {
/*
* Name does exist - promote it.
Return True if we translated (and did a scuccessful stat on) the entire name.
*****************************************************************************/
-static BOOL stat_cache_lookup( char *name, char *dirpath, char **start, SMB_STRUCT_STAT *pst)
+static BOOL stat_cache_lookup(struct connection_struct *conn, char *name,
+ char *dirpath, char **start,
+ SMB_STRUCT_STAT *pst)
{
stat_cache_entry *scp;
stat_cache_entry *longest_hit = NULL;
+ pstring chk_name;
int namelen;
if (!lp_stat_cache()) return False;
/*
* Don't lookup trivial valid directory entries.
*/
- if(strequal(name, ".") || strequal(name, "..")) {
+ if((*name == '\0') || (strcmp(name, ".") == 0) || (strcmp(name, "..") == 0)) {
global_stat_cache_misses++;
return False;
}
+ pstrcpy(chk_name, name);
+ if(!case_sensitive)
+ strupper( chk_name );
+
for( scp = (stat_cache_entry *)ubi_dlFirst( &stat_cache); scp;
scp = (stat_cache_entry *)ubi_dlNext( scp )) {
if(scp->name_len <= namelen) {
- if(stat_name_equal_len(scp->orig_name, name, scp->name_len)) {
+ if(stat_name_equal_len(scp->orig_name, chk_name, scp->name_len)) {
if((longest_hit == NULL) || (longest_hit->name_len <= scp->name_len))
longest_hit = scp;
}
* and then promote it to the top.
*/
- if(dos_stat( longest_hit->translated_name, pst) != 0) {
+ if(conn->vfs_ops.stat(longest_hit->translated_name, pst) != 0) {
/*
* Discard this entry.
*/
BOOL *bad_path, SMB_STRUCT_STAT *pst)
{
SMB_STRUCT_STAT st;
- char *start, *end, *orig_start;
+ char *start, *end;
pstring dirpath;
pstring orig_path;
int saved_errno;
extern char magic_char;
#endif
+ DEBUG(5, ("unix_convert called on file \"%s\"\n", name));
+
*dirpath = 0;
*bad_path = False;
if(pst) {
trim_string(name,"/","/");
+ /*
+ * If we trimmed down to a single '\0' character
+ * then we should use the "." directory to avoid
+ * searching the cache, but not if we are in a
+ * printing share.
+ */
+
+ if (!*name && (!conn -> printer)) {
+ name[0] = '.';
+ name[1] = '\0';
+ }
+
/*
* Ensure saved_last_component is valid even if file exists.
*/
for (s=name2 ; *s ; s++)
if (!issafe(*s)) *s = '_';
- pstrcpy(name,(char *)mktemp(name2));
+ pstrcpy(name,(char *)mktemp(name2));
}
return(True);
}
+ /*
+ * If we trimmed down to a single '\0' character
+ * then we will be using the "." directory.
+ * As we know this is valid we can return true here.
+ */
+
+ if(!*name)
+ return(True);
+
start = name;
while (strncmp(start,"./",2) == 0)
start += 2;
pstrcpy(orig_path, name);
- if(stat_cache_lookup( name, dirpath, &start, &st)) {
+ if(stat_cache_lookup(conn, name, dirpath, &start, &st)) {
if(pst)
*pst = st;
return True;
* stat the name - if it exists then we are all done!
*/
- if (dos_stat(name,&st) == 0) {
+ if (conn->vfs_ops.stat(name,&st) == 0) {
stat_cache_add(orig_path, name);
DEBUG(5,("conversion finished %s -> %s\n",orig_path, name));
if(pst)
* as is first, then trying to scan the directory for matching names.
*/
- for (orig_start = start; start ; start = (end?end+1:(char *)NULL)) {
+ for (; start ; start = (end?end+1:(char *)NULL)) {
/*
* Pinpoint the end of this section of the filename.
*/
/*
* Check if the name exists up to this point.
*/
- if (dos_stat(name, &st) == 0) {
+
+ if (conn->vfs_ops.stat(name, &st) == 0) {
/*
* It exists. it must either be a directory or this must be
* the last part of the path for it to be OK.
if (!lp_symlinks(SNUM(conn)))
{
SMB_STRUCT_STAT statbuf;
- if ( (dos_lstat(name,&statbuf) != -1) &&
+ if ( (conn->vfs_ops.lstat(dos_to_unix(name,False),&statbuf) != -1) &&
(S_ISLNK(statbuf.st_mode)) )
{
DEBUG(3,("check_name: denied: file path name %s is a symlink\n",name));