svn commit: samba r16798 - in branches/tmp/vl-messaging/source/lib: .

vlendec at samba.org vlendec at samba.org
Tue Jul 4 13:59:52 GMT 2006


Author: vlendec
Date: 2006-07-04 13:59:52 +0000 (Tue, 04 Jul 2006)
New Revision: 16798

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16798

Log:
A couple of fixes
Modified:
   branches/tmp/vl-messaging/source/lib/dbwrap_file.c


Changeset:
Modified: branches/tmp/vl-messaging/source/lib/dbwrap_file.c
===================================================================
--- branches/tmp/vl-messaging/source/lib/dbwrap_file.c	2006-07-04 13:49:17 UTC (rev 16797)
+++ branches/tmp/vl-messaging/source/lib/dbwrap_file.c	2006-07-04 13:59:52 UTC (rev 16798)
@@ -53,7 +53,9 @@
 	struct db_locked_file *data =
 		talloc_get_type_abort(p, struct db_locked_file);
 
-	data->parent->locked_record = NULL;
+	if (data->parent != NULL) {
+		data->parent->locked_record = NULL;
+	}
 
 	if (close(data->fd) != 0) {
 		DEBUG(3, ("close failed: %s\n", strerror(errno)));
@@ -82,22 +84,21 @@
 	SMB_ASSERT(ctx->locked_record == NULL);
 
  again:
-	result = TALLOC_P(mem_ctx, struct db_record);
-	if (result == NULL) {
+	if (!(result = TALLOC_P(mem_ctx, struct db_record))) {
 		DEBUG(0, ("talloc failed\n"));
 		return NULL;
 	}
 
-	result->private_data = file = TALLOC_P(result, struct db_locked_file);
-	result->store = db_file_store;
-	result->delete_rec = db_file_delete;
-
-	if (file == NULL) {
+	if (!(file = TALLOC_P(result, struct db_locked_file))) {
 		DEBUG(0, ("talloc failed\n"));
 		TALLOC_FREE(result);
 		return NULL;
 	}
 
+	result->private_data = file;
+	result->store = db_file_store;
+	result->delete_rec = db_file_delete;
+
 	result->key.dsize = key.dsize;
 	result->key.dptr = (char *)talloc_memdup(result, key.dptr, key.dsize);
 	if (result->key.dptr == NULL) {
@@ -194,23 +195,19 @@
 	return result;
 }
 
-static int db_file_store(struct db_record *rec, TDB_DATA data, int flag)
+static int db_file_store_root(int fd, TDB_DATA data)
 {
-	struct db_locked_file *file =
-		talloc_get_type_abort(rec->private_data,
-				      struct db_locked_file);
-
-	if (sys_lseek(file->fd, 0, SEEK_SET) != 0) {
+	if (sys_lseek(fd, 0, SEEK_SET) != 0) {
 		DEBUG(0, ("sys_lseek failed: %s\n", strerror(errno)));
 		return -1;
 	}
 
-	if (write_data(file->fd, data.dptr, data.dsize) != data.dsize) {
+	if (write_data(fd, data.dptr, data.dsize) != data.dsize) {
 		DEBUG(3, ("write_data failed: %s\n", strerror(errno)));
 		return -1;
 	}
 
-	if (sys_ftruncate(file->fd, data.dsize) != 0) {
+	if (sys_ftruncate(fd, data.dsize) != 0) {
 		DEBUG(3, ("sys_ftruncate failed: %s\n", strerror(errno)));
 		return -1;
 	}
@@ -218,6 +215,20 @@
 	return 0;
 }
 
+static int db_file_store(struct db_record *rec, TDB_DATA data, int flag)
+{
+	struct db_locked_file *file =
+		talloc_get_type_abort(rec->private_data,
+				      struct db_locked_file);
+	int ret;
+
+	become_root();
+	ret = db_file_store_root(file->fd, data);
+	unbecome_root();
+
+	return ret;
+}
+
 static int db_file_delete(struct db_record *rec)
 {
 	struct db_locked_file *file =
@@ -348,26 +359,26 @@
 	struct db_context *result = NULL;
 	struct db_file_ctx *ctx;
 
-	result = TALLOC_P(mem_ctx, struct db_context);
-	if (result == NULL) {
+	if (!(result = TALLOC_P(mem_ctx, struct db_context))) {
 		DEBUG(0, ("talloc failed\n"));
-		goto fail;
+		return NULL;
 	}
 
+	if (!(ctx = TALLOC_P(result, struct db_file_ctx))) {
+		DEBUG(0, ("talloc failed\n"));
+		TALLOC_FREE(result);
+		return NULL;
+	}
+
+	result->private_data = ctx;
 	result->fetch_locked = db_file_fetch_locked;
 	result->traverse = db_file_traverse;
 
-	result->private_data = ctx = TALLOC_P(result, struct db_file_ctx);
-	if (ctx == NULL) {
-		DEBUG(0, ("talloc failed\n"));
-		goto fail;
-	}
-
 	ctx->locked_record = NULL;
-	ctx->dirname = talloc_strdup(ctx, name);
-	if (ctx->dirname == NULL) {
+	if (!(ctx->dirname = talloc_strdup(ctx, name))) {
 		DEBUG(0, ("talloc failed\n"));
-		goto fail;
+		TALLOC_FREE(result);
+		return NULL;
 	}
 
 	if (open_flags & O_CREAT) {
@@ -381,7 +392,8 @@
 		if ((ret != 0) && (errno != EEXIST)) {
 			DEBUG(5, ("mkdir(%s,%o) failed: %s\n", name, mode,
 				  strerror(errno)));
-			goto fail;
+			TALLOC_FREE(result);
+			return NULL;
 		}
 
 		for (i=0; i<256; i++) {
@@ -389,23 +401,19 @@
 			path = talloc_asprintf(result, "%s/%2.2X", name, i);
 			if (path == NULL) {
 				DEBUG(0, ("asprintf failed\n"));
-				goto fail;
+				TALLOC_FREE(result);
+				return NULL;
 			}
 			ret = mkdir(path, mode);
 			if ((ret != 0) && (errno != EEXIST)) {
 				DEBUG(5, ("mkdir(%s,%o) failed: %s\n", path,
 					  mode, strerror(errno)));
-				goto fail;
+				TALLOC_FREE(result);
+				return NULL;
 			}
 			TALLOC_FREE(path);
 		}
 	}
 
 	return result;
-
- fail:
-	if (result != NULL) {
-		TALLOC_FREE(result);
-	}
-	return NULL;
 }



More information about the samba-cvs mailing list