hal/hald/linux2/probing shared.h,1.2,1.3
David Zeuthen
david at freedesktop.org
Wed Feb 8 05:54:46 PST 2006
Update of /cvs/hal/hal/hald/linux2/probing
In directory gabe:/tmp/cvs-serv20696/hald/linux2/probing
Modified Files:
shared.h
Log Message:
2006-02-08 David Zeuthen <davidz at redhat.com>
Patch from Matthew Garrett <mjg59 at srcf.ucam.org>.
Two patches attached: 1) Changes the ACPI addon to report the type
of button pressed as well as the fact that a button has been
pressed. 2) Adds a keyboard addon. The included fdi file will bind
it to anything that has type input.keyboard. It adds the
capability "button" to the keyboard devices, and on any keypress
checks the key against a table. If the key is found there, a
ButtonPressed event is generated with the name of the key in the
details field (one exception - KEY_SUSPEND is given the name
"hibernate").
There's a couple of extra features that could be added (export a
list of the available keys, for instance - not very helpful on
PS/2, but useful on USB), but could these be applied as is for
now?
* hald/linux2/probing/shared.h: Move drop_privileges here so other
code can use it too.
* hald/linux2/addons/Makefile.am: Add build rules for
hald-addon-keybaord
* hald/linux2/addons/addon-acpi.c: Also send button.type as part
of the event
* hald/linux2/addons/addon-keyboard.c: New file. Also set
button.type to "" and button.has_state to FALSE
Index: shared.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/probing/shared.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- shared.h 16 Feb 2005 22:25:20 -0000 1.2
+++ shared.h 8 Feb 2006 13:54:44 -0000 1.3
@@ -5,6 +5,11 @@
#include <time.h>
#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <grp.h>
+
static dbus_bool_t is_verbose = FALSE;
static void
@@ -47,4 +52,37 @@
_dbg ("%s:%d: " format "\n", __FILE__, __LINE__, ## arg); \
} while (0)
+/** Drop all but necessary privileges. Set the running user id to HAL_USER and
+ * group to HAL_GROUP
+ */
+static
+void drop_privileges () {
+ struct passwd *pw = NULL;
+ struct group *gr = NULL;
+
+ /* determine user id */
+ pw = getpwnam (HAL_USER);
+ if (!pw) {
+ printf ("drop_privileges: user " HAL_USER " does not exist");
+ exit (-1);
+ }
+
+ /* determine primary group id */
+ gr = getgrnam (HAL_GROUP);
+ if(!gr) {
+ printf("drop_privileges: group " HAL_GROUP " does not exist");
+ exit (-1);
+ }
+
+ if( setgid (gr->gr_gid) ) {
+ printf ("drop_privileges: could not set group id");
+ exit (-1);
+ }
+
+ if( setuid (pw->pw_uid)) {
+ printf ("drop_privileges: could not set user id");
+ exit (-1);
+ }
+}
+
#endif
More information about the hal-commit
mailing list