[Midnightbsd-cvs] src [7502] trunk/lib/libmport: start work on @(root, wheel, 0755) command structure
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri Apr 8 21:13:29 EDT 2016
Revision: 7502
http://svnweb.midnightbsd.org/src/?rev=7502
Author: laffer1
Date: 2016-04-08 21:13:28 -0400 (Fri, 08 Apr 2016)
Log Message:
-----------
start work on @(root,wheel,0755) command structure
Modified Paths:
--------------
trunk/lib/libmport/Makefile
trunk/lib/libmport/db.c
trunk/lib/libmport/delete_primative.c
trunk/lib/libmport/mport.h
trunk/lib/libmport/mport_private.h
trunk/lib/libmport/pkgmeta.c
trunk/lib/libmport/plist.c
trunk/lib/libmport/verify.c
Modified: trunk/lib/libmport/Makefile
===================================================================
--- trunk/lib/libmport/Makefile 2016-04-03 15:46:50 UTC (rev 7501)
+++ trunk/lib/libmport/Makefile 2016-04-09 01:13:28 UTC (rev 7502)
@@ -12,7 +12,7 @@
INCS= mport.h mport_dispatch.h
CFLAGS+= -I${.CURDIR} -fblocks -g
-SHLIB_MAJOR= 1
+SHLIB_MAJOR= 2
MAN= mport.3
NO_PROFILE=
Modified: trunk/lib/libmport/db.c
===================================================================
--- trunk/lib/libmport/db.c 2016-04-03 15:46:50 UTC (rev 7501)
+++ trunk/lib/libmport/db.c 2016-04-09 01:13:28 UTC (rev 7502)
@@ -37,6 +37,7 @@
static int mport_upgrade_master_schema_0to2(sqlite3 *);
static int mport_upgrade_master_schema_2to3(sqlite3 *);
static int mport_upgrade_master_schema_3to4(sqlite3 *);
+static int mport_upgrade_master_schema_4to6(sqlite3 *);
/* mport_db_do(sqlite3 *db, const char *sql, ...)
@@ -179,7 +180,7 @@
RUN_SQL(db, "CREATE TABLE meta (field text NOT NULL, value text NOT NULL)");
RUN_SQL(db, "INSERT INTO meta VALUES (\"bundle_format_version\", " MPORT_BUNDLE_VERSION_STR ")");
RUN_SQL(db, sql);
- RUN_SQL(db, "CREATE TABLE assets (pkg text not NULL, type int NOT NULL, data text, checksum text)");
+ RUN_SQL(db, "CREATE TABLE assets (pkg text not NULL, type int NOT NULL, data text, checksum text, owner text, grp text, mode text)");
RUN_SQL(db, "CREATE TABLE packages (pkg text NOT NULL, version text NOT NULL, origin text NOT NULL, lang text, options text, prefix text NOT NULL, comment text, os_release text NOT NULL, cpe text NOT NULL)");
RUN_SQL(db, "CREATE TABLE conflicts (pkg text NOT NULL, conflict_pkg text NOT NULL, conflict_version text NOT NULL)");
RUN_SQL(db, "CREATE TABLE depends (pkg text NOT NULL, depend_pkgname text NOT NULL, depend_pkgversion text, depend_port text NOT NULL)");
@@ -201,10 +202,14 @@
mport_upgrade_master_schema_2to3(db);
case 3:
mport_upgrade_master_schema_3to4(db);
- mport_set_database_version(db);
break;
case 4:
+ case 5:
+ mport_upgrade_master_schema_4to6(db);
+ mport_set_database_version(db);
break;
+ case 6:
+ break;
default:
RETURN_ERROR(MPORT_ERR_FATAL, "Invalid master database version");
}
@@ -217,7 +222,7 @@
{
RUN_SQL(db, "ALTER TABLE packages ADD COLUMN os_release text;");
- RUN_SQL(db, "update packages set os_release='0.4'");
+ RUN_SQL(db, "update packages set os_release='0.4';");
return (MPORT_OK);
}
@@ -234,12 +239,22 @@
static int
mport_upgrade_master_schema_3to4(sqlite3 *db)
{
- RUN_SQL(db, "ALTER TABLE Packages ADD COLUMN locked int");
- RUN_SQL(db, "update packages set locked=0");
+ RUN_SQL(db, "ALTER TABLE Packages ADD COLUMN locked int;");
+ RUN_SQL(db, "update packages set locked=0;");
return (MPORT_OK);
}
+static int
+mport_upgrade_master_schema_4to6(sqlite3 *db)
+{
+ RUN_SQL(db, "ALTER TABLE assets ADD COLUMN owner text;");
+ RUN_SQL(db, "ALTER TABLE assets ADD COLUMN grp text;");
+ RUN_SQL(db, "ALTER TABLE assets ADD COLUMN mode text;");
+
+ return (MPORT_OK);
+}
+
int
mport_generate_master_schema(sqlite3 *db)
{
@@ -255,7 +270,7 @@
RUN_SQL(db, "CREATE TABLE IF NOT EXISTS log (pkg text NOT NULL, version text NOT NULL, date int NOT NULL, msg text NOT NULL)");
RUN_SQL(db, "CREATE INDEX IF NOT EXISTS log_pkg ON log (pkg, version)");
- RUN_SQL(db, "CREATE TABLE IF NOT EXISTS assets (pkg text NOT NULL, type int NOT NULL, data text, checksum text)");
+ RUN_SQL(db, "CREATE TABLE IF NOT EXISTS assets (pkg text NOT NULL, type int NOT NULL, data text, checksum text, owner text, grp text, mode text)");
RUN_SQL(db, "CREATE INDEX IF NOT EXISTS assets_pkg ON assets (pkg)");
RUN_SQL(db, "CREATE TABLE IF NOT EXISTS categories (pkg text NOT NULL, category text NOT NULL)");
Modified: trunk/lib/libmport/delete_primative.c
===================================================================
--- trunk/lib/libmport/delete_primative.c 2016-04-03 15:46:50 UTC (rev 7501)
+++ trunk/lib/libmport/delete_primative.c 2016-04-09 01:13:28 UTC (rev 7502)
@@ -89,8 +89,8 @@
/* get the file count for the progress meter */
if (mport_db_prepare(mport->db, &stmt,
- "SELECT COUNT(*) FROM assets WHERE (type=%i or type=%i or type=%i) AND pkg=%Q", ASSET_FILE,
- ASSET_SAMPLE, ASSET_SHELL, pack->name) != MPORT_OK)
+ "SELECT COUNT(*) FROM assets WHERE (type=%i or type=%i or type=%i or type=%i) AND pkg=%Q", ASSET_FILE,
+ ASSET_SAMPLE, ASSET_SHELL, ASSET_FILE_OWNER_MODE, pack->name) != MPORT_OK)
RETURN_CURRENT_ERROR;
switch (sqlite3_step(stmt)) {
@@ -149,12 +149,15 @@
/* XXX data is null when ASSET_CHMOD (mode) or similar commands are in plist */
snprintf(file, sizeof(file), "%s", mport->root);
} else if (*data == '/') {
- snprintf(file, sizeof(file), "%s%s", mport->root, data);
+ /* TODO: do we still want to support mport->root here? seems to fail for /var entries */
+ snprintf(file, sizeof(file), "%s", data);
} else {
snprintf(file, sizeof(file), "%s%s/%s", mport->root, pack->prefix, data);
}
switch (type) {
+ case ASSET_FILE_OWNER_MODE:
+ /* falls through */
case ASSET_FILE:
/* falls through */
case ASSET_SHELL:
Modified: trunk/lib/libmport/mport.h
===================================================================
--- trunk/lib/libmport/mport.h 2016-04-03 15:46:50 UTC (rev 7501)
+++ trunk/lib/libmport/mport.h 2016-04-09 01:13:28 UTC (rev 7502)
@@ -82,15 +82,20 @@
ASSET_DIRRM, ASSET_DIRRMTRY, ASSET_IGNORE_INST, ASSET_OPTION, ASSET_ORIGIN,
ASSET_DEPORIGIN, ASSET_NOINST, ASSET_DISPLAY, ASSET_DIR,
ASSET_SAMPLE, ASSET_SHELL,
- ASSET_PREEXEC, ASSET_PREUNEXEC, ASSET_POSTEXEC, ASSET_POSTUNEXEC
+ ASSET_PREEXEC, ASSET_PREUNEXEC, ASSET_POSTEXEC, ASSET_POSTUNEXEC,
+ ASSET_FILE_OWNER_MODE
};
typedef enum _AssetListEntryType mportAssetListEntryType;
struct _AssetListEntry {
- mportAssetListEntryType type;
- char *data;
- STAILQ_ENTRY(_AssetListEntry) next;
+ mportAssetListEntryType type;
+ char *data;
+ char *owner;
+ char *group;
+ char *mode;
+
+ STAILQ_ENTRY(_AssetListEntry) next;
};
STAILQ_HEAD(_AssetList, _AssetListEntry);
Modified: trunk/lib/libmport/mport_private.h
===================================================================
--- trunk/lib/libmport/mport_private.h 2016-04-03 15:46:50 UTC (rev 7501)
+++ trunk/lib/libmport/mport_private.h 2016-04-09 01:13:28 UTC (rev 7502)
@@ -43,9 +43,9 @@
#define MPORT_PUBLIC_API
-#define MPORT_MASTER_VERSION 5
-#define MPORT_BUNDLE_VERSION 3
-#define MPORT_BUNDLE_VERSION_STR "3"
+#define MPORT_MASTER_VERSION 6
+#define MPORT_BUNDLE_VERSION 4
+#define MPORT_BUNDLE_VERSION_STR "4"
/* callback syntaxtic sugar */
void mport_call_msg_cb(mportInstance *, const char *, ...);
Modified: trunk/lib/libmport/pkgmeta.c
===================================================================
--- trunk/lib/libmport/pkgmeta.c 2016-04-03 15:46:50 UTC (rev 7501)
+++ trunk/lib/libmport/pkgmeta.c 2016-04-09 01:13:28 UTC (rev 7502)
@@ -361,7 +361,7 @@
*alist_p = alist;
- if (mport_db_prepare(mport->db, &stmt, "SELECT type, data FROM assets WHERE pkg=%Q", pkg->name) != MPORT_OK) {
+ if (mport_db_prepare(mport->db, &stmt, "SELECT type, data, owner, grp, mode FROM assets WHERE pkg=%Q", pkg->name) != MPORT_OK) {
sqlite3_finalize(stmt);
RETURN_CURRENT_ERROR;
}
@@ -386,6 +386,9 @@
e->type = sqlite3_column_int(stmt, 0);
e->data = strdup(sqlite3_column_text(stmt, 1));
+ e->owner = strdup(sqlite3_column_text(stmt, 2));
+ e->group = strdup(sqlite3_column_text(stmt, 3));
+ e->mode = strdup(sqlite3_column_text(stmt, 4));
if (e->data == NULL) {
sqlite3_finalize(stmt);
Modified: trunk/lib/libmport/plist.c
===================================================================
--- trunk/lib/libmport/plist.c 2016-04-03 15:46:50 UTC (rev 7501)
+++ trunk/lib/libmport/plist.c 2016-04-09 01:13:28 UTC (rev 7502)
@@ -41,6 +41,7 @@
#define STRING_EQ(r, l) (strcmp((r),(l)) == 0)
static mportAssetListEntryType parse_command(const char *);
+static int parse_file_owner_mode(mportAssetListEntry **, char *);
/* Do everything needed to set up a new plist. Always use this to create a plist,
* don't go off and do it yourself.
@@ -114,7 +115,9 @@
if (cmnd == NULL)
RETURN_ERROR(MPORT_ERR_FATAL, "Malformed plist file.");
- entry->type = parse_command(cmnd);
+ entry->type = parse_command(cmnd);
+ if (entry->type == ASSET_FILE_OWNER_MODE)
+ parse_file_owner_mode(&entry, cmnd);
} else {
entry->type = ASSET_FILE;
}
@@ -156,7 +159,38 @@
return MPORT_OK;
}
+/**
+ * Parse the file owner, group and mode.
+ */
+static int
+parse_file_owner_mode(mportAssetListEntry **entry, char *cmdLine) {
+ char *start;
+ char *op = start = strdup(cmdLine);
+ char *tok;
+ char *permissions[3] = {NULL, NULL, NULL};
+ int i = 0;
+ while((tok = strsep(&op, ",)")) != NULL) {
+ if (i == 3)
+ break;
+ permissions[i] = op;
+ i++;
+ }
+
+ if (permissions[0] != NULL)
+ (*entry)->owner = strdup(permissions[0]);
+ if (permissions[1] != NULL)
+ (*entry)->group = strdup(permissions[1]);
+ if (permissions[2] != NULL)
+ (*entry)->mode = strdup(permissions[2]);
+
+ free(start);
+
+ return MPORT_OK;
+}
+
+
+
static mportAssetListEntryType
parse_command(const char *s) {
@@ -220,6 +254,10 @@
if (STRING_EQ(s, "shell"))
return ASSET_SHELL;
+ /* special case, starts with ( as in @(root,wheel,0755) */
+ if (s[0] == '(')
+ return ASSET_FILE_OWNER_MODE;
+
return ASSET_INVALID;
}
Modified: trunk/lib/libmport/verify.c
===================================================================
--- trunk/lib/libmport/verify.c 2016-04-03 15:46:50 UTC (rev 7501)
+++ trunk/lib/libmport/verify.c 2016-04-09 01:13:28 UTC (rev 7502)
@@ -75,13 +75,17 @@
/* XXX data is null when ASSET_CHMOD (mode) or similar commands are in plist */
snprintf(file, sizeof(file), "%s", mport->root);
} else if (*data == '/') {
- snprintf(file, sizeof(file), "%s%s", mport->root, data);
+ /* we don't use mport->root because it's an absolute path like /var */
+ snprintf(file, sizeof(file), "%s", data);
} else {
snprintf(file, sizeof(file), "%s%s/%s", mport->root, pack->prefix, data);
}
switch (type) {
+ case ASSET_FILE_OWNER_MODE:
+ /* FALLS THROUGH */
case ASSET_FILE:
+ /* FALLS THROUGH */
case ASSET_SAMPLE:
if (lstat(file, &st) != 0) {
mport_call_msg_cb(mport, "Can't stat %s: %s", file, strerror(errno));
More information about the Midnightbsd-cvs
mailing list