1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-06 16:23:49 +03:00

r15186: Introduce ISDOT and ISDOTDOT macros for testing whether a filename is

"." for "..". These express the intention better that strcmp or strequal
and improve searchability via cscope/ctags.
This commit is contained in:
James Peach
2006-04-24 00:16:51 +00:00
committed by Gerald (Jerry) Carter
parent 95eb558063
commit 7e4ad7e8e5
21 changed files with 78 additions and 112 deletions

View File

@@ -286,9 +286,9 @@ BOOL mask_match(struct smbcli_state *c, const char *string, const char *pattern,
char *p2, *s2;
BOOL ret;
if (strcmp(string,"..") == 0)
if (ISDOTDOT(string))
string = ".";
if (strcmp(pattern,".") == 0)
if (ISDOT(pattern))
return False;
if (is_case_sensitive)
@@ -497,8 +497,8 @@ static void do_list_helper(struct clilist_file_info *f, const char *mask, void *
do_list_fn(ctx, f);
}
if (do_list_recurse &&
!strequal(f->name,".") &&
!strequal(f->name,"..")) {
!ISDOT(f->name) &&
!ISDOTDOT(f->name)) {
char *mask2;
char *p;
@@ -838,7 +838,7 @@ static void do_mget(struct smbclient_context *ctx, struct clilist_file_info *fin
char *mget_mask;
char *saved_curdir;
if (strequal(finfo->name,".") || strequal(finfo->name,".."))
if (ISDOT(finfo->name) || ISDOTDOT(finfo->name))
return;
if (finfo->attrib & FILE_ATTRIBUTE_DIRECTORY)
@@ -1327,8 +1327,9 @@ static int file_find(struct smbclient_context *ctx, struct file_list **list, con
if (!dir) return -1;
while ((dname = readdirname(dir))) {
if (!strcmp("..", dname)) continue;
if (!strcmp(".", dname)) continue;
if (ISDOT(dname) || ISDOTDOT(dname)) {
continue;
}
if (asprintf(&path, "%s/%s", directory, dname) <= 0) {
continue;
@@ -2725,7 +2726,7 @@ static void completion_remote_filter(struct clilist_file_info *f, const char *ma
{
completion_remote_t *info = (completion_remote_t *)state;
if ((info->count < MAX_COMPLETIONS - 1) && (strncmp(info->text, f->name, info->len) == 0) && (strcmp(f->name, ".") != 0) && (strcmp(f->name, "..") != 0)) {
if ((info->count < MAX_COMPLETIONS - 1) && (strncmp(info->text, f->name, info->len) == 0) && (!ISDOT(f->name)) && (!ISDOTDOT(f->name))) {
if ((info->dirmask[0] == 0) && !(f->attrib & FILE_ATTRIBUTE_DIRECTORY))
info->matches[info->count] = strdup(f->name);
else {

View File

@@ -239,8 +239,7 @@ static void cb_select_child (GtkWidget *root_tree, GtkWidget *child,
/* Get stats on the file/dir and see what we have */
if ((strcmp(dirp->name, ".") != 0) &&
(strcmp(dirp->name, "..") != 0)) {
if (!ISDOT(dirp->name) && !ISDOTDOT(dirp->name)) {
strncpy(path1, path, sizeof(path1));
strncat(path1, "/", sizeof(path) - strlen(path));
@@ -414,8 +413,8 @@ static void cb_itemsignal( GtkWidget *item,
if (dirp->smbc_type != SMBC_FILE &&
dirp->smbc_type != SMBC_IPC_SHARE &&
(strcmp(dirp->name, ".") != 0) &&
(strcmp(dirp->name, "..") !=0)){
(!ISDOT(dirp->name)) &&
(!ISDOTDOT(dirp->name))){
subtree = gtk_tree_new();
gtk_tree_item_set_subtree(GTK_TREE_ITEM(aitem), subtree);

View File

@@ -40,3 +40,22 @@
#ifndef HAVE_MKDIR_MODE
#define mkdir(dir, mode) mkdir(dir)
#endif
/* Test whether a file name is the "." or ".." directory entries.
* These really should be inline functions.
*/
#ifndef ISDOT
#define ISDOT(path) ( \
*((const char *)path) == '.' && \
*(((const char *)path) + 1) == '\0' \
)
#endif
#ifndef ISDOTDOT
#define ISDOTDOT(path) ( \
*((const char *)path) == '.' && \
*(((const char *)path) + 1) == '.' && \
*(((const char *)path) + 2) == '\0' \
)
#endif

View File

@@ -88,8 +88,7 @@ static WERROR reg_dir_key_by_index(TALLOC_CTX *mem_ctx, const struct registry_ke
if(!d) return WERR_INVALID_PARAM;
while((e = readdir(d))) {
if( strcmp(e->d_name, ".") &&
strcmp(e->d_name, "..")) {
if(!ISDOT(e->d_name) && !ISDOTDOT(e->d_name)) {
struct stat stbuf;
char *thispath;

View File

@@ -73,7 +73,7 @@ _PUBLIC_ init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)
}
while((entry = readdir(dir))) {
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
if (ISDOT(entry->d_name) || ISDOTDOT(entry->d_name))
continue;
filename = talloc_asprintf(mem_ctx, "%s/%s", path, entry->d_name);

View File

@@ -21,6 +21,7 @@
#include "includes.h"
#include "libcli/raw/libcliraw.h"
#include "libcli/libcli.h"
#include "system/dir.h"
struct delete_state {
struct smbcli_tree *tree;
@@ -35,8 +36,9 @@ static void delete_fn(struct clilist_file_info *finfo, const char *name, void *s
{
struct delete_state *dstate = state;
char *s, *n;
if (strcmp(finfo->name, ".") == 0 ||
strcmp(finfo->name, "..") == 0) return;
if (ISDOT(finfo->name) || ISDOTDOT(finfo->name)) {
return;
}
n = strdup(name);
n[strlen(n)-1] = 0;

View File

@@ -939,7 +939,6 @@ NTSTATUS ntvfs_cifs_init(void)
{
NTSTATUS ret;
struct ntvfs_ops ops;
NTVFS_CURRENT_CRITICAL_SIZES(vers);
ZERO_STRUCT(ops);
@@ -986,7 +985,7 @@ NTSTATUS ntvfs_cifs_init(void)
/* register ourselves with the NTVFS subsystem. We register
under the name 'cifs'. */
ret = ntvfs_register(&ops, &vers);
ret = ntvfs_register(&ops);
if (!NT_STATUS_IS_OK(ret)) {
DEBUG(0,("Failed to register CIFS backend!\n"));

View File

@@ -777,7 +777,6 @@ NTSTATUS ntvfs_ipc_init(void)
{
NTSTATUS ret;
struct ntvfs_ops ops;
NTVFS_CURRENT_CRITICAL_SIZES(vers);
ZERO_STRUCT(ops);
@@ -818,7 +817,7 @@ NTSTATUS ntvfs_ipc_init(void)
ops.cancel = ipc_cancel;
/* register ourselves with the NTVFS subsystem. */
ret = ntvfs_register(&ops, &vers);
ret = ntvfs_register(&ops);
if (!NT_STATUS_IS_OK(ret)) {
DEBUG(0,("Failed to register IPC backend!\n"));

View File

@@ -884,7 +884,6 @@ NTSTATUS ntvfs_nbench_init(void)
{
NTSTATUS ret;
struct ntvfs_ops ops;
NTVFS_CURRENT_CRITICAL_SIZES(vers);
ZERO_STRUCT(ops);
@@ -929,7 +928,7 @@ NTSTATUS ntvfs_nbench_init(void)
ops.trans2 = NULL;
/* register ourselves with the NTVFS subsystem. */
ret = ntvfs_register(&ops, &vers);
ret = ntvfs_register(&ops);
if (!NT_STATUS_IS_OK(ret)) {
DEBUG(0,("Failed to register nbench backend!\n"));

View File

@@ -266,17 +266,6 @@ struct ntvfs_critical_sizes {
int sizeof_ntvfs_request;
};
#define NTVFS_CURRENT_CRITICAL_SIZES(c) \
struct ntvfs_critical_sizes c = { \
.interface_version = NTVFS_INTERFACE_VERSION, \
.sizeof_ntvfs_critical_sizes = sizeof(struct ntvfs_critical_sizes), \
.sizeof_ntvfs_context = sizeof(struct ntvfs_context), \
.sizeof_ntvfs_module_context = sizeof(struct ntvfs_module_context), \
.sizeof_ntvfs_ops = sizeof(struct ntvfs_ops), \
.sizeof_ntvfs_async_state = sizeof(struct ntvfs_async_state), \
.sizeof_ntvfs_request = sizeof(struct ntvfs_request), \
}
struct messaging_context;
#include "librpc/gen_ndr/security.h"
#include "librpc/gen_ndr/notify.h"

View File

@@ -44,18 +44,11 @@ static int num_backends;
The 'type' is used to specify whether this is for a disk, printer or IPC$ share
*/
_PUBLIC_ NTSTATUS ntvfs_register(const struct ntvfs_ops *ops,
const struct ntvfs_critical_sizes *const sizes)
_PUBLIC_ NTSTATUS ntvfs_register(const void *_ops)
{
const struct ntvfs_ops *ops = _ops;
struct ntvfs_ops *new_ops;
if (ntvfs_interface_differs(sizes)) {
DEBUG(0, ("NTVFS backend '%s' for type %d "
"failed version check\n",
ops->name, (int)ops->type));
return NT_STATUS_BAD_FUNCTION_TABLE;
}
if (ntvfs_backend_byname(ops->name, ops->type) != NULL) {
/* its already registered! */
DEBUG(0,("NTVFS backend '%s' for type %d already registered\n",
@@ -105,49 +98,21 @@ _PUBLIC_ const struct ntvfs_ops *ntvfs_backend_byname(const char *name, enum ntv
This can be used by backends to either detect compilation errors, or provide
multiple implementations for different smbd compilation options in one module
*/
static const NTVFS_CURRENT_CRITICAL_SIZES(critical_sizes);
static const struct ntvfs_critical_sizes critical_sizes = {
.interface_version = NTVFS_INTERFACE_VERSION,
.sizeof_ntvfs_critical_sizes = sizeof(struct ntvfs_critical_sizes),
.sizeof_ntvfs_context = sizeof(struct ntvfs_context),
.sizeof_ntvfs_module_context = sizeof(struct ntvfs_module_context),
.sizeof_ntvfs_ops = sizeof(struct ntvfs_ops),
.sizeof_ntvfs_async_state = sizeof(struct ntvfs_async_state),
.sizeof_ntvfs_request = sizeof(struct ntvfs_request),
};
_PUBLIC_ const struct ntvfs_critical_sizes *ntvfs_interface_version(void)
{
return &critical_sizes;
}
_PUBLIC_ BOOL ntvfs_interface_differs(const struct ntvfs_critical_sizes *const iface)
{
/* The comparison would be easier with memcmp, but compiler-interset
* alignment padding is not guaranteed to be zeroed.
*/
#define FIELD_DIFFERS(field) (iface->field != critical_sizes.field)
if (FIELD_DIFFERS(interface_version))
return True;
if (FIELD_DIFFERS(sizeof_ntvfs_critical_sizes))
return True;
if (FIELD_DIFFERS(sizeof_ntvfs_context))
return True;
if (FIELD_DIFFERS(sizeof_ntvfs_module_context))
return True;
if (FIELD_DIFFERS(sizeof_ntvfs_ops))
return True;
if (FIELD_DIFFERS(sizeof_ntvfs_async_state))
return True;
if (FIELD_DIFFERS(sizeof_ntvfs_request))
return True;
/* Versions match. */
return False;
#undef FIELD_DIFFERS
}
/*
initialise a connection structure to point at a NTVFS backend

View File

@@ -218,8 +218,7 @@ const char *pvfs_list_next(struct pvfs_dir *dir, uint_t *ofs)
while ((de = readdir(dir->dir))) {
const char *dname = de->d_name;
if (strcmp(dname, ".") == 0 ||
strcmp(dname, "..") == 0) {
if (ISDOT(dname) || ISDOT(dname)) {
continue;
}
@@ -269,13 +268,13 @@ NTSTATUS pvfs_list_seek(struct pvfs_dir *dir, const char *name, uint_t *ofs)
struct dirent *de;
int i;
if (strcmp(name, ".") == 0) {
if (ISDOT(name)) {
dir->offset = DIR_OFFSET_DOTDOT;
*ofs = dir->offset;
return NT_STATUS_OK;
}
if (strcmp(name, "..") == 0) {
if (ISDOTDOT(name)) {
dir->offset = DIR_OFFSET_BASE;
*ofs = dir->offset;
return NT_STATUS_OK;
@@ -324,8 +323,7 @@ BOOL pvfs_directory_empty(struct pvfs_state *pvfs, struct pvfs_filename *name)
}
while ((de = readdir(dir))) {
if (strcmp(de->d_name, ".") != 0 &&
strcmp(de->d_name, "..") != 0) {
if (!ISDOT(de->d_name) && !ISDOTDOT(de->d_name)) {
closedir(dir);
return False;
}

View File

@@ -372,7 +372,7 @@ static NTSTATUS pvfs_reduce_name(TALLOC_CTX *mem_ctx, const char **fname, uint_t
if (strcmp(components[i], "") == 0) {
continue;
}
if (strcmp(components[i], ".") == 0 || err_count) {
if (ISDOT(components[i]) || err_count) {
err_count++;
}
}
@@ -394,7 +394,7 @@ static NTSTATUS pvfs_reduce_name(TALLOC_CTX *mem_ctx, const char **fname, uint_t
i--;
continue;
}
if (strcmp(components[i], "..") == 0) {
if (ISDOTDOT(components[i])) {
if (i < 1) return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
memmove(&components[i-1], &components[i+1],
sizeof(char *)*(num_components-(i+1)));

View File

@@ -22,6 +22,7 @@
#include "includes.h"
#include "vfs_posix.h"
#include "system/dir.h"
/*
@@ -164,8 +165,7 @@ NTSTATUS pvfs_unlink(struct ntvfs_module_context *ntvfs,
while ((fname = pvfs_list_next(dir, &ofs))) {
/* this seems to be a special case */
if ((unl->unlink.in.attrib & FILE_ATTRIBUTE_DIRECTORY) &&
(strcmp(fname, ".") == 0 ||
strcmp(fname, "..") == 0)) {
(ISDOT(fname) || ISDOTDOT(fname))) {
return NT_STATUS_OBJECT_NAME_INVALID;
}

View File

@@ -286,7 +286,6 @@ NTSTATUS ntvfs_posix_init(void)
{
NTSTATUS ret;
struct ntvfs_ops ops;
NTVFS_CURRENT_CRITICAL_SIZES(vers);
ZERO_STRUCT(ops);
@@ -329,14 +328,14 @@ NTSTATUS ntvfs_posix_init(void)
under the name 'default' as we wish to be the default
backend, and also register as 'posix' */
ops.name = "default";
ret = ntvfs_register(&ops, &vers);
ret = ntvfs_register(&ops);
if (!NT_STATUS_IS_OK(ret)) {
DEBUG(0,("Failed to register POSIX backend as '%s'!\n", ops.name));
}
ops.name = "posix";
ret = ntvfs_register(&ops, &vers);
ret = ntvfs_register(&ops);
if (!NT_STATUS_IS_OK(ret)) {
DEBUG(0,("Failed to register POSIX backend as '%s'!\n", ops.name));

View File

@@ -100,7 +100,6 @@ NTSTATUS ntvfs_print_init(void)
{
NTSTATUS ret;
struct ntvfs_ops ops;
NTVFS_CURRENT_CRITICAL_SIZES(vers);
ZERO_STRUCT(ops);
@@ -116,7 +115,7 @@ NTSTATUS ntvfs_print_init(void)
/* register ourselves with the NTVFS subsystem. We register under the name 'default'
as we wish to be the default backend */
ret = ntvfs_register(&ops, &vers);
ret = ntvfs_register(&ops);
if (!NT_STATUS_IS_OK(ret)) {
DEBUG(0,("Failed to register PRINT backend!\n"));

View File

@@ -969,7 +969,6 @@ NTSTATUS ntvfs_simple_init(void)
{
NTSTATUS ret;
struct ntvfs_ops ops;
NTVFS_CURRENT_CRITICAL_SIZES(vers);
ZERO_STRUCT(ops);
@@ -1011,7 +1010,7 @@ NTSTATUS ntvfs_simple_init(void)
ops.type = NTVFS_DISK;
ops.name = "simple";
ret = ntvfs_register(&ops, &vers);
ret = ntvfs_register(&ops);
if (!NT_STATUS_IS_OK(ret)) {
DEBUG(0,("Failed to register simple backend with name: %s!\n",

View File

@@ -639,7 +639,6 @@ NTSTATUS ntvfs_unixuid_init(void)
{
NTSTATUS ret;
struct ntvfs_ops ops;
NTVFS_CURRENT_CRITICAL_SIZES(vers);
ZERO_STRUCT(ops);
@@ -680,15 +679,15 @@ NTSTATUS ntvfs_unixuid_init(void)
/* we register under all 3 backend types, as we are not type specific */
ops.type = NTVFS_DISK;
ret = ntvfs_register(&ops, &vers);
ret = ntvfs_register(&ops);
if (!NT_STATUS_IS_OK(ret)) goto failed;
ops.type = NTVFS_PRINT;
ret = ntvfs_register(&ops, &vers);
ret = ntvfs_register(&ops);
if (!NT_STATUS_IS_OK(ret)) goto failed;
ops.type = NTVFS_IPC;
ret = ntvfs_register(&ops, &vers);
ret = ntvfs_register(&ops);
if (!NT_STATUS_IS_OK(ret)) goto failed;
failed:

View File

@@ -57,8 +57,7 @@ static void recursive_delete(const char *path)
char *fname;
struct stat st;
if (strcmp(de->d_name, ".") == 0 ||
strcmp(de->d_name, "..") == 0) {
if (ISDOT(de->d_name) || ISDOTDOT(de->d_name)) {
continue;
}

View File

@@ -21,6 +21,7 @@
#include "includes.h"
#include "torture/torture.h"
#include "system/filesys.h"
#include "system/dir.h"
#include "lib/tdb/include/tdbutil.h"
#include "libcli/libcli.h"
#include "torture/util.h"
@@ -130,7 +131,7 @@ static void gen_name(char *name)
p[i] = 0;
if (strcmp(p, ".") == 0 || strcmp(p, "..") == 0) {
if (ISDOT(p) || ISDOTDOT(p)) {
p[0] = '_';
}

View File

@@ -20,6 +20,7 @@
#include "includes.h"
#include "system/filesys.h"
#include "system/dir.h"
#include "libcli/libcli.h"
#include "libcli/raw/libcliraw.h"
#include "system/time.h"
@@ -41,9 +42,9 @@ static BOOL reg_match_one(struct smbcli_state *cli, const char *pattern, const c
/* oh what a weird world this is */
if (old_list && strcmp(pattern, "*.*") == 0) return True;
if (strcmp(pattern,".") == 0) return False;
if (ISDOT(pattern)) return False;
if (strcmp(file,"..") == 0) file = ".";
if (ISDOTDOT(file)) file = ".";
return ms_fnmatch(pattern, file, cli->transport->negotiate.protocol)==0;
}
@@ -101,9 +102,9 @@ static BOOL f_info_hit;
static void listfn(struct clilist_file_info *f, const char *s, void *state)
{
if (strcmp(f->name,".") == 0) {
if (ISDOT(f->name)) {
resultp[0] = '+';
} else if (strcmp(f->name,"..") == 0) {
} else if (ISDOTDOT(f->name)) {
resultp[1] = '+';
} else {
resultp[2] = '+';
@@ -227,9 +228,9 @@ static void test_mask(int argc, char *argv[],
}
file[l+l2] = 0;
if (strcmp(file+l,".") == 0 ||
strcmp(file+l,"..") == 0 ||
strcmp(mask+l,"..") == 0) continue;
if (ISDOT(file+l) || ISDOTDOT(file+l) || ISDOTDOT(mask+l)) {
continue;
}
if (strspn(file+l, ".") == strlen(file+l)) continue;