Add PolkitSmackProcess: a subclass of PolkitUnixProcess 26/16926/1
authorMichael Leibowitz <michael.leibowitz@intel.com>
Thu, 27 Feb 2014 04:52:28 +0000 (20:52 -0800)
committerMichael Leibowitz <michael.leibowitz@intel.com>
Thu, 27 Feb 2014 05:16:42 +0000 (21:16 -0800)
This adds smack label based subjects and re-arranges the way unix
process is done to make it possible to inherit.  The docs are still a
little broken.

Change-Id: I118683bce8829a6dc00c84305a5372a88aefb49a

docs/polkit/polkit-1-docs.xml
docs/polkit/polkit-1-sections.txt
docs/polkit/polkit-1.types
src/polkit/Makefile.am
src/polkit/polkitsmackprocess.c [new file with mode: 0644]
src/polkit/polkitsmackprocess.h [new file with mode: 0644]
src/polkit/polkitsubject.c
src/polkit/polkittypes.h
src/polkit/polkitunixprocess.c
src/polkit/polkitunixprocessprivate.h [new file with mode: 0644]

index 69a7b88bb7b3ef8c348ee937d47081995a771dc0..9350db62ef5b250832e151726c0d33046e885844 100644 (file)
@@ -35,6 +35,7 @@
       <title>Subjects</title>
       <xi:include href="xml/polkitsubject.xml"/>
       <xi:include href="xml/polkitunixprocess.xml"/>
+      <!-- <xi:include href="xml/polkitsmackprocess.xml"/> -->
       <xi:include href="xml/polkitunixsession.xml"/>
       <xi:include href="xml/polkitsystembusname.xml"/>
     </chapter>
index e7db6e377f7cd4094825beea65fa1d18edb86459..8edc662352d7b2f2bbc8ce9d8b1a7a5c1623bae0 100644 (file)
@@ -187,6 +187,25 @@ POLKIT_IS_UNIX_PROCESS_CLASS
 POLKIT_UNIX_PROCESS_GET_CLASS
 </SECTION>
 
+<SECTION>
+<File>polkitsmackprocess</FILE>
+PolkitSmackProcess
+polkit_smack_process_get_label
+polkit_smack_process_set_label
+<SUBSECTION Standard>
+PolkitSmackProcessClass
+POLKIT_IS_SMACK_PROCESS
+POLKIT_IS_SMACK_PROCESS_CLASS
+POLKIT_SMACK_PROCESS
+POLKIT_SMACK_PROCESS_CLASS
+POLKIT_SMACK_PROCESS_GET_CLASS
+POLKIT_TYPE_AGENT_REGISTER_FLAGS
+POLKIT_TYPE_AUTHORITY_FEATURES
+POLKIT_TYPE_CHECK_AUTHORIZATION_FLAGS
+POLKIT_TYPE_IMPLICIT_AUTHORIZATION
+POLKIT_TYPE_SMACK_PROCESS
+</SECTION>
+
 <SECTION>
 <FILE>polkitidentity</FILE>
 PolkitIdentity
index 6354d125bb80a6ec130ec455765883459a983a3e..295c3cc5d8f01a5da7784efb74adf1e22ef54d6e 100644 (file)
@@ -9,6 +9,7 @@ polkit_unix_group_get_type
 polkit_unix_netgroup_get_type
 polkit_subject_get_type
 polkit_unix_process_get_type
+polkit_smack_process_get_type
 polkit_unix_session_get_type
 polkit_system_bus_name_get_type
 polkit_error_get_type
index d648d29952259a4117c14ecc0f2c7d10d7c38b96..40a257385acd20a82f9a6cf418cc1b1786190138 100644 (file)
@@ -46,6 +46,7 @@ libpolkit_gobject_1include_HEADERS =                                                  \
        polkiterror.h                                                                   \
        polkitsubject.h                                                                 \
        polkitunixprocess.h                                                             \
+       polkitunixprocessprivate.h                                                      \
        polkitunixsession.h                                                             \
        polkitsystembusname.h                                                           \
        polkitidentity.h                                                                \
@@ -69,6 +70,7 @@ libpolkit_gobject_1_la_SOURCES =                                                      \
        polkiterror.c                           polkiterror.h                           \
        polkitsubject.c                         polkitsubject.h                         \
        polkitunixprocess.c                     polkitunixprocess.h                     \
+       polkitsmackprocess.c                    polkitsmackprocess.h                    \
        polkitsystembusname.c                   polkitsystembusname.h                   \
        polkitidentity.c                        polkitidentity.h                        \
        polkitunixuser.c                        polkitunixuser.h                        \
diff --git a/src/polkit/polkitsmackprocess.c b/src/polkit/polkitsmackprocess.c
new file mode 100644 (file)
index 0000000..ce3055c
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2014 Intel, inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Michael Leibowitz <michael.leibowitz@intel.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "polkitsmackprocess.h"
+#include "polkitunixprocess.h"
+#include "polkitunixprocessprivate.h"
+#include "polkitsubject.h"
+
+
+struct _PolkitSmackProcess
+{
+   PolkitUnixProcess parent_instance;
+
+  gchar* label;
+};
+
+struct _PolkitSmackProcessClass
+{
+  PolkitUnixProcessClass parent_class;
+};
+
+enum
+{
+  PROP_0,
+  PROP_LABEL
+};
+
+G_DEFINE_TYPE(PolkitSmackProcess, polkit_smack_process, POLKIT_TYPE_UNIX_PROCESS);
+
+static void
+polkit_smack_process_init (PolkitSmackProcess *smack_process)
+{
+  smack_process->label = NULL;
+}
+
+static void
+polkit_smack_process_get_property (GObject    *object,
+                                   guint       prop_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
+{
+  PolkitSmackProcess *smack_process = POLKIT_SMACK_PROCESS (object);
+
+  switch (prop_id)
+    {
+    case PROP_LABEL:
+      g_value_set_string(value, smack_process->label);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+polkit_smack_process_set_property (GObject      *object,
+                                   guint         prop_id,
+                                   const GValue *value,
+                                   GParamSpec   *pspec)
+{
+  PolkitSmackProcess *smack_process = POLKIT_SMACK_PROCESS (object);
+
+  switch (prop_id)
+    {
+    case PROP_LABEL:
+      polkit_smack_process_set_label (smack_process, g_value_get_string (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+polkit_smack_process_class_init (PolkitSmackProcessClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gobject_class->get_property = polkit_smack_process_get_property;
+  gobject_class->set_property = polkit_smack_process_set_property;
+
+  /**
+   * PolkitSmackProcess:label:
+   *
+   * The label of the process
+   */
+  g_object_class_install_property (gobject_class,
+                                  PROP_LABEL,
+                                  g_param_spec_string ("label",
+                                                       "Process label",
+                                                       "The SMACK process label",
+                                                       NULL,
+                                                       G_PARAM_CONSTRUCT |
+                                                       G_PARAM_READWRITE |
+                                                       G_PARAM_STATIC_NAME |
+                                                       G_PARAM_STATIC_BLURB |
+                                                       G_PARAM_STATIC_NICK));
+}
+
+PolkitSubject *
+polkit_smack_process_new_full (gint         pid,
+                               guint64      start_time,
+                               gint         uid,
+                               const gchar *label)
+{
+  return POLKIT_SUBJECT (g_object_new (POLKIT_TYPE_SMACK_PROCESS,
+                                      "pid", pid,
+                                      "start_time", start_time,
+                                      "uid", uid,
+                                      "label", label,
+                                      NULL));
+}
+
+
+/**
+ * polkit_smack_process_get_label:
+ * @process: A #PolkitSmackProcess.
+ *
+ * Gets the label for @process.
+ *
+ * Returns: The label for @process or NULL if unknown.  The returned
+ * string is the caller's responsibility to free.
+ */
+char*
+polkit_smack_process_get_label (PolkitSmackProcess *process)
+{
+  g_return_val_if_fail (POLKIT_IS_SMACK_PROCESS (process), NULL);
+  return g_strdup(process->label);
+}
+
+
+/**
+ * polkit_smack_process_set_label:
+ * @process: A #PolkitSmackProcess
+ * @label: The label to set for the @process or NULL to unset it.
+ *
+ * Sets the label for @process
+ */
+void
+polkit_smack_process_set_label (PolkitSmackProcess *process,
+                               const gchar        *label)
+{
+  g_return_if_fail (POLKIT_IS_SMACK_PROCESS (process));
+  g_return_if_fail (label == NULL);
+  process->label = g_strdup(label);
+}
diff --git a/src/polkit/polkitsmackprocess.h b/src/polkit/polkitsmackprocess.h
new file mode 100644 (file)
index 0000000..71a213e
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2014 Intel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Michael Leibowitz <michael.leibowitz@intel.com>
+ */
+
+#if !defined (_POLKIT_COMPILATION) && !defined(_POLKIT_INSIDE_POLKIT_H)
+#error "Only <polkit/polkit.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef __POLKIT_SMACK_PROCESS_H
+#define __POLKIT_SMACK_PROCESS_H
+
+#include <glib-object.h>
+#include <polkitunixprocessprivate.h>
+#include <polkit/polkittypes.h>
+
+G_BEGIN_DECLS
+
+#define POLKIT_TYPE_SMACK_PROCESS          (polkit_smack_process_get_type())
+#define POLKIT_SMACK_PROCESS(o)            (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_SMACK_PROCESS, PolkitSmackProcess))
+#define POLKIT_SMACK_PROCESS_CLASS(k)      (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_SMACK_PROCESS, PolkitSmackProcessClass))
+#define POLKIT_SMACK_PROCESS_GET_CLASS(o)  (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_SMACK_PROCESS, PolkitSmackProcessClass))
+#define POLKIT_IS_SMACK_PROCESS(o)         (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_SMACK_PROCESS))
+#define POLKIT_IS_SMACK_PROCESS_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_SMACK_PROCESS))
+
+#if 0
+typedef struct _PolkitSmackProcess PolkitSmackProcess;
+#endif
+typedef struct _PolkitSmackProcessClass PolkitSmackProcessClass;
+
+GType          polkit_smack_process_get_type  (void) G_GNUC_CONST;
+PolkitSubject *polkit_smack_process_new_full  (gint                pid,
+                                               guint64             start_time,
+                                               gint                uid,
+                                               const gchar        *label);
+char*           polkit_smack_process_get_label (PolkitSmackProcess *process);
+void            polkit_smack_process_set_label (PolkitSmackProcess *process,
+                                                const gchar        *label);
+
+
+G_END_DECLS
+
+#endif /* __POLKIT_SMACK_PROCESS_H */
index aed57951bb6bac9a1a7ffdebd3b199015636c076..d289a07c6fe7e83a85ce998004620c3013adb568 100644 (file)
 
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 #include "polkitsubject.h"
 #include "polkitunixprocess.h"
+#include "polkitsmackprocess.h"
 #include "polkitunixsession.h"
 #include "polkitsystembusname.h"
 #include "polkiterror.h"
@@ -264,6 +266,18 @@ polkit_subject_from_string  (const gchar   *str,
             }
         }
     }
+  else if (g_str_has_prefix (str, "smack-process:"))
+    {
+      gint scanned_pid;
+      guint64 scanned_starttime;
+      gint scanned_uid;
+      const char *scanned_label = NULL;
+      if (sscanf (str, "smack-process:%d:%" G_GUINT64_FORMAT ":%d:%as", &scanned_pid, &scanned_starttime, &scanned_uid, &scanned_label) == 4)
+       {
+         subject = polkit_smack_process_new_full (scanned_pid, scanned_starttime, scanned_uid, scanned_label);
+         free ((void*)scanned_label);
+       }
+    }
   else if (g_str_has_prefix (str, "unix-session:"))
     {
       subject = polkit_unix_session_new (str + sizeof "unix-session:" - 1);
@@ -307,6 +321,22 @@ polkit_subject_to_gvariant (PolkitSubject *subject)
       g_variant_builder_add (&builder, "{sv}", "uid",
                              g_variant_new_int32 (polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject))));
     }
+  else if (POLKIT_IS_SMACK_PROCESS (subject))
+    {
+      /**
+       * @FIXME: this could be dryer
+       */
+      kind = "smack-process";
+      g_variant_builder_add (&builder, "{sv}", "pid",
+                             g_variant_new_uint32 (polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject))));
+      g_variant_builder_add (&builder, "{sv}", "start-time",
+                             g_variant_new_uint64 (polkit_unix_process_get_start_time (POLKIT_UNIX_PROCESS (subject))));
+      g_variant_builder_add (&builder, "{sv}", "uid",
+                             g_variant_new_int32 (polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject))));
+      g_variant_builder_add (&builder, "{sv}", "label",
+                            g_variant_new_string (polkit_smack_process_get_label (POLKIT_SMACK_PROCESS (subject))));
+
+    }
   else if (POLKIT_IS_UNIX_SESSION (subject))
     {
       kind = "unix-session";
@@ -399,7 +429,7 @@ polkit_subject_new_for_gvariant (GVariant  *variant,
                  &kind,
                  &details_gvariant);
 
-  if (g_strcmp0 (kind, "unix-process") == 0)
+  if (g_strcmp0 (kind, "unix-process") == 0 || g_strcmp0 (kind, "smack-process") == 0)
     {
       GVariant *v;
       guint32 pid;
@@ -435,7 +465,26 @@ polkit_subject_new_for_gvariant (GVariant  *variant,
           uid = -1;
         }
 
-      ret = polkit_unix_process_new_for_owner (pid, start_time, uid);
+      if (g_strcmp0 (kind, "smack-process") == 0)
+       {
+         const gchar *label;
+
+         v = lookup_asv(details_gvariant, "label", G_VARIANT_TYPE_STRING, error);
+
+         if (v == NULL)
+           {
+             g_prefix_error (error, "Error parsing unix-process subject: ");
+             goto out;
+           }
+         label = g_variant_get_string(v, NULL);
+         g_variant_unref(v);
+
+         ret = polkit_smack_process_new_full (pid, start_time, uid, label);
+       }
+      else
+       {
+         ret = polkit_unix_process_new_for_owner (pid, start_time, uid);
+       }
     }
   else if (g_strcmp0 (kind, "unix-session") == 0)
     {
index 3de1778128d15e2ad2ad14a4bbe92887a556f0d1..8e2245325975f4b990419140fae38c46660a6923 100644 (file)
@@ -35,6 +35,9 @@ typedef struct _PolkitSubject PolkitSubject; /* Dummy typedef */
 struct _PolkitUnixProcess;
 typedef struct _PolkitUnixProcess PolkitUnixProcess;
 
+struct _PolkitSmackProcess;
+typedef struct _PolkitSmackProcess PolkitSmackProcess;
+
 struct _PolkitUnixSession;
 typedef struct _PolkitUnixSession PolkitUnixSession;
 
index 9d30cd213b7fd4cf04f3ed10dd72123f5d549734..b1586d4ee13d8a764aabe3c07d272cef43531c5a 100644 (file)
@@ -35,6 +35,7 @@
 #include <stdio.h>
 
 #include "polkitunixprocess.h"
+#include "polkitunixprocessprivate.h"
 #include "polkitsubject.h"
 #include "polkitprivate.h"
 #include "polkiterror.h"
  * time since the kernel was started) is used.
  */
 
-/**
- * PolkitUnixProcess:
- *
- * The #PolkitUnixProcess struct should not be accessed directly.
- */
-struct _PolkitUnixProcess
-{
-  GObject parent_instance;
-
-  gint pid;
-  guint64 start_time;
-  gint uid;
-};
-
-struct _PolkitUnixProcessClass
-{
-  GObjectClass parent_class;
-};
-
 enum
 {
   PROP_0,
diff --git a/src/polkit/polkitunixprocessprivate.h b/src/polkit/polkitunixprocessprivate.h
new file mode 100644 (file)
index 0000000..bbcc629
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2014 Intel, inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Michael Leibowitz <michael.leibowitz@intel.com>
+ */
+
+#ifndef __POLKIT_UNIX_PROCESS_PRIVATE_H
+#define __POLKIT_UNIX_PROCESS_PRIVATE_H
+
+/**
+ * PolkitUnixProcess:
+ *
+ * The #PolkitUnixProcess struct should not be accessed directly.
+ */
+struct _PolkitUnixProcess
+{
+  GObject parent_instance;
+
+  gint pid;
+  guint64 start_time;
+  gint uid;
+};
+
+struct _PolkitUnixProcessClass
+{
+  GObjectClass parent_class;
+};
+
+#endif /* __POLKIT_UNIX_PROCESS_PRIVATE_H */