Robert Craig avatar Robert Craig committed edb7378

Modiy mkyaffsimage for SELinux.

We need to ensure that a leading '/' is present for
selabel_lookups so they match file_context entries.

Change-Id: If39df42b73141bed0851a6b74c6f2c2da0c1658f
Signed-off-by: rpcraig <rpcraig@tycho.ncsc.mil>;

Comments (0)

Files changed (1)

yaffs2/utils/mkyaffs2image.c

 							mntpoint, suffix);
 						exit(1);
 					}
+
+					char *sepath = NULL;
+					if (dest_name[0] == '/')
+					        sepath = strdup(dest_name);
+					else if (asprintf(&sepath, "/%s", dest_name) < 0)
+                                                sepath = NULL;
+
+					if (!sepath) {
+					        perror("malloc");
+					        exit(1);
+					}
+
 					if (selabel_lookup(sehnd, &secontext,
-							   dest_name,
+							   sepath,
 							   stats.st_mode) < 0) {
-						perror("selabel_lookup");
-						exit(1);
+					        perror("selabel_lookup");
+					        free(sepath);
+					        exit(1);
 					}
+					free(sepath);
 				}
 #endif
 
 	//printf("Processing directory %s into image file %s\n",dir,image);
 #ifdef HAVE_SELINUX
     if (sehnd) {
-	    if (selabel_lookup(sehnd, &secontext, mntpoint, stats.st_mode) < 0) {
-		    perror("selabel_lookup");
-		    exit(1);
-	    }
+
+        char *sepath = NULL;
+        if (mntpoint[0] == '/')
+	    sepath = strdup(mntpoint);
+        else if (asprintf(&sepath, "/%s", mntpoint) < 0)
+            sepath = NULL;
+
+        if (!sepath) {
+	    perror("malloc");
+	    exit(1);
+	}
+
+	if (selabel_lookup(sehnd, &secontext, sepath, stats.st_mode) < 0) {
+	    perror("selabel_lookup");
+	    free(sepath);
+	    exit(1);
+	}
+
+	free(sepath);
     }
 #endif
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.