hal/libhal-policy Makefile.am,1.1,1.2 libhal-policy.c,1.1,1.2

Artem Kachitchkine artem at kemper.freedesktop.org
Sat Mar 4 16:41:52 PST 2006


Update of /cvs/hal/hal/libhal-policy
In directory kemper:/tmp/cvs-serv7678/libhal-policy

Modified Files:
	Makefile.am libhal-policy.c 
Log Message:
2006-03-04  Artem Kachitchkine  <artem.kachitchkin at sun.com>

	* configure.in: check for getgrouplist() and use the local version
	if not provided by the system.

	* hald/hald_dbus.c: (hald_exec_method_free_mi),
	(hald_exec_method_do_invocation), (hald_exec_method): stdin is
	a macro in Solaris, can't use to name struct members.

	* hald/logger.h: if using Sun compiler, define __FUNCTION__
	through __func__.

	* libhal-policy/Makefile.am: posix thread flags required on Solaris
	for getgrgid_r() to have 5 arguments (otherwise it has 4).

	* libhal-policy/libhal-policy.c: (afp_process_elem),
	(libhal_policy_util_uid_to_name), (libhal_policy_element_set_uid),
	(libhal_policy_element_set_gid), (libhal_policy_element_get_uid),
	(libhal_policy_element_get_gid), (libhal_policy_element_dump):
	anonymous unions are not supported in C99, fixed LibHalPolicyElement.
	(getgrouplist): check for getgrouplist() and use the local version
	if not provided by the system.

	* tools/lshal.c: if using Sun compiler, define __FUNCTION__
	through __func__.



Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/libhal-policy/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am	25 Feb 2006 16:32:28 -0000	1.1
+++ Makefile.am	5 Mar 2006 00:41:50 -0000	1.2
@@ -1,5 +1,9 @@
 ## Process this file with automake to produce Makefile.in
 
+if HALD_COMPILE_SOLARIS
+CFLAGS += -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT
+endif
+
 INCLUDES = \
 	-DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\" \
 	-DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \
@@ -24,7 +28,6 @@
 
 libhal_policy_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
 
-
 check_PROGRAMS = libhal-policy-test
 
 libhal_policy_test_SOURCES =                             \

Index: libhal-policy.c
===================================================================
RCS file: /cvs/hal/hal/libhal-policy/libhal-policy.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- libhal-policy.c	25 Feb 2006 16:32:28 -0000	1.1
+++ libhal-policy.c	5 Mar 2006 00:41:50 -0000	1.2
@@ -50,6 +50,10 @@
 
 #define LIBHAL_POLICY_MAGIC 0x3117beef
 
+#ifdef __SUNPRO_C
+#define __FUNCTION__ __func__
+#endif
+
 /** Checks if LibHalContext *ctx == NULL */
 #define LIBHAL_POLICY_CHECK_CONTEXT(_ctx_, _ret_)				\
 	do {									\
@@ -79,7 +83,7 @@
 	union {
 		uid_t uid;
 		gid_t gid;
-	};
+	} id;
 	gboolean include_all;
 	gboolean exclude_all;
 	char *resource;
@@ -298,7 +302,7 @@
 		} else if (elem->exclude_all) {
 			*flag = FALSE;
 		}else {
-			if (elem->uid == uid)
+			if (elem->id.uid == uid)
 				*flag = TRUE;
 		}
 		break;
@@ -311,7 +315,7 @@
 		}else {
 			guint i;
 			for (i = 0; i < num_gids; i++) {
-				if (elem->gid == gid_list[i])
+				if (elem->id.gid == gid_list[i])
 					*flag = TRUE;
 			}
 		}
@@ -401,7 +405,7 @@
 
 	bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
 	buf = g_new0 (char, bufsize);
-		
+
 	rc = getpwuid_r (uid, &pwd, buf, bufsize, &pwdp);
 	if (rc != 0 || pwdp == NULL) {
 		/*g_warning ("getpwuid_r() returned %d", rc);*/
@@ -690,14 +694,14 @@
 libhal_policy_element_set_uid (LibHalPolicyElement     *elem, 
 			       uid_t                    uid)
 {
-	elem->uid = uid;
+	elem->id.uid = uid;
 }
 
 void
 libhal_policy_element_set_gid (LibHalPolicyElement     *elem, 
 			       gid_t                    gid)
 {
-	elem->gid = gid;
+	elem->id.gid = gid;
 }
 
 void
@@ -751,13 +755,13 @@
 uid_t
 libhal_policy_element_get_uid (LibHalPolicyElement     *elem)
 {
-	return elem->uid;
+	return elem->id.uid;
 }
 
 gid_t
 libhal_policy_element_get_gid (LibHalPolicyElement     *elem)
 {
-	return elem->gid;
+	return elem->id.gid;
 }
 
 const char *
@@ -785,7 +789,7 @@
 		} else if (elem->exclude_all) {
 			fprintf (fp, "uid:      none\n");
 		} else {
-			fprintf (fp, "uid:      %d\n", (int) elem->uid);
+			fprintf (fp, "uid:      %d\n", (int) elem->id.uid);
 		}
 	} else if (elem->type == LIBHAL_POLICY_ELEMENT_TYPE_GID) {
 		if (elem->include_all) {
@@ -793,10 +797,50 @@
 		} else if (elem->exclude_all) {
 			fprintf (fp, "gid:      none\n");
 		} else {
-			fprintf (fp, "gid:      %d\n", (int) elem->gid);
+			fprintf (fp, "gid:      %d\n", (int) elem->id.gid);
 		}
 	}
 	fprintf (fp, "resource: %s\n", elem->resource != NULL ? elem->resource : "(None)");
 }
 
+#ifndef HAVE_GETGROUPLIST
+/* Get group list for the named user.
+ * Return up to ngroups in the groups array.
+ * Return actual number of groups in ngroups.
+ * Return -1 if more groups found than requested.
+ */
+int
+getgrouplist (const char *name, int baseid, int *groups, int *ngroups)
+{
+	struct group *g;
+	int n = 0;
+	int i;
+	int ret;
+
+	if (*ngroups <= 0) {
+		return (-1);
+	}
+
+	*groups++ = baseid;
+	n++;
+
+	setgrent ();
+	while ((g = getgrent ()) != NULL) {
+		for (i = 0; g->gr_mem[i]; i++) {
+			if (strcmp (name, g->gr_mem[0]) == 0) {
+				*groups++ = g->gr_gid;
+				if (++n > *ngroups) {
+					break;
+				}
+			}
+		}
+	}
+	endgrent ();
+
+	ret = (n > *ngroups) ? -1 : n;
+	*ngroups = n;
+	return (ret);
+}
+#endif
+
 /** @} */




More information about the hal-commit mailing list