RIP BOOL. Convert BOOL -> bool. I found a few interesting
[tprouty/samba.git] / source3 / libsmb / samlogon_cache.c
index e82ee8dbb8c74b689afa3f8dbdb8d209a6892c8e..b1d6c8d8f3d019cfb04d802fce21b3fd02ec52c6 100644 (file)
@@ -8,7 +8,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,
@@ -17,8 +17,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"
@@ -31,7 +30,7 @@ static TDB_CONTEXT *netsamlogon_tdb = NULL;
  open the tdb
  ***********************************************************************/
  
-BOOL netsamlogon_cache_init(void)
+bool netsamlogon_cache_init(void)
 {
        if (!netsamlogon_tdb) {
                netsamlogon_tdb = tdb_open_log(lock_path(NETSAMLOGON_TDB), 0,
@@ -46,7 +45,7 @@ BOOL netsamlogon_cache_init(void)
  Shutdown samlogon_cache database
 ***********************************************************************/
 
-BOOL netsamlogon_cache_shutdown(void)
+bool netsamlogon_cache_shutdown(void)
 {
        if(netsamlogon_tdb)
                return (tdb_close(netsamlogon_tdb) == 0);
@@ -59,8 +58,7 @@ BOOL netsamlogon_cache_shutdown(void)
 ***********************************************************************/
 void netsamlogon_clear_cached_user(TDB_CONTEXT *tdb, NET_USER_INFO_3 *user)
 {
-       TDB_DATA key;
-       BOOL got_tdb = False;
+       bool got_tdb = False;
        DOM_SID sid;
        fstring key_str, sid_string;
 
@@ -93,7 +91,7 @@ void netsamlogon_clear_cached_user(TDB_CONTEXT *tdb, NET_USER_INFO_3 *user)
 
        fstr_sprintf(key_str, "UG/%s", sid_to_string(sid_string, &sid));
 
-       DEBUG(10, ("netsamlogon_clear_cached_user: clearing %s\n", key.dptr));
+       DEBUG(10, ("netsamlogon_clear_cached_user: clearing %s\n", key_str));
 
        tdb_delete(tdb, string_tdb_data(key_str));
 
@@ -106,12 +104,12 @@ void netsamlogon_clear_cached_user(TDB_CONTEXT *tdb, NET_USER_INFO_3 *user)
  username should be in UTF-8 format
 ***********************************************************************/
 
-BOOL netsamlogon_cache_store( const char *username, NET_USER_INFO_3 *user )
+bool netsamlogon_cache_store( const char *username, NET_USER_INFO_3 *user )
 {
        TDB_DATA        data;
         fstring        keystr;
        prs_struct      ps;
-       BOOL            result = False;
+       bool            result = False;
        DOM_SID         user_sid;
        time_t          t = time(NULL);
        TALLOC_CTX      *mem_ctx;
@@ -156,7 +154,7 @@ BOOL netsamlogon_cache_store( const char *username, NET_USER_INFO_3 *user )
        if ( net_io_user_info3("", user, &ps, 0, 3, 0) ) 
        {
                data.dsize = prs_offset( &ps );
-               data.dptr = prs_data_p( &ps );
+               data.dptr = (uint8 *)prs_data_p( &ps );
 
                if (tdb_store_bystring(netsamlogon_tdb, keystr, data, TDB_REPLACE) != -1)
                        result = True;
@@ -193,21 +191,23 @@ NET_USER_INFO_3* netsamlogon_cache_get( TALLOC_CTX *mem_ctx, const DOM_SID *user
        data = tdb_fetch_bystring( netsamlogon_tdb, keystr );
        
        if ( data.dptr ) {
-               
-               if ( (user = SMB_MALLOC_P(NET_USER_INFO_3)) == NULL )
+
+               user = TALLOC_ZERO_P(mem_ctx, NET_USER_INFO_3);
+               if (user == NULL) {
                        return NULL;
-                       
+               }
+
                prs_init( &ps, 0, mem_ctx, UNMARSHALL );
-               prs_give_memory( &ps, data.dptr, data.dsize, True );
+               prs_give_memory( &ps, (char *)data.dptr, data.dsize, True );
                
                if ( !prs_uint32( "timestamp", &ps, 0, &t ) ) {
                        prs_mem_free( &ps );
-                       SAFE_FREE(user);
+                       TALLOC_FREE(user);
                        return False;
                }
                
                if ( !net_io_user_info3("", user, &ps, 0, 3, 0) ) {
-                       SAFE_FREE( user );
+                       TALLOC_FREE( user );
                }
                        
                prs_mem_free( &ps );
@@ -226,7 +226,7 @@ NET_USER_INFO_3* netsamlogon_cache_get( TALLOC_CTX *mem_ctx, const DOM_SID *user
                if ( (time_diff < 0 ) || (time_diff > lp_winbind_cache_time()) ) {
                        DEBUG(10,("netsamlogon_cache_get: cache entry expired \n"));
                        tdb_delete( netsamlogon_tdb, key );
-                       SAFE_FREE( user );
+                       TALLOC_FREE( user );
                }
 #endif
        }
@@ -234,11 +234,11 @@ NET_USER_INFO_3* netsamlogon_cache_get( TALLOC_CTX *mem_ctx, const DOM_SID *user
        return user;
 }
 
-BOOL netsamlogon_cache_have(const DOM_SID *user_sid)
+bool netsamlogon_cache_have(const DOM_SID *user_sid)
 {
        TALLOC_CTX *mem_ctx = talloc_init("netsamlogon_cache_have");
        NET_USER_INFO_3 *user = NULL;
-       BOOL result;
+       bool result;
 
        if (!mem_ctx)
                return False;
@@ -248,7 +248,6 @@ BOOL netsamlogon_cache_have(const DOM_SID *user_sid)
        result = (user != NULL);
 
        talloc_destroy(mem_ctx);
-       SAFE_FREE(user);
 
        return result;
 }