]> git.saurik.com Git - apple/launchd.git/blobdiff - launchd/src/launchproxy.c
launchd-392.35.tar.gz
[apple/launchd.git] / launchd / src / launchproxy.c
index 3a909359607182c8f7dca676f337b54b186724af..d3290aac27ef1816dd7d7119e01b02455a5ce0b2 100644 (file)
  * @APPLE_APACHE_LICENSE_HEADER_END@
  */
 #include "config.h"
-#if HAVE_SECURITY
-#include <Security/Authorization.h>
-#include <Security/AuthorizationTags.h>
-#include <Security/AuthSession.h>
-#endif
 #include <sys/types.h>
 #include <sys/select.h>
 #include <sys/event.h>
 #include <signal.h>
 #include <netdb.h>
 
-#include "launch.h"
+#if !TARGET_OS_EMBEDDED
+#include <bsm/audit.h>
+#include <bsm/audit_session.h>
+#endif // !TARGET_OS_EMBEDDED
 
-#if __GNUC__ >= 4 && HAVE_SECURITY
-OSStatus SessionCreate(SessionCreationFlags flags, SessionAttributeBits attributes) __attribute__((weak));
-#endif
+#include "launch.h"
 
 static int kq = 0;
 
@@ -181,7 +177,7 @@ int main(int argc __attribute__((unused)), char *argv[])
                        switch (fork()) {
                        case -1:
                                syslog(LOG_WARNING, "fork(): %m");
-                               if( errno != ENOMEM ) {
+                               if (errno != ENOMEM) {
                                        continue;
                                }
                                goto out;
@@ -194,17 +190,23 @@ int main(int argc __attribute__((unused)), char *argv[])
 
                        setpgid(0, 0);
 
-#if HAVE_SECURITY
+#if !TARGET_OS_EMBEDDED
                        if ((tmp = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_SESSIONCREATE)) && launch_data_get_bool(tmp)) {
-                               if (SessionCreate) {
-                                       OSStatus scr = SessionCreate(0, 0);
-                                       if (scr != noErr)
-                                               syslog(LOG_NOTICE, "%s: SessionCreate() failed: %d", prog, scr);
+                               auditinfo_addr_t auinfo = {
+                                       .ai_termid = { .at_type = AU_IPv4 },
+                                       .ai_asid = AU_ASSIGN_ASID,
+                                       .ai_auid = getuid(),
+                                       .ai_flags = 0,
+                               };
+                               if (setaudit_addr(&auinfo, sizeof(auinfo)) == 0) {
+                                       char session[16]; 
+                                       snprintf(session, sizeof(session), "%x", auinfo.ai_asid);
+                                       setenv("SECURITYSESSIONID", session, 1);
                                } else {
-                                       syslog(LOG_NOTICE, "%s: SessionCreate == NULL!", prog);
+                                       syslog(LOG_NOTICE, "%s: Setting Audit Session ID failed: %d", prog, errno);
                                }
                        }
-#endif
+#endif // !TARGET_OS_EMBEDDED
                        fcntl(r, F_SETFL, 0);
                        fcntl(r, F_SETFD, 1);
                        dup2(r, STDIN_FILENO);