[darwinbuild-changes] [770] branches/PR-7593824/darwinup

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 12 08:45:43 PST 2010


Revision: 770
          http://trac.macosforge.org/projects/darwinbuild/changeset/770
Author:   wsiegrist at apple.com
Date:     2010-03-12 08:45:40 -0800 (Fri, 12 Mar 2010)
Log Message:
-----------
Ensure the depot gets creaed with the right mode and ownership. Differentiate between permission denied and empty depot when trying to list as not-root.

Modified Paths:
--------------
    branches/PR-7593824/darwinup/Depot.cpp
    branches/PR-7593824/darwinup/Depot.h
    branches/PR-7593824/darwinup/main.cpp

Modified: branches/PR-7593824/darwinup/Depot.cpp
===================================================================
--- branches/PR-7593824/darwinup/Depot.cpp	2010-03-11 21:59:31 UTC (rev 769)
+++ branches/PR-7593824/darwinup/Depot.cpp	2010-03-12 16:45:40 UTC (rev 770)
@@ -39,6 +39,7 @@
 #include <copyfile.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <grp.h>
 #include <libgen.h>
 #include <limits.h>
 #include <stdio.h>
@@ -102,18 +103,28 @@
 }
 
 int Depot::create_storage() {
+	uid_t uid = getuid();
+	struct group *gs = getgrnam("admin");
+	gid_t gid = gs->gr_gid;
+	
 	int res = mkdir(m_depot_path, m_depot_mode);
+	res = chmod(m_depot_path, m_depot_mode);
+	res = chown(m_depot_path, uid, gid);
 	if (res && errno != EEXIST) {
 		perror(m_depot_path);
 		return res;
 	}
 	res = mkdir(m_archives_path, m_depot_mode);
+	res = chmod(m_archives_path, m_depot_mode);
+	res = chown(m_archives_path, uid, gid);
 	if (res && errno != EEXIST) {
 		perror(m_archives_path);
 		return res;
 	}
 	
 	res = mkdir(m_downloads_path, m_depot_mode);
+	res = chmod(m_downloads_path, m_depot_mode);
+	res = chown(m_downloads_path, uid, gid);
 	if (res && errno != EEXIST) {
 		perror(m_downloads_path);
 		return res;
@@ -146,11 +157,16 @@
 		if (res) return res;
 	}
 
-	int exists = is_regular_file(m_database_path);
-	if (!exists && !writable) {
-		// read-only mode requested but we have no database
-		return -2;
+	struct stat sb;
+	res = stat(m_database_path, &sb);
+	if (!writable && res == -1 && (errno == ENOENT || errno == ENOTDIR)) {
+		// depot does not exist
+		return -2; 
 	}
+	if (!writable && res == -1 && errno == EACCES) {
+		// permission denied
+		return -3;
+	}
 
 	res = this->connect();
 

Modified: branches/PR-7593824/darwinup/Depot.h
===================================================================
--- branches/PR-7593824/darwinup/Depot.h	2010-03-11 21:59:31 UTC (rev 769)
+++ branches/PR-7593824/darwinup/Depot.h	2010-03-12 16:45:40 UTC (rev 770)
@@ -116,6 +116,8 @@
 
 	bool is_superseded(Archive* archive);
 
+	void    archive_header();
+	
 protected:
 
 	// Serialize access to the Depot via flock(2).
@@ -151,8 +153,6 @@
 	File*	file_preceded_by(File* file);
 
 	int		check_consistency();
-
-	void    archive_header();
 	
 	DarwinupDatabase* m_db;
 	

Modified: branches/PR-7593824/darwinup/main.cpp
===================================================================
--- branches/PR-7593824/darwinup/main.cpp	2010-03-11 21:59:31 UTC (rev 769)
+++ branches/PR-7593824/darwinup/main.cpp	2010-03-12 16:45:40 UTC (rev 770)
@@ -150,10 +150,16 @@
 		if (res == -2) {
 			// we are not asking to write, 
 			// but no depot exists yet either,
-			// so print the apparent truth
-			fprintf(stdout, "Nothing has been installed yet.\n");
+			// so print an empty list
+			depot->archive_header();
 			exit(0);
 		}
+		if (res == -3) {
+			// permission denied when trying to read
+			// the depot
+			fprintf(stderr, "Permission denied when trying to read the database.\n");
+			exit(6);
+		}
 		if (res == 0) depot->list(argc-1, (char**)(argv+1));
 	} else if (argc == 1) {
 		// other commands which take no arguments
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100312/6e404ae6/attachment.html>


More information about the darwinbuild-changes mailing list