Skip to contentSkip to conversation

libselinux: support objname in compute_create

PATCH In review Christian Göttsche 2 participants 4 messages Aug 30, 2022 – Oct 13, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: support objname in compute_create

Support passing an optional object name to compute_create for name based type transitions.

---
 libselinux/utils/compute_create.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
libselinux/utils/compute_create.c +6 -3
index c6481f4b..5401fe96 100644
@@ -10,10 +10,11 @@ int main(int argc, char **argv)
 {
 	char *buf;
 	security_class_t tclass;
+	const char *objname;
 	int ret;
 
-	if (argc != 4) {
-		fprintf(stderr, "usage:  %s scontext tcontext tclass\n",
+	if (argc != 4 && argc != 5) {
+		fprintf(stderr, "usage:  %s scontext tcontext tclass [objname]\n",
 			argv[0]);
 		exit(1);
 	}
@@ -34,7 +35,9 @@ int main(int argc, char **argv)
 		exit(2);
 	}
 
-	ret = security_compute_create(argv[1], argv[2], tclass, &buf);
+	objname = (argc == 5) ? argv[4] : NULL;
+
+	ret = security_compute_create_name(argv[1], argv[2], tclass, objname, &buf);
 	if (ret < 0) {
 		fprintf(stderr, "%s:  security_compute_create failed:  %s\n",
 			argv[0], strerror(errno));
Signature · 1 line
2.37.2
#1 lore raw
Quoted 4 lines · Christian Göttsche

Support passing an optional object name to compute_create for name based type transitions.

Any comments?

Patchwork:
https://patchwork.kernel.org/project/selinux/patch/[email protected]/

Quoted 37 lines
---
 libselinux/utils/compute_create.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
libselinux/utils/compute_create.c +6 -4
index c6481f4b..5401fe96 100644
@@ -10,10 +10,11 @@ int main(int argc, char **argv)
 {
        char *buf;
        security_class_t tclass;
+       const char *objname;
        int ret;
 
-       if (argc != 4) {
-               fprintf(stderr, "usage:  %s scontext tcontext tclass\n",
+       if (argc != 4 && argc != 5) {
+               fprintf(stderr, "usage:  %s scontext tcontext tclass [objname]\n",
                        argv[0]);
                exit(1);
        }
@@ -34,7 +35,9 @@ int main(int argc, char **argv)
                exit(2);
        }
 
-       ret = security_compute_create(argv[1], argv[2], tclass, &buf);
+       objname = (argc == 5) ? argv[4] : NULL;
+
+       ret = security_compute_create_name(argv[1], argv[2], tclass, objname, &buf);
        if (ret < 0) {
                fprintf(stderr, "%s:  security_compute_create failed:  %s\n",
                        argv[0], strerror(errno));
--

2.37.2

Acked-by on v1 1/1
#2 lore raw
In reply to Christian Göttsche
Quoted 5 lines · Christian Göttsche

Support passing an optional object name to compute_create for name based type transitions.

Quoted 36 lines
---
 libselinux/utils/compute_create.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
libselinux/utils/compute_create.c +6 -4
index c6481f4b..5401fe96 100644
@@ -10,10 +10,11 @@ int main(int argc, char **argv)
 {
        char *buf;
        security_class_t tclass;
+       const char *objname;
        int ret;
 
-       if (argc != 4) {
-               fprintf(stderr, "usage:  %s scontext tcontext tclass\n",
+       if (argc != 4 && argc != 5) {
+               fprintf(stderr, "usage:  %s scontext tcontext tclass [objname]\n",
                        argv[0]);
                exit(1);
        }
@@ -34,7 +35,9 @@ int main(int argc, char **argv)
                exit(2);
        }
 
-       ret = security_compute_create(argv[1], argv[2], tclass, &buf);
+       objname = (argc == 5) ? argv[4] : NULL;
+
+       ret = security_compute_create_name(argv[1], argv[2], tclass, objname, &buf);
        if (ret < 0) {
                fprintf(stderr, "%s:  security_compute_create failed:  %s\n",
                        argv[0], strerror(errno));
--

2.37.2

#3 lore raw
Quoted 11 lines · James Carter
Quoted 5 lines · Christian Göttsche

Support passing an optional object name to compute_create for name based type transitions.

Merged.
Jim

Quoted 36 lines
Quoted 36 lines
---
 libselinux/utils/compute_create.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
libselinux/utils/compute_create.c +6 -4
index c6481f4b..5401fe96 100644
@@ -10,10 +10,11 @@ int main(int argc, char **argv)
 {
        char *buf;
        security_class_t tclass;
+       const char *objname;
        int ret;
 
-       if (argc != 4) {
-               fprintf(stderr, "usage:  %s scontext tcontext tclass\n",
+       if (argc != 4 && argc != 5) {
+               fprintf(stderr, "usage:  %s scontext tcontext tclass [objname]\n",
                        argv[0]);
                exit(1);
        }
@@ -34,7 +35,9 @@ int main(int argc, char **argv)
                exit(2);
        }
 
-       ret = security_compute_create(argv[1], argv[2], tclass, &buf);
+       objname = (argc == 5) ? argv[4] : NULL;
+
+       ret = security_compute_create_name(argv[1], argv[2], tclass, objname, &buf);
        if (ret < 0) {
                fprintf(stderr, "%s:  security_compute_create failed:  %s\n",
                        argv[0], strerror(errno));
--

2.37.2