5501583
diff -up smartmontools-5.38/configure.in.lowcap smartmontools-5.38/configure.in
5565886
--- smartmontools-5.38/configure.in.lowcap	2009-10-05 15:33:00.231298546 +0200
5565886
+++ smartmontools-5.38/configure.in	2009-10-05 15:33:00.237483461 +0200
6b05469
@@ -143,6 +143,40 @@ if test "$with_selinux" = "yes"; then
1a8b53a
 	AC_DEFINE(WITH_SELINUX, [1], [Define to 1 if SELinux support is enabled])
1a8b53a
 fi
1a8b53a
 
6b05469
+  AC_ARG_WITH(libcap-ng,
6b05469
+    [  --with-libcap-ng=[auto/yes/no]  Add Libcap-ng support [default=auto]],,
6b05469
+    with_libcap_ng=auto)
6b05469
+
6b05469
+# Check for Libcap-ng API
6b05469
+#
6b05469
+# libcap-ng detection
6b05469
+
6b05469
+if test x$with_libcap_ng = xno ; then
6b05469
+    have_libcap_ng=no;
6b05469
+else
6b05469
+    # Start by checking for header file
6b05469
+    AC_CHECK_HEADER(cap-ng.h, capng_headers=yes, capng_headers=no)
6b05469
+
6b05469
+    # See if we have libcap-ng library
6b05469
+    AC_CHECK_LIB(cap-ng, capng_clear, CAPNG_LDADD=-lcap-ng,)
6b05469
+
6b05469
+    # Check results are usable
6b05469
+    if test x$with_libcap_ng = xyes -a x$CAPNG_LDADD = x ; then
6b05469
+       AC_MSG_ERROR(libcap-ng support was requested and the library was not found)
6b05469
+    fi
6b05469
+    if test x$CAPNG_LDADD != x -a $capng_headers = no ; then
6b05469
+       AC_MSG_ERROR(libcap-ng libraries found but headers are missing)
6b05469
+    fi
6b05469
+fi
6b05469
+AC_SUBST(CAPNG_LDADD)
6b05469
+AC_MSG_CHECKING(whether to use libcap-ng)
6b05469
+if test x$CAPNG_LDADD != x ; then
6b05469
+    AC_DEFINE(HAVE_LIBCAP_NG,1,[libcap-ng support])
6b05469
+    AC_MSG_RESULT(yes)
6b05469
+else
6b05469
+    AC_MSG_RESULT(no)
6b05469
+fi
1a8b53a
+
1a8b53a
 if test "$prefix" = "NONE"; then
1a8b53a
     dnl no prefix and no mandir, so use ${prefix}/share/man as default
1a8b53a
     if test "$mandir" = '${prefix}/man'; then
5501583
diff -up smartmontools-5.38/Makefile.am.lowcap smartmontools-5.38/Makefile.am
5501583
--- smartmontools-5.38/Makefile.am.lowcap	2007-04-01 18:49:44.000000000 +0200
5565886
+++ smartmontools-5.38/Makefile.am	2009-10-05 15:33:00.238483296 +0200
1a8b53a
@@ -35,7 +35,7 @@ smartd_SOURCES =  smartd.cpp      \
1a8b53a
                   utility.cpp     \
1a8b53a
                   utility.h
1a8b53a
 
1a8b53a
-smartd_LDADD = @os_deps@ @os_libs@
1a8b53a
+smartd_LDADD = @os_deps@ @os_libs@ @CAPNG_LDADD@
1a8b53a
 smartd_DEPENDENCIES = @os_deps@
1a8b53a
 
1a8b53a
 EXTRA_smartd_SOURCES = os_darwin.cpp    \
2ba6d85
diff -up smartmontools-5.38/smartd.8.in.lowcap smartmontools-5.38/smartd.8.in
2ba6d85
--- smartmontools-5.38/smartd.8.in.lowcap	2008-03-04 23:09:47.000000000 +0100
5565886
+++ smartmontools-5.38/smartd.8.in	2009-10-05 15:44:35.455113557 +0200
2ba6d85
@@ -354,6 +354,12 @@ The default level is 1, so \'\-r ataioct
2ba6d85
 equivalent.
2ba6d85
 
2ba6d85
 .TP
5565886
+.B \-C, \-\-capabilities
2ba6d85
+Use possix \fBcapabilities(7)\fP (EXPERIMENTAL).
2ba6d85
+
2ba6d85
+Warning: Mail notification does not work when used.
2ba6d85
+
2ba6d85
+.TP
2ba6d85
 .B \-\-service
2ba6d85
 Cygwin and Windows only: Enables \fBsmartd\fP to run as a Windows service.
2ba6d85
 
5501583
diff -up smartmontools-5.38/smartd.cpp.lowcap smartmontools-5.38/smartd.cpp
5565886
--- smartmontools-5.38/smartd.cpp.lowcap	2009-10-05 15:33:00.224483349 +0200
5565886
+++ smartmontools-5.38/smartd.cpp	2009-10-05 15:33:00.245483604 +0200
1a8b53a
@@ -74,6 +74,10 @@ extern "C" int __stdcall FreeConsole(voi
1a8b53a
 #include <io.h> // setmode()
1a8b53a
 #endif // __CYGWIN__
1a8b53a
 
1a8b53a
+#ifdef HAVE_LIBCAP_NG
1a8b53a
+#include <cap-ng.h>
1a8b53a
+#endif //LIBCAP_NG
1a8b53a
+
1a8b53a
 // locally included files
1a8b53a
 #include "int64.h"
1a8b53a
 #include "atacmds.h"
2ba6d85
@@ -179,6 +183,11 @@ static int facility=LOG_DAEMON;
2ba6d85
 static bool do_fork=true;
2ba6d85
 #endif
2ba6d85
 
2ba6d85
+#ifdef HAVE_LIBCAP_NG
2ba6d85
+// enable possix capabilities
2ba6d85
+static bool enable_capabilities=false;
2ba6d85
+#endif
2ba6d85
+
2ba6d85
 // used for control of printing, passing arguments to atacmds.c
2ba6d85
 smartmonctrl *con=NULL;
2ba6d85
 
2ba6d85
@@ -613,6 +622,15 @@ void MailWarning(cfgfile *cfg, int which
2ba6d85
     if  (epoch<(mail->lastsent+days))
2ba6d85
       return;
2ba6d85
   }
2ba6d85
+  
2ba6d85
+#ifdef HAVE_LIBCAP_NG
2ba6d85
+  if (enable_capabilities) {
2ba6d85
+    PrintOut(LOG_ERR,"Sending a mail was supressed. "
2ba6d85
+		     "Mails can't be send when capabilites are enabled\n");
2ba6d85
+    return;
2ba6d85
+  }
2ba6d85
+
2ba6d85
+#endif
2ba6d85
 
2ba6d85
   // record the time of this mail message, and the first mail message
2ba6d85
   if (!mail->logged)
2ba6d85
@@ -1239,6 +1257,11 @@ void Usage (void){
2ba6d85
   PrintOut(LOG_INFO,"        Quit on one of: %s\n\n", GetValidArgList('q'));
2ba6d85
   PrintOut(LOG_INFO,"  -r, --report=TYPE\n");
2ba6d85
   PrintOut(LOG_INFO,"        Report transactions for one of: %s\n\n", GetValidArgList('r'));
2ba6d85
+#ifdef HAVE_LIBCAP_NG
2ba6d85
+  PrintOut(LOG_INFO,"  -C, --usecapabilities\n");
2ba6d85
+  PrintOut(LOG_INFO,"        Use possix capabilities (EXPERIMENTAL).\n"
2ba6d85
+		    "        Warning: Mail notification does not work when used.\n");
2ba6d85
+#endif
2ba6d85
 #ifdef _WIN32
2ba6d85
   PrintOut(LOG_INFO,"  --service\n");
2ba6d85
   PrintOut(LOG_INFO,"        Running as windows service (see man page), install with:\n");
2ba6d85
@@ -1260,6 +1283,9 @@ void Usage (void){
2ba6d85
   PrintOut(LOG_INFO,"  -p NAME    Write PID file NAME\n");
2ba6d85
   PrintOut(LOG_INFO,"  -q WHEN    Quit on one of: %s\n", GetValidArgList('q'));
2ba6d85
   PrintOut(LOG_INFO,"  -r TYPE    Report transactions for one of: %s\n", GetValidArgList('r'));
2ba6d85
+#ifdef HAVE_LIBCAP_NG
2ba6d85
+  PrintOut(LOG_INFO,"  -C         Use possix capabilities (EXPERIMENTAL)\n");
2ba6d85
+#endif
2ba6d85
   PrintOut(LOG_INFO,"  -V         Print License, Copyright, and version information\n");
2ba6d85
 #endif
2ba6d85
 }
2ba6d85
@@ -3890,6 +3916,7 @@ void ParseOpts(int argc, char **argv){
2ba6d85
     { "copyright",      no_argument,       0, 'V' },
2ba6d85
     { "help",           no_argument,       0, 'h' },
2ba6d85
     { "usage",          no_argument,       0, 'h' },
2ba6d85
+    { "usecapabilities",no_argument,       0, 'C' },
2ba6d85
     { 0,                0,                 0, 0   }
2ba6d85
   };
2ba6d85
 #endif
2ba6d85
@@ -4030,6 +4057,12 @@ void ParseOpts(int argc, char **argv){
2ba6d85
       PrintCopyleft();
2ba6d85
       EXIT(0);
2ba6d85
       break;
2ba6d85
+#ifdef HAVE_LIBCAP_NG
2ba6d85
+    case 'C':
2ba6d85
+      //enable possix capabilities
2ba6d85
+      enable_capabilities=1;
2ba6d85
+      break;
2ba6d85
+#endif
2ba6d85
     case 'h':
2ba6d85
       // help: print summary of command-line options
2ba6d85
       debugmode=1;
2ba6d85
@@ -4408,6 +4441,16 @@ static int smartd_main(int argc, char **
1a8b53a
   
1a8b53a
   // don't exit on bad checksums
1a8b53a
   con->checksumfail=0;
1a8b53a
+
1a8b53a
+#ifdef HAVE_LIBCAP_NG
1a8b53a
+  // Drop capabilities
2ba6d85
+  if (enable_capabilities) {
2ba6d85
+    capng_clear(CAPNG_SELECT_BOTH);
2ba6d85
+    capng_updatev(CAPNG_ADD, (capng_type_t)(CAPNG_EFFECTIVE|CAPNG_PERMITTED),
2ba6d85
+                CAP_SYS_ADMIN, CAP_MKNOD, CAP_SYS_RAWIO, -1);
2ba6d85
+    capng_apply(CAPNG_SELECT_BOTH);
2ba6d85
+  }
1a8b53a
+#endif
1a8b53a
   
1a8b53a
   // the main loop of the code
1a8b53a
   while (1){
2ba6d85
@@ -4482,7 +4525,15 @@ static int smartd_main(int argc, char **
2ba6d85
         PrintTestSchedule(ATAandSCSIdevlist);
2ba6d85
         EXIT(0);
2ba6d85
       }
2ba6d85
-      
2ba6d85
+#ifdef HAVE_LIBCAP_NG
2ba6d85
+      for(int i=numdevata+numdevscsi; i>1; i--) {
2ba6d85
+	  if (ATAandSCSIdevlist[i-1]->mailwarn) {
2ba6d85
+	      PrintOut(LOG_WARNING,"Mail can't be enabled together with --usecapabilities. All mail will be suppressed.\n");
2ba6d85
+	      break;
2ba6d85
+	  }
2ba6d85
+      }
2ba6d85
+	
2ba6d85
+#endif
2ba6d85
       // reset signal
2ba6d85
       caughtsigHUP=0;
2ba6d85
     }