Attached is second version of patch.

Read from dir uses better name for function (no security but rather
uidgid) so it's included too. Take it as a version, which will be
back-ported to RHEL 5.

Regards,
  Honza

Steven Dake wrote:
> rename "security" as an objdb key to "uidgid".
> 
> The uid || gid should be valid, not requiring an and operation.
> 
> On Wed, 2009-05-13 at 18:21 +0200, Jan Friesse wrote:
>> Attached is first version of support for multiple security items (uid-gid).
>>
>> First question what I have. I'm currently testing uid and gid as a pair,
>> so user process must have gid and uid (not only uid or gid). Is that
>> correct, or you will rather see something, what will check uid OR gid?
>> (From my point of view, both solution are acceptable and both have some
>> pros/cons, so I think, there should be major consensus)
>>
> or operation
> 
>> Second question. Items are cached, but in list. Steve talked something
>> about, that this is fast path, so isn't list some performance killer? If
>> yes, I think we can use:
>> - hash table (red black tree/...) in case 1. question will be answered,
>> that we should check uid and gid as a pair
>> - bit-array of uid and gid, if 1. question will be answered uid OR gid
>>
> A list should be ok for now.
> 
>> Third question. I'm not sure, if I should implement some reloading stuff
>> or not. Because in current implementation, ug_config.uid/gid are never
>> reloaded, and only logstuff is reloaded.
>>
> 
> followup patch imo
> 
>> Fourth think. From my point of view. ug_config.uid/gid no longer make
>> sense to be used for IPC authentifications (becase this patch should be
>> full and better replacement), so second patch (corosync-remove-...)
>> removes this.
>>
> 
> ok
> 
>> And last think. Can please somebody with native English language update
>> manual pages? Of course I can do that, but ... I'm not sure that my
>> Czechlish is understandable to anybody different then me, and you, as my
>> colleagues ;)
>>
> 
> right up there with root canals.  The man pages need love, and we will
> get to them eventually.
> 
> Regards
> -steve
> 
>> Regards,
>>   Honza
>> _______________________________________________
>> Openais mailing list
>> [email protected]
>> https://lists.linux-foundation.org/mailman/listinfo/openais
> 

diff --git a/trunk/exec/main.c b/trunk/exec/main.c
index db22e96..2b41111 100644
--- a/trunk/exec/main.c
+++ b/trunk/exec/main.c
@@ -138,6 +138,18 @@ static void sigusr2_handler (int num)
 	}
 }
 
+static void corosync_remove_uidgid_list (void) {
+	struct list_head *iter;
+
+	for (iter = ug_config.uidgid_list.next; iter != &ug_config.uidgid_list; ) {
+		struct uidgid_item *ugi = list_entry (iter, struct uidgid_item, list);
+		iter = iter->next;
+
+		list_del (&ugi->list);
+		free (ugi);
+	}
+}
+
 /*
  * TODO this function needs some love
  */
@@ -150,6 +162,10 @@ void corosync_request_shutdown (void)
 	poll_stop (0);
 	totempg_finalize ();
 	coroipcs_ipc_exit ();
+
+	/*Remove uidgid_list*/
+	corosync_remove_uidgid_list ();
+
 	corosync_exit_error (AIS_DONE_EXIT);
 }
 
@@ -482,12 +498,18 @@ static coroipcs_handler_fn_lvalue corosync_handler_fn_get (unsigned int service,
 
 static int corosync_security_valid (int euid, int egid)
 {
+	struct list_head *iter;
 	if (euid == 0 || egid == 0) {
 		return (1);
 	}
-	if (euid == ug_config.uid || egid == ug_config.gid) {
-		return (1);
+
+	for (iter = ug_config.uidgid_list.next; iter != &ug_config.uidgid_list; iter = iter->next) {
+		struct uidgid_item *ugi = list_entry (iter, struct uidgid_item, list);
+
+		if (euid == ugi->uid || egid == ugi->gid)
+			return (1);
 	}
+
 	return (0);
 }
 
diff --git a/trunk/exec/mainconfig.c b/trunk/exec/mainconfig.c
index 79e01cd..eb0563c 100644
--- a/trunk/exec/mainconfig.c
+++ b/trunk/exec/mainconfig.c
@@ -671,6 +671,54 @@ static void add_logsys_config_notification(
 
 }
 
+static int corosync_main_config_read_uidgid (
+	struct objdb_iface_ver0 *objdb,
+	const char **error_string,
+	struct ug_config *ug_config)
+{
+	hdb_handle_t object_find_handle;
+	hdb_handle_t object_service_handle;
+	char *value;
+	int uid, gid;
+	struct uidgid_item *ugi;
+
+	list_init (&ug_config->uidgid_list);
+
+	objdb->object_find_create (
+		OBJECT_PARENT_HANDLE,
+		"uidgid",
+		strlen ("uidgid"),
+		&object_find_handle);
+
+	while (objdb->object_find_next (
+		object_find_handle,
+		&object_service_handle) == 0) {
+		uid = -1;
+		gid = -1;
+
+		if (!objdb_get_string (objdb,object_service_handle, "uid", &value)) {
+			uid = uid_determine(value);
+		}
+
+		if (!objdb_get_string (objdb,object_service_handle, "gid", &value)) {
+			gid = gid_determine(value);
+		}
+
+		if (uid > -1 || gid > -1) {
+			ugi = malloc (sizeof (*ugi));
+			if (ugi == NULL) {
+				_corosync_out_of_memory_error();
+			}
+			ugi->uid = uid;
+			ugi->gid = gid;
+			list_add (&ugi->list, &ug_config->uidgid_list);
+		}
+	}
+	objdb->object_find_destroy (object_find_handle);
+
+	return 0;
+}
+
 int corosync_main_config_read (
 	struct objdb_iface_ver0 *objdb,
 	const char **error_string,
@@ -719,6 +767,8 @@ int corosync_main_config_read (
 		ug_config->gid = gid_determine("ais");
 	}
 
+	corosync_main_config_read_uidgid (objdb, error_string, ug_config);
+
 	add_logsys_config_notification(objdb);
 
 	return 0;
diff --git a/trunk/exec/mainconfig.h b/trunk/exec/mainconfig.h
index c9ab7ea..26135ad 100644
--- a/trunk/exec/mainconfig.h
+++ b/trunk/exec/mainconfig.h
@@ -37,6 +37,7 @@
 
 #include <corosync/engine/objdb.h>
 #include <corosync/engine/logsys.h>
+#include <corosync/list.h>
 
 /*
  * All service handlers in the AIS
@@ -49,14 +50,29 @@ struct dynamic_service {
 };
 #define MAX_DYNAMIC_SERVICES 128
 
+/*
+ * Structure describing cached uidgid item
+ */
+struct uidgid_item {
+	struct list_head list;
+	int uid;
+	int gid;
+};
+
 struct ug_config {
 	/*
 	 * user/group to run as
 	 */
 	int uid;
 	int gid;
+
+	/*
+	 * Allowed users/group to connect. This is of type uidgid item.
+	 */
+	struct list_head uidgid_list;
 };
 
+
 extern int corosync_main_config_read (
 	struct objdb_iface_ver0 *objdb,
 	const char **error_string,
commit b5fb3d54bf77c58a70202ff053862d3e2302579c
Author: Jan Friesse <[email protected]>
Date:   Tue May 12 18:07:33 2009 +0200

    coroparse: Support for reading configuration files from /etc/ais/uidgid.d

diff --git a/trunk/exec/coroparse.c b/trunk/exec/coroparse.c
index 5a71381..c6ac66c 100644
--- a/trunk/exec/coroparse.c
+++ b/trunk/exec/coroparse.c
@@ -47,6 +47,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <string.h>
+#include <dirent.h>
 
 #include <corosync/lcr/lcr_comp.h>
 #include <corosync/engine/objdb.h>
@@ -156,7 +157,45 @@ static int parse_section(FILE *fp,
 	return 0;
 }
 
+static int read_uidgid_files_into_objdb(
+	struct objdb_iface_ver0 *objdb,
+	const char **error_string)
+{
+	FILE *fp;
+	const char *dirname;
+	DIR *dp;
+	struct dirent *dirent;
+	char filename[PATH_MAX + NAME_MAX + 1];
+	int res = 0;
+
+	dirname = SYSCONFDIR "/ais/uidgid.d";
+	dp = opendir (dirname);
+
+	if (dp == NULL)
+		return 0;
+
+	while ((dirent = readdir (dp))) {
+		if (dirent->d_type == DT_REG) {
+			snprintf(filename, sizeof (filename), "%s/%s", dirname, dirent->d_name);
+
+			fp = fopen (filename, "r");
+			if (fp == NULL) continue;
+
+			res = parse_section(fp, objdb, OBJECT_PARENT_HANDLE, error_string);
+
+			fclose (fp);
 
+			if (res != 0) {
+				goto error_exit;
+			}
+		}
+	}
+
+error_exit:
+	closedir(dp);
+
+	return res;
+}
 
 /* Read config file and load into objdb */
 static int read_config_file_into_objdb(
@@ -186,6 +225,10 @@ static int read_config_file_into_objdb(
 	fclose(fp);
 
 	if (res == 0) {
+	        res = read_uidgid_files_into_objdb(objdb, error_string);
+	}
+
+	if (res == 0) {
 		snprintf (error_reason, sizeof(error_string_response),
 			"Successfully read main configuration file '%s'.\n", filename);
 		*error_string = error_reason;
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to