1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-23 09:57:40 +03:00

Several mb tidyups - getting ready to address the XXX_sub function.

Jeremy.
(This used to be commit 92c3ae3458177ec7f721598311a8ad04b2db5138)
This commit is contained in:
Jeremy Allison 2004-03-05 22:32:45 +00:00
parent 474758956c
commit 48eb635f31
4 changed files with 91 additions and 94 deletions

View File

@ -2,7 +2,7 @@
Unix SMB/CIFS implementation. Unix SMB/CIFS implementation.
filename handling routines filename handling routines
Copyright (C) Andrew Tridgell 1992-1998 Copyright (C) Andrew Tridgell 1992-1998
Copyright (C) Jeremy Allison 1999-200 Copyright (C) Jeremy Allison 1999-2004
Copyright (C) Ying Chen 2000 Copyright (C) Ying Chen 2000
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
@ -392,9 +392,10 @@ BOOL check_name(pstring name,connection_struct *conn)
errno = 0; errno = 0;
if (IS_VETO_PATH(conn, name)) { if (IS_VETO_PATH(conn, name)) {
if(strcmp(name, ".") && strcmp(name, "..")) { /* Is it not dot or dot dot. */
if (!((name[0] == '.') && (!name[1] || (name[1] == '.' && !name[2])))) {
DEBUG(5,("file path name %s vetoed\n",name)); DEBUG(5,("file path name %s vetoed\n",name));
return(0); return False;
} }
} }
@ -412,7 +413,7 @@ BOOL check_name(pstring name,connection_struct *conn)
if ( (SMB_VFS_LSTAT(conn,name,&statbuf) != -1) && if ( (SMB_VFS_LSTAT(conn,name,&statbuf) != -1) &&
(S_ISLNK(statbuf.st_mode)) ) { (S_ISLNK(statbuf.st_mode)) ) {
DEBUG(3,("check_name: denied: file path name %s is a symlink\n",name)); DEBUG(3,("check_name: denied: file path name %s is a symlink\n",name));
ret=0; ret = False;
} }
} }
#endif #endif
@ -464,8 +465,11 @@ static BOOL scan_directory(const char *path, char *name, size_t maxlength,
/* now scan for matching names */ /* now scan for matching names */
while ((dname = ReadDirName(cur_dir))) { while ((dname = ReadDirName(cur_dir))) {
if (*dname == '.' && (strequal(dname,".") || strequal(dname,"..")))
/* Is it dot or dot dot. */
if ((dname[0] == '.') && (!dname[1] || (dname[1] == '.' && !dname[2]))) {
continue; continue;
}
/* /*
* At this point dname is the unmangled name. * At this point dname is the unmangled name.

View File

@ -112,105 +112,96 @@ int add_home_service(const char *service, const char *username, const char *home
/** /**
* Find a service entry. service is always in dos codepage. * Find a service entry.
* *
* @param service is modified (to canonical form??) * @param service is modified (to canonical form??)
**/ **/
int find_service(fstring service) int find_service(fstring service)
{ {
int iService; int iService;
all_string_sub(service,"\\","/",0); all_string_sub(service,"\\","/",0);
iService = lp_servicenumber(service); iService = lp_servicenumber(service);
/* now handle the special case of a home directory */ /* now handle the special case of a home directory */
if (iService < 0) if (iService < 0) {
{ char *phome_dir = get_user_home_dir(service);
char *phome_dir = get_user_home_dir(service);
if(!phome_dir) if(!phome_dir) {
{ /*
/* * Try mapping the servicename, it may
* Try mapping the servicename, it may * be a Windows to unix mapped user name.
* be a Windows to unix mapped user name. */
*/ if(map_username(service))
if(map_username(service)) phome_dir = get_user_home_dir(service);
phome_dir = get_user_home_dir(service); }
}
DEBUG(3,("checking for home directory %s gave %s\n",service, DEBUG(3,("checking for home directory %s gave %s\n",service,
phome_dir?phome_dir:"(NULL)")); phome_dir?phome_dir:"(NULL)"));
iService = add_home_service(service,service /* 'username' */, phome_dir); iService = add_home_service(service,service /* 'username' */, phome_dir);
} }
/* If we still don't have a service, attempt to add it as a printer. */ /* If we still don't have a service, attempt to add it as a printer. */
if (iService < 0) if (iService < 0) {
{ int iPrinterService;
int iPrinterService;
if ((iPrinterService = lp_servicenumber(PRINTERS_NAME)) >= 0) if ((iPrinterService = lp_servicenumber(PRINTERS_NAME)) >= 0) {
{ char *pszTemp;
char *pszTemp;
DEBUG(3,("checking whether %s is a valid printer name...\n", service)); DEBUG(3,("checking whether %s is a valid printer name...\n", service));
pszTemp = lp_printcapname(); pszTemp = lp_printcapname();
if ((pszTemp != NULL) && pcap_printername_ok(service, pszTemp)) if ((pszTemp != NULL) && pcap_printername_ok(service, pszTemp)) {
{ DEBUG(3,("%s is a valid printer name\n", service));
DEBUG(3,("%s is a valid printer name\n", service)); DEBUG(3,("adding %s as a printer service\n", service));
DEBUG(3,("adding %s as a printer service\n", service)); lp_add_printer(service, iPrinterService);
lp_add_printer(service, iPrinterService); iService = lp_servicenumber(service);
iService = lp_servicenumber(service); if (iService < 0) {
if (iService < 0) DEBUG(0,("failed to add %s as a printer service!\n", service));
DEBUG(0,("failed to add %s as a printer service!\n", service)); }
} } else {
else DEBUG(3,("%s is not a valid printer name\n", service));
DEBUG(3,("%s is not a valid printer name\n", service)); }
} }
} }
/* Check for default vfs service? Unsure whether to implement this */ /* Check for default vfs service? Unsure whether to implement this */
if (iService < 0) if (iService < 0) {
{ }
}
/* just possibly it's a default service? */ /* just possibly it's a default service? */
if (iService < 0) if (iService < 0) {
{ char *pdefservice = lp_defaultservice();
char *pdefservice = lp_defaultservice(); if (pdefservice && *pdefservice && !strequal(pdefservice,service) && !strstr(service,"..")) {
if (pdefservice && *pdefservice && /*
!strequal(pdefservice,service) && * We need to do a local copy here as lp_defaultservice()
!strstr(service,"..")) * returns one of the rotating lp_string buffers that
{ * could get overwritten by the recursive find_service() call
/* * below. Fix from Josef Hinteregger <joehtg@joehtg.co.at>.
* We need to do a local copy here as lp_defaultservice() */
* returns one of the rotating lp_string buffers that pstring defservice;
* could get overwritten by the recursive find_service() call pstrcpy(defservice, pdefservice);
* below. Fix from Josef Hinteregger <joehtg@joehtg.co.at>. iService = find_service(defservice);
*/ if (iService >= 0) {
pstring defservice; all_string_sub(service, "_","/",0);
pstrcpy(defservice, pdefservice); iService = lp_add_service(service, iService);
iService = find_service(defservice); }
if (iService >= 0) }
{ }
all_string_sub(service, "_","/",0);
iService = lp_add_service(service, iService);
}
}
}
if (iService >= 0) if (iService >= 0) {
if (!VALID_SNUM(iService)) if (!VALID_SNUM(iService)) {
{ DEBUG(0,("Invalid snum %d for %s\n",iService, service));
DEBUG(0,("Invalid snum %d for %s\n",iService, service)); iService = -1;
iService = -1; }
} }
if (iService < 0) if (iService < 0)
DEBUG(3,("find_service() failed to find service %s\n", service)); DEBUG(3,("find_service() failed to find service %s\n", service));
return (iService); return (iService);
} }
@ -218,6 +209,7 @@ int find_service(fstring service)
do some basic sainity checks on the share. do some basic sainity checks on the share.
This function modifies dev, ecode. This function modifies dev, ecode.
****************************************************************************/ ****************************************************************************/
static NTSTATUS share_sanity_checks(int snum, fstring dev) static NTSTATUS share_sanity_checks(int snum, fstring dev)
{ {

View File

@ -249,6 +249,9 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
open_size = IVAL(params,14); open_size = IVAL(params,14);
pname = &params[28]; pname = &params[28];
if (IS_IPC(conn))
return(ERROR_DOS(ERRSRV,ERRaccess));
srvstr_get_path(inbuf, fname, pname, sizeof(fname), -1, STR_TERMINATE, &status); srvstr_get_path(inbuf, fname, pname, sizeof(fname), -1, STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status); return ERROR_NT(status);
@ -257,9 +260,6 @@ static int call_trans2open(connection_struct *conn, char *inbuf, char *outbuf, i
DEBUG(3,("trans2open %s mode=%d attr=%d ofun=%d size=%d\n", DEBUG(3,("trans2open %s mode=%d attr=%d ofun=%d size=%d\n",
fname,open_mode, open_attr, open_ofun, open_size)); fname,open_mode, open_attr, open_ofun, open_size));
if (IS_IPC(conn))
return(ERROR_DOS(ERRSRV,ERRaccess));
/* XXXX we need to handle passed times, sattr and flags */ /* XXXX we need to handle passed times, sattr and flags */
unix_convert(fname,conn,0,&bad_path,&sbuf); unix_convert(fname,conn,0,&bad_path,&sbuf);

View File

@ -863,8 +863,8 @@ BOOL reduce_name(connection_struct *conn, pstring s, const char *dir)
DEBUG(3,("reduce_name [%s] [%s]\n",s,dir)); DEBUG(3,("reduce_name [%s] [%s]\n",s,dir));
/* remove any double slashes */ /* We know there are no double slashes as this comes from srvstr_get_path().
all_string_sub(s,"//","/",0); and has gone through check_path_syntax(). JRA */
pstrcpy(base_name,s); pstrcpy(base_name,s);
p = strrchr_m(base_name,'/'); p = strrchr_m(base_name,'/');
@ -915,17 +915,19 @@ BOOL reduce_name(connection_struct *conn, pstring s, const char *dir)
{ {
size_t l = strlen(dir2); size_t l = strlen(dir2);
if (dir2[l-1] == '/') char *last_slash = strrchr_m(dir2, '/');
if (last_slash && (last_slash[1] == '\0'))
l--; l--;
if (strncmp(newname,dir2,l) != 0) { if (strncmp(newname,dir2,l) != 0) {
vfs_ChDir(conn,wd); vfs_ChDir(conn,wd);
DEBUG(2,("Bad access attempt? s=%s dir=%s newname=%s l=%d\n",s,dir2,newname,(int)l)); DEBUG(2,("Bad access attempt: s=%s dir=%s newname=%s l=%d\n",s,dir2,newname,(int)l));
return(False); return(False);
} }
if (!readlink_check(conn, dir, newname)) { if (!readlink_check(conn, dir, newname)) {
DEBUG(2, ("Bad access attemt? %s is a symlink outside the share path", s)); DEBUG(2, ("Bad access attemt: %s is a symlink outside the share path", s));
return(False); return(False);
} }
@ -947,4 +949,3 @@ BOOL reduce_name(connection_struct *conn, pstring s, const char *dir)
return(True); return(True);
#endif #endif
} }