[Midnightbsd-cvs] src [6794] trunk/lib/libmport: first pass at supporting permissions aka chmod, chown, chgrp as well as @dir command

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Oct 1 22:04:41 EDT 2014


Revision: 6794
          http://svnweb.midnightbsd.org/src/?rev=6794
Author:   laffer1
Date:     2014-10-01 22:04:41 -0400 (Wed, 01 Oct 2014)
Log Message:
-----------
first pass at supporting permissions aka chmod, chown, chgrp as well as @dir command

Modified Paths:
--------------
    trunk/lib/libmport/bundle_read_install_pkg.c
    trunk/lib/libmport/delete_primative.c
    trunk/lib/libmport/mport.h
    trunk/lib/libmport/plist.c

Modified: trunk/lib/libmport/bundle_read_install_pkg.c
===================================================================
--- trunk/lib/libmport/bundle_read_install_pkg.c	2014-10-02 01:16:08 UTC (rev 6793)
+++ trunk/lib/libmport/bundle_read_install_pkg.c	2014-10-02 02:04:41 UTC (rev 6794)
@@ -36,6 +36,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <unistd.h>
 #include <archive_entry.h>
 
 
@@ -82,15 +83,21 @@
 static int
 do_actual_install(mportInstance *mport, mportBundleRead *bundle, mportPackageMeta *pkg)
 {
-  int file_total, ret;
-  int file_count = 0;
-  mportAssetListEntryType type;
-  struct archive_entry *entry;
-  const char *data, *checksum;
-  char *orig_cwd; 
-  char file[FILENAME_MAX], cwd[FILENAME_MAX], dir[FILENAME_MAX];
-  sqlite3_stmt *assets = NULL, *count, *insert = NULL;
-  sqlite3 *db;
+	int file_total, ret;
+	int file_count = 0;
+	mportAssetListEntryType type;
+	struct archive_entry *entry;
+	const char *data, *checksum;
+	char *orig_cwd;
+	uid_t owner = 0; /* root */
+	gid_t group = 0; /* wheel */
+	mode_t *set;
+	mode_t newmode;
+	char *mode = NULL; 
+	struct stat sb;
+	char file[FILENAME_MAX], cwd[FILENAME_MAX], dir[FILENAME_MAX];
+	sqlite3_stmt *assets = NULL, *count, *insert = NULL;
+	sqlite3 *db;
   
   db = mport->db;
 
@@ -161,6 +168,24 @@
           goto ERROR;
           
         break;
+      case ASSET_CHMOD:
+	if (mode != NULL)
+		free(mode);
+	mode = strdup(data);
+        break;
+      case ASSET_CHOWN:
+	owner = mport_get_uid(data);
+        break;
+      case ASSET_CHGRP:
+	group = mport_get_gid(data);
+        break;
+      case ASSET_DIR:
+      case ASSET_DIRRM:
+      case ASSET_DIRRMTRY:
+        /* TODO: handle mode properly */
+        if (stat(data, &sb) == -1)
+	   mkdir(data, 0755); /* XXX: we ignore error because it's most likely already there */
+	break;
       case ASSET_EXEC:
         if (mport_run_asset_exec(mport, data, cwd, file) != MPORT_OK)
           goto ERROR;
@@ -174,7 +199,24 @@
 
         if (mport_bundle_read_extract_next_file(bundle, entry) != MPORT_OK) 
           goto ERROR;
-        
+
+	/* Set the owner and group */
+	if (chown(file, owner, group) == -1)
+		goto ERROR;
+
+	/* Set the file permissions, assumes non NFSv4 */
+	if (mode != NULL)
+	{
+		if (stat(file, &sb))
+			goto ERROR;
+		if ((set = setmode(mode)) == NULL)
+			goto ERROR;
+		newmode = getmode(set, sb.st_mode);
+		free(set);
+		if (chmod(file, newmode))
+			goto ERROR;
+	}
+
         (mport->progress_step_cb)(++file_count, file_total, file);
         
         break;

Modified: trunk/lib/libmport/delete_primative.c
===================================================================
--- trunk/lib/libmport/delete_primative.c	2014-10-02 01:16:08 UTC (rev 6793)
+++ trunk/lib/libmport/delete_primative.c	2014-10-02 02:04:41 UTC (rev 6794)
@@ -143,6 +143,7 @@
           mport_call_msg_cb(mport, "Could not execute %s: %s", data, mport_err_string());
         }
         break;
+      case ASSET_DIR:
       case ASSET_DIRRM:
       case ASSET_DIRRMTRY:
         if (mport_rmdir(file, type == ASSET_DIRRMTRY ? 1 : 0) != MPORT_OK) {

Modified: trunk/lib/libmport/mport.h
===================================================================
--- trunk/lib/libmport/mport.h	2014-10-02 01:16:08 UTC (rev 6793)
+++ trunk/lib/libmport/mport.h	2014-10-02 02:04:41 UTC (rev 6794)
@@ -79,7 +79,7 @@
   ASSET_COMMENT, ASSET_IGNORE, ASSET_NAME, ASSET_EXEC, ASSET_UNEXEC,
   ASSET_SRC, ASSET_DISPLY, ASSET_PKGDEP, ASSET_CONFLICTS, ASSET_MTREE,
   ASSET_DIRRM, ASSET_DIRRMTRY, ASSET_IGNORE_INST, ASSET_OPTION, ASSET_ORIGIN,
-  ASSET_DEPORIGIN, ASSET_NOINST, ASSET_DISPLAY
+  ASSET_DEPORIGIN, ASSET_NOINST, ASSET_DISPLAY, ASSET_DIR
 };
 
 typedef enum _AssetListEntryType mportAssetListEntryType;

Modified: trunk/lib/libmport/plist.c
===================================================================
--- trunk/lib/libmport/plist.c	2014-10-02 01:16:08 UTC (rev 6793)
+++ trunk/lib/libmport/plist.c	2014-10-02 02:04:41 UTC (rev 6794)
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD: src/lib/libmport/plist.c,v 1.13 2012/04/10 22:11:33 laffer1 Exp $");
+__MBSDID("$MidnightBSD$");
 
 #include <sys/cdefs.h>
 #include <stdio.h>
@@ -170,6 +170,8 @@
     return ASSET_DIRRM;
   if (STRING_EQ(s, "dirrmtry"))
     return ASSET_DIRRMTRY;
+  if (STRING_EQ(s, "dir"))
+    return ASSET_DIR;
   if (STRING_EQ(s, "cwd") || STRING_EQ(s, "cd"))
     return ASSET_CWD;
   if (STRING_EQ(s, "srcdir"))



More information about the Midnightbsd-cvs mailing list