It seems that I'm meant to be using the helper function here, not the struct
[kai/samba.git] / source3 / profile / profile.c
index 430732c6f86c09d178aeec7de5bfe50aa0b281a4..689f67da997d558208da04afabe3011440c535d5 100644 (file)
@@ -1,6 +1,5 @@
 /* 
-   Unix SMB/Netbios implementation.
-   Version 1.9.
+   Unix SMB/CIFS implementation.
    store smbd profiling information in shared memory
    Copyright (C) Andrew Tridgell 1999
    
 
 #include "includes.h"
 
-extern int DEBUGLEVEL;
-
+#ifdef WITH_PROFILE
 #define IPC_PERMS ((SHM_R | SHM_W) | (SHM_R>>3) | (SHM_R>>6))
+#endif /* WITH_PROFILE */
 
+#ifdef WITH_PROFILE
 static int shm_id;
 static BOOL read_only;
+#endif
 
 struct profile_header *profile_h;
 struct profile_stats *profile_p;
@@ -48,6 +49,7 @@ void profile_message(int msg_type, pid_t src, void *buf, size_t len)
         int level;
 
        memcpy(&level, buf, sizeof(int));
+#ifdef WITH_PROFILE
        switch (level) {
        case 0:         /* turn off profiling */
                do_profile_flag = False;
@@ -69,6 +71,9 @@ void profile_message(int msg_type, pid_t src, void *buf, size_t len)
                DEBUG(1,("INFO: Profiling values cleared from pid %d\n", (int)src));
                break;
        }
+#else /* WITH_PROFILE */
+       DEBUG(1,("INFO: Profiling support unavailable in this build.\n"));
+#endif /* WITH_PROFILE */
 }
 
 /****************************************************************************
@@ -90,6 +95,7 @@ void reqprofile_message(int msg_type, pid_t src, void *buf, size_t len)
 /*******************************************************************
   open the profiling shared memory area
   ******************************************************************/
+#ifdef WITH_PROFILE
 BOOL profile_setup(BOOL rdonly)
 {
        struct shmid_ds shm_ds;
@@ -130,12 +136,10 @@ BOOL profile_setup(BOOL rdonly)
                return False;
        }
 
-#if 0
-       if (shm_ds.shm_perm.cuid != 0 || shm_ds.shm_perm.cgid != 0) {
-               DEBUG(0,("ERROR: root did not create the shmem\n"));
+       if (shm_ds.shm_perm.cuid != sec_initial_uid() || shm_ds.shm_perm.cgid != sec_initial_gid()) {
+               DEBUG(0,("ERROR: we did not create the shmem (owned by another user)\n"));
                return False;
        }
-#endif
 
        if (shm_ds.shm_segsz != sizeof(*profile_h)) {
                DEBUG(0,("WARNING: profile size is %d (expected %d). Deleting\n",
@@ -159,4 +163,4 @@ BOOL profile_setup(BOOL rdonly)
        message_register(MSG_REQ_PROFILELEVEL, reqprofile_message);
        return True;
 }
-
+#endif /* WITH_PROFILE */