s3-talloc Change TALLOC_ZERO_P() to talloc_zero()
[nivanova/samba-autobuild/.git] / source3 / winbindd / winbindd_cred_cache.c
index 25f14f49384ad5d9060f1bd04e6c0af426d5d880..5e79a96ca7642a8824364bf8412a9ff8a6d2c209 100644 (file)
@@ -25,6 +25,7 @@
 #include "winbindd.h"
 #include "../libcli/auth/libcli_auth.h"
 #include "smb_krb5.h"
+#include "libads/kerberos_proto.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
@@ -47,7 +48,12 @@ static void add_krb5_ticket_gain_handler_event(struct WINBINDD_CCACHE_ENTRY *,
 /* The Krb5 ticket refresh handler should be scheduled
    at one-half of the period from now till the tkt
    expiration */
-#define KRB5_EVENT_REFRESH_TIME(x) ((x) - (((x) - time(NULL))/2))
+
+static time_t krb5_event_refresh_time(time_t end_time)
+{
+       time_t rest = end_time - time(NULL);
+       return end_time - rest/2;
+}
 
 /****************************************************************
  Find an entry by name.
@@ -183,7 +189,7 @@ rekinit:
                        /* The tkt should be refreshed at one-half the period
                           from now to the expiration time */
                        expire_time = entry->refresh_time;
-                       new_start = KRB5_EVENT_REFRESH_TIME(entry->refresh_time);
+                       new_start = krb5_event_refresh_time(entry->refresh_time);
 #endif
                        goto done;
                } else {
@@ -207,7 +213,7 @@ rekinit:
        new_start = time(NULL) + 30;
 #else
        expire_time = new_start;
-       new_start = KRB5_EVENT_REFRESH_TIME(new_start);
+       new_start = krb5_event_refresh_time(new_start);
 #endif
 
        gain_root_privilege();
@@ -269,7 +275,7 @@ done:
         * but try to regain ticket if it is possible */
        if (entry->renew_until && expire_time
             && (entry->renew_until <= expire_time)) {
-               /* try to regain ticket 10 seconds beforre expiration */
+               /* try to regain ticket 10 seconds before expiration */
                expire_time -= 10;
                add_krb5_ticket_gain_handler_event(entry,
                                        timeval_set(expire_time, 0));
@@ -359,7 +365,7 @@ static void krb5_ticket_gain_handler(struct event_context *event_ctx,
 
   retry_later:
  
-#if defined(DEBUG_KRB5_TKT_REGAIN)
+#if defined(DEBUG_KRB5_TKT_RENEWAL)
        t = timeval_set(time(NULL) + 30, 0);
 #else
        t = timeval_current_ofs(MAX(30, lp_winbind_cache_time()), 0);
@@ -373,7 +379,7 @@ static void krb5_ticket_gain_handler(struct event_context *event_ctx,
 #if defined(DEBUG_KRB5_TKT_RENEWAL)
        t = timeval_set(time(NULL) + 30, 0);
 #else
-       t = timeval_set(KRB5_EVENT_REFRESH_TIME(entry->refresh_time), 0);
+       t = timeval_set(krb5_event_refresh_time(entry->refresh_time), 0);
 #endif
 
        if (entry->refresh_time == 0) {
@@ -558,7 +564,8 @@ NTSTATUS add_ccache_to_list(const char *princ_name,
 #if defined(DEBUG_KRB5_TKT_RENEWAL)
                                t = timeval_set(time(NULL)+30, 0);
 #else
-                               t = timeval_set(KRB5_EVENT_REFRESH_TIME(ticket_end), 0);
+                               t = timeval_set(krb5_event_refresh_time(ticket_end),
+                                               0);
 #endif
                                if (!entry->refresh_time) {
                                        entry->refresh_time = t.tv_sec;
@@ -589,7 +596,7 @@ NTSTATUS add_ccache_to_list(const char *princ_name,
                return NT_STATUS_OK;
        }
 
-       entry = TALLOC_P(NULL, struct WINBINDD_CCACHE_ENTRY);
+       entry = talloc(NULL, struct WINBINDD_CCACHE_ENTRY);
        if (!entry) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -642,7 +649,7 @@ NTSTATUS add_ccache_to_list(const char *princ_name,
 #if defined(DEBUG_KRB5_TKT_RENEWAL)
                t = timeval_set(time(NULL)+30, 0);
 #else
-               t = timeval_set(KRB5_EVENT_REFRESH_TIME(ticket_end), 0);
+               t = timeval_set(krb5_event_refresh_time(ticket_end), 0);
 #endif
                if (entry->refresh_time == 0) {
                        entry->refresh_time = t.tv_sec;
@@ -901,7 +908,7 @@ static NTSTATUS winbindd_add_memory_creds_internal(const char *username,
                return winbindd_replace_memory_creds_internal(memcredp, pass);
        }
 
-       memcredp = TALLOC_ZERO_P(NULL, struct WINBINDD_MEMORY_CREDS);
+       memcredp = talloc_zero(NULL, struct WINBINDD_MEMORY_CREDS);
        if (!memcredp) {
                return NT_STATUS_NO_MEMORY;
        }