s3-talloc Change TALLOC_ZERO_P() to talloc_zero()
[nivanova/samba-autobuild/.git] / source3 / libsmb / samlogon_cache.c
index 45354f1c77e4a086f6f0582796b1adf14d0fbc5b..67c0e08114a2f19a485fdd1553f6d0df2f1ff94c 100644 (file)
 */
 
 #include "includes.h"
+#include "system/filesys.h"
 #include "librpc/gen_ndr/ndr_krb5pac.h"
+#include "../libcli/security/security.h"
+#include "util_tdb.h"
 
 #define NETSAMLOGON_TDB        "netsamlogon_cache.tdb"
 
@@ -68,16 +71,9 @@ clear:
        }
        first_try = false;
 
-       DEBUG(0,("retry after CLEAR_IF_FIRST for '%s'\n", path));
-       tdb = tdb_open_log(path, 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
-                          O_RDWR | O_CREAT, 0600);
-       if (tdb) {
-               tdb_close(tdb);
-               goto again;
-       }
-       DEBUG(0,("tdb_open_log(%s) with CLEAR_IF_FIRST - failed\n", path));
-
-       return false;
+       DEBUG(0,("retry after truncate for '%s'\n", path));
+       truncate(path, 0);
+       goto again;
 }
 
 
@@ -98,14 +94,9 @@ bool netsamlogon_cache_shutdown(void)
  Clear cache getpwnam and getgroups entries from the winbindd cache
 ***********************************************************************/
 
-void netsamlogon_clear_cached_user(struct netr_SamInfo3 *info3)
+void netsamlogon_clear_cached_user(const struct dom_sid *user_sid)
 {
-       struct dom_sid  user_sid;
-       fstring keystr, tmp;
-
-       if (!info3) {
-               return;
-       }
+       fstring keystr;
 
        if (!netsamlogon_cache_init()) {
                DEBUG(0,("netsamlogon_clear_cached_user: cannot open "
@@ -113,10 +104,9 @@ void netsamlogon_clear_cached_user(struct netr_SamInfo3 *info3)
                        NETSAMLOGON_TDB));
                return;
        }
-       sid_compose(&user_sid, info3->base.domain_sid, info3->base.rid);
 
        /* Prepare key as DOMAIN-SID/USER-RID string */
-       slprintf(keystr, sizeof(keystr), "%s", sid_to_fstring(tmp, &user_sid));
+       sid_to_fstring(keystr, user_sid);
 
        DEBUG(10,("netsamlogon_clear_cached_user: SID [%s]\n", keystr));
 
@@ -131,7 +121,7 @@ void netsamlogon_clear_cached_user(struct netr_SamInfo3 *info3)
 bool netsamlogon_cache_store(const char *username, struct netr_SamInfo3 *info3)
 {
        TDB_DATA data;
-       fstring keystr, tmp;
+       fstring keystr;
        bool result = false;
        struct dom_sid  user_sid;
        time_t t = time(NULL);
@@ -153,13 +143,13 @@ bool netsamlogon_cache_store(const char *username, struct netr_SamInfo3 *info3)
        sid_compose(&user_sid, info3->base.domain_sid, info3->base.rid);
 
        /* Prepare key as DOMAIN-SID/USER-RID string */
-       slprintf(keystr, sizeof(keystr), "%s", sid_to_fstring(tmp, &user_sid));
+       sid_to_fstring(keystr, &user_sid);
 
        DEBUG(10,("netsamlogon_cache_store: SID [%s]\n", keystr));
 
        /* Prepare data */
 
-       if (!(mem_ctx = TALLOC_P( NULL, int))) {
+       if (!(mem_ctx = talloc( NULL, int))) {
                DEBUG(0,("netsamlogon_cache_store: talloc() failed!\n"));
                return false;
        }
@@ -227,7 +217,7 @@ struct netr_SamInfo3 *netsamlogon_cache_get(TALLOC_CTX *mem_ctx, const struct do
                return NULL;
        }
 
-       info3 = TALLOC_ZERO_P(mem_ctx, struct netr_SamInfo3);
+       info3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
        if (!info3) {
                goto done;
        }