r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[tprouty/samba.git] / source / smbd / dmapi.c
index 2188924d4b8518638b48d7695a764077d6d31a13..127d1627cf05ba3058e5698d9a92979d14d74180 100644 (file)
@@ -6,7 +6,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -15,8 +15,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_DMAPI
 
-#if defined(HAVE_LIBDM)
-#if (defined(HAVE_XFS_DMAPI_H) || defined(HAVE_SYS_DMI_H))
-#define USE_DMAPI 1
-#endif
-#endif
-
 #ifndef USE_DMAPI
 
 int dmapi_init_session(void) { return -1; }
@@ -40,10 +33,14 @@ BOOL dmapi_have_session(void) { return False; }
 
 #ifdef HAVE_XFS_DMAPI_H
 #include <xfs/dmapi.h>
-#endif
-
-#ifdef HAVE_SYS_DMI_H
+#elif defined(HAVE_SYS_DMI_H)
 #include <sys/dmi.h>
+#elif defined(HAVE_SYS_JFSDMAPI_H)
+#include <sys/jfsdmapi.h>
+#elif defined(HAVE_SYS_DMAPI_H)
+#include <sys/dmapi.h>
+#elif defined(HAVE_DMAPI_H)
+#include <dmapi.h>
 #endif
 
 #define DMAPI_SESSION_NAME "samba"
@@ -154,7 +151,9 @@ retry:
 
        /* No session already defined. */
        if (dmapi_session == DM_NO_SESSION) {
-               err = dm_create_session(DM_NO_SESSION, DMAPI_SESSION_NAME,
+               err = dm_create_session(DM_NO_SESSION,
+                                       CONST_DISCARD(char *,
+                                                     DMAPI_SESSION_NAME),
                                        &dmapi_session);
                if (err < 0) {
                        DEBUGADD(DMAPI_TRACE,
@@ -244,6 +243,13 @@ uint32 dmapi_file_flags(const char * const path)
                }
        }
 
+       /* AIX has DMAPI but no POSIX capablities support. In this case,
+        * we need to be root to do DMAPI manipulations.
+        */
+#ifndef HAVE_POSIX_CAPABILITIES
+       become_root();
+#endif
+
        err = dm_path_to_handle(CONST_DISCARD(char *, path),
                &dm_handle, &dm_handle_len);
        if (err < 0) {
@@ -251,7 +257,7 @@ uint32 dmapi_file_flags(const char * const path)
                            path, strerror(errno)));
 
                if (errno != EPERM) {
-                       return 0;
+                       goto done;
                }
 
                /* Linux capabilities are broken in that changing our
@@ -269,7 +275,7 @@ uint32 dmapi_file_flags(const char * const path)
                        DEBUG(DMAPI_TRACE,
                            ("retrying dm_path_to_handle(%s): %s\n",
                            path, strerror(errno)));
-                       return 0;
+                       goto done;
                }
        }
 
@@ -279,7 +285,7 @@ uint32 dmapi_file_flags(const char * const path)
                DEBUG(DMAPI_TRACE, ("dm_get_eventlist(%s): %s\n",
                            path, strerror(errno)));
                dm_handle_free(dm_handle, dm_handle_len);
-               return 0;
+               goto done;
        }
 
        /* We figure that the only reason a DMAPI application would be
@@ -298,6 +304,12 @@ uint32 dmapi_file_flags(const char * const path)
                DEBUG(DMAPI_TRACE, ("%s is OFFLINE\n", path));
        }
 
+done:
+
+#ifndef HAVE_POSIX_CAPABILITIES
+       unbecome_root();
+#endif
+
        return flags;
 }