tdb: fix recovery reuse after crash
[ira/wip.git] / lib / uid_wrapper / uid_wrapper.c
index e009fa0b5c3eedf607e68df962e0e6b874b26c32..93ebb7c1897c3aeb63d8b336ace8417c61dc0b84 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#ifdef _SAMBA_BUILD_
+
 #define UID_WRAPPER_NOT_REPLACE
-#include "includes.h"
+#include "../replace/replace.h"
+#include <talloc.h>
 #include "system/passwd.h"
-#include "system/filesys.h"
+
+#else /* _SAMBA_BUILD_ */
+
+#error uid_wrapper_only_supported_in_samba_yet
+
+#endif
 
 #ifndef _PUBLIC_
 #define _PUBLIC_
@@ -42,9 +50,20 @@ static void uwrap_init(void)
        uwrap.initialised = true;
        if (getenv("UID_WRAPPER")) {
                uwrap.enabled = true;
+               /* put us in one group */
+               uwrap.ngroups = 1;
+               uwrap.groups = talloc_array(talloc_autofree_context(), gid_t, 1);
+               uwrap.groups[0] = 0;
        }
 }
 
+#undef uwrap_enabled
+_PUBLIC_ int uwrap_enabled(void)
+{
+       uwrap_init();
+       return uwrap.enabled?1:0;
+}
+
 _PUBLIC_ int uwrap_seteuid(uid_t euid)
 {
        uwrap_init();
@@ -94,14 +113,17 @@ _PUBLIC_ int uwrap_setgroups(size_t size, const gid_t *list)
 
        talloc_free(uwrap.groups);
        uwrap.ngroups = 0;
+       uwrap.groups = NULL;
 
-       uwrap.groups = talloc_array(talloc_autofree_context(), gid_t, size);
-       if (uwrap.groups == NULL) {
-               errno = ENOMEM;
-               return -1;
+       if (size != 0) {
+               uwrap.groups = talloc_array(talloc_autofree_context(), gid_t, size);
+               if (uwrap.groups == NULL) {
+                       errno = ENOMEM;
+                       return -1;
+               }
+               memcpy(uwrap.groups, list, size*sizeof(gid_t));
+               uwrap.ngroups = size;
        }
-       memcpy(uwrap.groups, list, size*sizeof(gid_t));
-       uwrap.ngroups = size;
        return 0;
 }
 
@@ -123,7 +145,7 @@ _PUBLIC_ int uwrap_getgroups(int size, gid_t *list)
                return -1;
        }
        memcpy(list, uwrap.groups, size*sizeof(gid_t));
-       return 0;
+       return uwrap.ngroups;
 }
 
 _PUBLIC_ uid_t uwrap_getuid(void)