[SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0pre2-2486-g93111ea

Volker Lendecke vlendec at samba.org
Fri May 16 21:45:14 GMT 2008


The branch, v3-3-test has been updated
       via  93111ea0a1191e8547ad6cf112e2699d3bb3799b (commit)
      from  1c4adc8dda68eae9839bdff843aadf8c98dd9e87 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-test


- Log -----------------------------------------------------------------
commit 93111ea0a1191e8547ad6cf112e2699d3bb3799b
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Mar 29 18:19:31 2008 +0100

    Simplify fake_file logic

-----------------------------------------------------------------------

Summary of changes:
 source/include/fake_file.h |   16 ++--------
 source/include/ntquotas.h  |    2 +-
 source/include/smb.h       |    2 +-
 source/smbd/fake_file.c    |   68 ++++++++++++++++++++------------------------
 source/smbd/ntquotas.c     |   29 ++++++-------------
 source/smbd/nttrans.c      |    2 +-
 6 files changed, 46 insertions(+), 73 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/include/fake_file.h b/source/include/fake_file.h
index d8a5389..93da106 100644
--- a/source/include/fake_file.h
+++ b/source/include/fake_file.h
@@ -31,19 +31,9 @@ we now get the unix name --metze
 #define FAKE_FILE_NAME_QUOTA_WIN32	"\\$Extend\\$Quota:$Q:$INDEX_ALLOCATION"
 #define FAKE_FILE_NAME_QUOTA_UNIX	"$Extend/$Quota:$Q:$INDEX_ALLOCATION"
 
-typedef struct _FAKE_FILE_HANDLE {
+struct fake_file_handle {
 	enum FAKE_FILE_TYPE type;
-	TALLOC_CTX *mem_ctx;
-	void *pd; /* for private data */
-	void (*free_pd)(void **pd); /* free private_data */
-} FAKE_FILE_HANDLE;
-
-typedef struct _FAKE_FILE {
-	const char *name;
-	enum FAKE_FILE_TYPE type;
-	void *(*init_pd)(TALLOC_CTX *men_ctx);
-	void (*free_pd)(void **pd);
-} FAKE_FILE;
-
+	void *private_data;
+};
 
 #endif /* _FAKE_FILE_H */
diff --git a/source/include/ntquotas.h b/source/include/ntquotas.h
index 8fd54e8..5b92b66 100644
--- a/source/include/ntquotas.h
+++ b/source/include/ntquotas.h
@@ -91,6 +91,6 @@ typedef struct _SMB_NTQUOTA_HANDLE {
 #define CHECK_NTQUOTA_HANDLE_OK(fsp,conn)	(FNUM_OK(fsp,conn) &&\
 	 (fsp)->fake_file_handle &&\
 	 ((fsp)->fake_file_handle->type == FAKE_FILE_TYPE_QUOTA) &&\
-	 (fsp)->fake_file_handle->pd)
+	 (fsp)->fake_file_handle->private_data)
 
 #endif /*_NTQUOTAS_H */
diff --git a/source/include/smb.h b/source/include/smb.h
index 1d6aba9..d6b026d 100644
--- a/source/include/smb.h
+++ b/source/include/smb.h
@@ -515,7 +515,7 @@ typedef struct files_struct {
 	char *fsp_name;
 
 	struct vfs_fsp_data *vfs_extension;
- 	FAKE_FILE_HANDLE *fake_file_handle;
+	struct fake_file_handle *fake_file_handle;
 
 	struct notify_change_buf *notify;
 
diff --git a/source/smbd/fake_file.c b/source/smbd/fake_file.c
index 0a54c85..565b557 100644
--- a/source/smbd/fake_file.c
+++ b/source/smbd/fake_file.c
@@ -21,52 +21,52 @@
 
 extern struct current_user current_user;
 
-static FAKE_FILE fake_files[] = {
+struct fake_file_type {
+	const char *name;
+	enum FAKE_FILE_TYPE type;
+	void *(*init_pd)(TALLOC_CTX *mem_ctx);
+};
+
+static struct fake_file_type fake_files[] = {
 #ifdef WITH_QUOTAS
-	{FAKE_FILE_NAME_QUOTA_UNIX,	FAKE_FILE_TYPE_QUOTA,	init_quota_handle,	destroy_quota_handle},
+	{FAKE_FILE_NAME_QUOTA_UNIX, FAKE_FILE_TYPE_QUOTA, init_quota_handle},
 #endif /* WITH_QUOTAS */
-	{NULL,				FAKE_FILE_TYPE_NONE,	NULL,			NULL }
+	{NULL, FAKE_FILE_TYPE_NONE, NULL}
 };
 
 /****************************************************************************
  Create a fake file handle
 ****************************************************************************/
 
-static struct _FAKE_FILE_HANDLE *init_fake_file_handle(enum FAKE_FILE_TYPE type)
+static struct fake_file_handle *init_fake_file_handle(enum FAKE_FILE_TYPE type)
 {
-	TALLOC_CTX *mem_ctx = NULL;
-	FAKE_FILE_HANDLE *fh = NULL;
+	struct fake_file_handle *fh = NULL;
 	int i;
 
-	for (i=0;fake_files[i].name!=NULL;i++) {
+	for (i=0; fake_files[i].name!=NULL; i++) {
 		if (fake_files[i].type==type) {
-			DEBUG(5,("init_fake_file_handle: for [%s]\n",fake_files[i].name));
-
-			if ((mem_ctx=talloc_init("fake_file_handle"))==NULL) {
-				DEBUG(0,("talloc_init(fake_file_handle) failed.\n"));
-				return NULL;	
-			}
+			break;
+		}
+	}
 
-			if ((fh =TALLOC_ZERO_P(mem_ctx, FAKE_FILE_HANDLE))==NULL) {
-				DEBUG(0,("TALLOC_ZERO() failed.\n"));
-				talloc_destroy(mem_ctx);
-				return NULL;
-			}
+	if (fake_files[i].name == NULL) {
+		return NULL;
+	}
 
-			fh->type = type;
-			fh->mem_ctx = mem_ctx;
+	DEBUG(5,("init_fake_file_handle: for [%s]\n",fake_files[i].name));
 
-			if (fake_files[i].init_pd) {
-				fh->pd = fake_files[i].init_pd(fh->mem_ctx);
-			}
+	fh = talloc(NULL, struct fake_file_handle);
+	if (fh == NULL) {
+		DEBUG(0,("TALLOC_ZERO() failed.\n"));
+		return NULL;
+	}
 
-			fh->free_pd = fake_files[i].free_pd;
+	fh->type = type;
 
-			return fh;
-		}
+	if (fake_files[i].init_pd) {
+		fh->private_data = fake_files[i].init_pd(fh);
 	}
-
-	return NULL;	
+	return fh;
 }
 
 /****************************************************************************
@@ -147,18 +147,12 @@ NTSTATUS open_fake_file(connection_struct *conn,
 	return NT_STATUS_OK;
 }
 
-void destroy_fake_file_handle(FAKE_FILE_HANDLE **fh)
+void destroy_fake_file_handle(struct fake_file_handle **fh)
 {
-	if (!fh||!(*fh)) {
+	if (!fh) {
 		return;
 	}
-
-	if ((*fh)->free_pd) {
-		(*fh)->free_pd(&(*fh)->pd);		
-	}
-
-	talloc_destroy((*fh)->mem_ctx);
-	(*fh) = NULL;
+	TALLOC_FREE(*fh);
 }
 
 NTSTATUS close_fake_file(files_struct *fsp)
diff --git a/source/smbd/ntquotas.c b/source/smbd/ntquotas.c
index fcccf9d..c616c49 100644
--- a/source/smbd/ntquotas.c
+++ b/source/smbd/ntquotas.c
@@ -222,6 +222,13 @@ int vfs_get_user_ntquota_list(files_struct *fsp, SMB_NTQUOTA_LIST **qt_list)
 	return 0;
 }
 
+static int quota_handle_destructor(SMB_NTQUOTA_HANDLE *handle)
+{
+	if (handle->quota_list)
+		free_ntquota_list(&handle->quota_list);
+	return 0;
+}
+
 void *init_quota_handle(TALLOC_CTX *mem_ctx)
 {
 	SMB_NTQUOTA_HANDLE *qt_handle;
@@ -235,24 +242,6 @@ void *init_quota_handle(TALLOC_CTX *mem_ctx)
 		return NULL;
 	}
 
-	return (void *)qt_handle;	
-}
-
-void destroy_quota_handle(void **pqt_handle)
-{
-	SMB_NTQUOTA_HANDLE *qt_handle = NULL;
-	if (!pqt_handle||!(*pqt_handle))
-		return;
-	
-	qt_handle = (SMB_NTQUOTA_HANDLE *)(*pqt_handle);
-	
-	
-	if (qt_handle->quota_list)
-		free_ntquota_list(&qt_handle->quota_list);
-
-	qt_handle->quota_list = NULL;
-	qt_handle->tmp_list = NULL;
-	qt_handle = NULL;
-
-	return;
+	talloc_set_destructor(qt_handle, quota_handle_destructor);
+	return (void *)qt_handle;
 }
diff --git a/source/smbd/nttrans.c b/source/smbd/nttrans.c
index b5546ea..cbe1299 100644
--- a/source/smbd/nttrans.c
+++ b/source/smbd/nttrans.c
@@ -2065,7 +2065,7 @@ static void call_nt_transact_get_user_quota(connection_struct *conn,
 	/* the NULL pointer checking for fsp->fake_file_handle->pd
 	 * is done by CHECK_NTQUOTA_HANDLE_OK()
 	 */
-	qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
+	qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
 
 	level = SVAL(params,2);
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list