This is a first pass at providing the feature requested in Bug 1207424

It leverages the appache config option

  AADefaultHatName

and when its value is specified as
  <hostname>

the hostname will be looked up and used.  Obviously this patch isn't
complete, but its a first pass and I wanted feedback before I put any
more work into it.

---

=== modified file 'changehat/mod_apparmor/mod_apparmor.c'
--- changehat/mod_apparmor/mod_apparmor.c       2011-02-08 16:18:36 +0000
+++ changehat/mod_apparmor/mod_apparmor.c       2013-08-02 08:36:24 +0000
@@ -48,6 +48,7 @@
 typedef struct {
        const char * hat_name;
        int is_initialized;
+       char hostname[HOST_NAME_MAX + 1];
 } immunix_srv_cfg;
 
 /* immunix_init() gets invoked in the post_config stage of apache.
@@ -235,6 +236,17 @@
                        parm1 ? parm1 : "DEFAULT");
     immunix_srv_cfg * scfg = mconfig;
     if (parm1 != NULL) {
+        if (strcmp(parm1, "<hostname>") == 0) {
+            if (gethostname(scfg->hostname, HOST_NAME_MAX+1)) {
+                ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
+                            "AADefaultHatName could not obtain hostname "
+                             " required by config");
+               /* TODO: what is the correct behavior for a failure here */
+               scfg->hat_name = "DEFAULT";
+            } else {
+                scfg->hat_name = scfg->hostname;
+            }
+      } else
        scfg->hat_name = parm1;
     } else {
        scfg->hat_name = "DEFAULT";


-- 
AppArmor mailing list
AppArmor@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to