Merge branch 'master' of ssh://jra@git.samba.org/data/git/samba
[kai/samba.git] / source4 / wrepl_server / wrepl_scavenging.c
index 4382195d5320423a7f8edc08ddcfc645a387cffd..a239403e3b0799dae1cda2186bbbf0e58058e7fd 100644 (file)
@@ -7,7 +7,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,
@@ -16,8 +16,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"
@@ -57,12 +56,12 @@ static NTSTATUS wreplsrv_scavenging_owned_records(struct wreplsrv_service *servi
        time_t now = time(NULL);
        const char *now_timestr;
        const char *action;
-       const char *old_state;
-       const char *new_state;
+       const char *old_state=NULL;
+       const char *new_state=NULL;
        uint32_t modify_flags;
-       BOOL modify_record;
-       BOOL delete_record;
-       BOOL delete_tombstones;
+       bool modify_record;
+       bool delete_record;
+       bool delete_tombstones;
        struct timeval tombstone_extra_time;
 
        now_timestr = ldb_timestring(tmp_mem, now);
@@ -75,9 +74,8 @@ static NTSTATUS wreplsrv_scavenging_owned_records(struct wreplsrv_service *servi
                                 "(expireTime<=%s))",
                                 owner_filter, now_timestr);
        NT_STATUS_HAVE_NO_MEMORY(filter);
-       ret = ldb_search(service->wins_db->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res);
+       ret = ldb_search(service->wins_db->ldb, tmp_mem, &res, NULL, LDB_SCOPE_SUBTREE, NULL, "%s", filter);
        if (ret != LDB_SUCCESS) return NT_STATUS_INTERNAL_DB_CORRUPTION;
-       talloc_steal(tmp_mem, res);
        DEBUG(10,("WINS scavenging: filter '%s' count %d\n", filter, res->count));
 
        tombstone_extra_time = timeval_add(&service->startup_time,
@@ -95,8 +93,8 @@ static NTSTATUS wreplsrv_scavenging_owned_records(struct wreplsrv_service *servi
                talloc_free(res->msgs[i]);
 
                modify_flags    = 0;
-               modify_record   = False;
-               delete_record   = False;
+               modify_record   = false;
+               delete_record   = false;
 
                switch (rec->state) {
                case WREPL_STATE_ACTIVE:
@@ -108,7 +106,7 @@ static NTSTATUS wreplsrv_scavenging_owned_records(struct wreplsrv_service *servi
                                rec->expire_time= service->config.tombstone_interval + now;
                        }
                        modify_flags    = 0;
-                       modify_record   = True;
+                       modify_record   = true;
                        break;
 
                case WREPL_STATE_RELEASED:
@@ -117,7 +115,7 @@ static NTSTATUS wreplsrv_scavenging_owned_records(struct wreplsrv_service *servi
                        rec->state      = WREPL_STATE_TOMBSTONE;
                        rec->expire_time= service->config.tombstone_timeout + now;
                        modify_flags    = WINSDB_FLAG_ALLOC_VERSION | WINSDB_FLAG_TAKE_OWNERSHIP;
-                       modify_record   = True;
+                       modify_record   = true;
                        break;
 
                case WREPL_STATE_TOMBSTONE:
@@ -125,7 +123,7 @@ static NTSTATUS wreplsrv_scavenging_owned_records(struct wreplsrv_service *servi
                        new_state       = "tombstone";
                        if (!delete_tombstones) break;
                        new_state       = "deleted";
-                       delete_record = True;
+                       delete_record = true;
                        break;
 
                case WREPL_STATE_RESERVED:
@@ -171,12 +169,12 @@ static NTSTATUS wreplsrv_scavenging_replica_non_active_records(struct wreplsrv_s
        time_t now = time(NULL);
        const char *now_timestr;
        const char *action;
-       const char *old_state;
-       const char *new_state;
+       const char *old_state=NULL;
+       const char *new_state=NULL;
        uint32_t modify_flags;
-       BOOL modify_record;
-       BOOL delete_record;
-       BOOL delete_tombstones;
+       bool modify_record;
+       bool delete_record;
+       bool delete_tombstones;
        struct timeval tombstone_extra_time;
 
        now_timestr = ldb_timestring(tmp_mem, now);
@@ -189,9 +187,8 @@ static NTSTATUS wreplsrv_scavenging_replica_non_active_records(struct wreplsrv_s
                                 "(!(recordState=%u))(expireTime<=%s))",
                                 owner_filter, WREPL_STATE_ACTIVE, now_timestr);
        NT_STATUS_HAVE_NO_MEMORY(filter);
-       ret = ldb_search(service->wins_db->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res);
+       ret = ldb_search(service->wins_db->ldb, tmp_mem, &res, NULL, LDB_SCOPE_SUBTREE, NULL, "%s", filter);
        if (ret != LDB_SUCCESS) return NT_STATUS_INTERNAL_DB_CORRUPTION;
-       talloc_steal(tmp_mem, res);
        DEBUG(10,("WINS scavenging: filter '%s' count %d\n", filter, res->count));
 
        tombstone_extra_time = timeval_add(&service->startup_time,
@@ -209,8 +206,8 @@ static NTSTATUS wreplsrv_scavenging_replica_non_active_records(struct wreplsrv_s
                talloc_free(res->msgs[i]);
 
                modify_flags    = 0;
-               modify_record   = False;
-               delete_record   = False;
+               modify_record   = false;
+               delete_record   = false;
 
                switch (rec->state) {
                case WREPL_STATE_ACTIVE:
@@ -224,7 +221,7 @@ static NTSTATUS wreplsrv_scavenging_replica_non_active_records(struct wreplsrv_s
                        rec->state      = WREPL_STATE_TOMBSTONE;
                        rec->expire_time= service->config.tombstone_timeout + now;
                        modify_flags    = 0;
-                       modify_record   = True;
+                       modify_record   = true;
                        break;
 
                case WREPL_STATE_TOMBSTONE:
@@ -232,7 +229,7 @@ static NTSTATUS wreplsrv_scavenging_replica_non_active_records(struct wreplsrv_s
                        new_state       = "tombstone";
                        if (!delete_tombstones) break;
                        new_state       = "deleted";
-                       delete_record = True;
+                       delete_record = true;
                        break;
 
                case WREPL_STATE_RESERVED:
@@ -283,9 +280,9 @@ static void verify_handler(struct irpc_request *ireq)
        const char *new_state = "active";
        const char *new_owner = "replica";
        uint32_t modify_flags = 0;
-       BOOL modify_record = False;
-       BOOL delete_record = False;
-       BOOL different = False;
+       bool modify_record = false;
+       bool delete_record = false;
+       bool different = false;
        int ret;
        NTSTATUS status;
        uint32_t i, j;
@@ -299,25 +296,25 @@ static void verify_handler(struct irpc_request *ireq)
         */
        status = irpc_call_recv(ireq);
        if (NT_STATUS_EQUAL(NT_STATUS_OBJECT_NAME_NOT_FOUND, status)) {
-               delete_record = True;
+               delete_record = true;
                new_state = "deleted";
        } else if (NT_STATUS_IS_OK(status) && rec->type != WREPL_TYPE_GROUP) {
                for (i=0; i < s->r.out.num_addrs; i++) {
-                       BOOL found = False;
+                       bool found = false;
                        for (j=0; rec->addresses[j]; j++) {
                                if (strcmp(s->r.out.addrs[i].addr, rec->addresses[j]->address) == 0) {
-                                       found = True;
+                                       found = true;
                                        break;
                                }
                        }
                        if (!found) {
-                               different = True;
+                               different = true;
                                break;
                        }
                }
        } else if (NT_STATUS_IS_OK(status) && rec->type == WREPL_TYPE_GROUP) {
                if (s->r.out.num_addrs != 1 || strcmp(s->r.out.addrs[0].addr, "255.255.255.255") != 0) {
-                       different = True;
+                       different = true;
                }
        }
 
@@ -337,7 +334,7 @@ static void verify_handler(struct irpc_request *ireq)
                for (i=0; rec->addresses[i]; i++) {
                        rec->addresses[i]->expire_time = rec->expire_time;
                }
-               modify_record   = True;
+               modify_record   = true;
                modify_flags    = WINSDB_FLAG_ALLOC_VERSION | WINSDB_FLAG_TAKE_OWNERSHIP;
                new_state       = "tombstone";
                new_owner       = "owned";
@@ -347,7 +344,7 @@ static void verify_handler(struct irpc_request *ireq)
                for (i=0; rec->addresses[i]; i++) {
                        rec->addresses[i]->expire_time = rec->expire_time;
                }
-               modify_record   = True;
+               modify_record   = true;
                modify_flags    = 0;
                new_state       = "active";
        }
@@ -388,10 +385,10 @@ static NTSTATUS wreplsrv_scavenging_replica_active_records(struct wreplsrv_servi
        const char *now_timestr;
        struct irpc_request *ireq;
        struct verify_state *s;
-       uint32_t *nbt_servers;
+       struct server_id *nbt_servers;
 
-       nbt_servers = irpc_servers_byname(service->task->msg_ctx, "nbt_server");
-       if ((nbt_servers == NULL) || (nbt_servers[0] == 0)) {
+       nbt_servers = irpc_servers_byname(service->task->msg_ctx, tmp_mem, "nbt_server");
+       if ((nbt_servers == NULL) || (nbt_servers[0].id == 0)) {
                return NT_STATUS_INTERNAL_ERROR;
        }
 
@@ -405,9 +402,8 @@ static NTSTATUS wreplsrv_scavenging_replica_active_records(struct wreplsrv_servi
                                 "(recordState=%u)(expireTime<=%s))",
                                 owner_filter, WREPL_STATE_ACTIVE, now_timestr);
        NT_STATUS_HAVE_NO_MEMORY(filter);
-       ret = ldb_search(service->wins_db->ldb, NULL, LDB_SCOPE_SUBTREE, filter, NULL, &res);
+       ret = ldb_search(service->wins_db->ldb, tmp_mem, &res, NULL, LDB_SCOPE_SUBTREE, NULL, "%s", filter);
        if (ret != LDB_SUCCESS) return NT_STATUS_INTERNAL_DB_CORRUPTION;
-       talloc_steal(tmp_mem, res);
        DEBUG(10,("WINS scavenging: filter '%s' count %d\n", filter, res->count));
 
        for (i=0; i < res->count; i++) {
@@ -435,7 +431,8 @@ static NTSTATUS wreplsrv_scavenging_replica_active_records(struct wreplsrv_servi
                 *             but we use a wins name query
                 */
                DEBUG(0,("ask wins server '%s' if '%s' with version_id:%llu still exists\n",
-                       rec->wins_owner, nbt_name_string(rec, rec->name), rec->version));
+                        rec->wins_owner, nbt_name_string(rec, rec->name), 
+                        (unsigned long long)rec->version));
 
                s = talloc_zero(tmp_mem, struct verify_state);
                NT_STATUS_HAVE_NO_MEMORY(s);
@@ -468,14 +465,14 @@ NTSTATUS wreplsrv_scavenging_run(struct wreplsrv_service *service)
 {
        NTSTATUS status;
        TALLOC_CTX *tmp_mem;
-       BOOL skip_first_run = False;
+       bool skip_first_run = false;
 
        if (!timeval_expired(&service->scavenging.next_run)) {
                return NT_STATUS_OK;
        }
 
        if (timeval_is_zero(&service->scavenging.next_run)) {
-               skip_first_run = True;
+               skip_first_run = true;
        }
 
        service->scavenging.next_run = timeval_current_ofs(service->config.scavenging_interval, 0);
@@ -497,23 +494,26 @@ NTSTATUS wreplsrv_scavenging_run(struct wreplsrv_service *service)
        DEBUG(4,("wreplsrv_scavenging_run(): start\n"));
 
        tmp_mem = talloc_new(service);
-       service->scavenging.processing = True;
+       NT_STATUS_HAVE_NO_MEMORY(tmp_mem);
+       service->scavenging.processing = true;
        status = wreplsrv_scavenging_owned_records(service,tmp_mem);
-       service->scavenging.processing = False;
+       service->scavenging.processing = false;
        talloc_free(tmp_mem);
        NT_STATUS_NOT_OK_RETURN(status);
 
        tmp_mem = talloc_new(service);  
-       service->scavenging.processing = True;
+       NT_STATUS_HAVE_NO_MEMORY(tmp_mem);
+       service->scavenging.processing = true;
        status = wreplsrv_scavenging_replica_non_active_records(service, tmp_mem);
-       service->scavenging.processing = False;
+       service->scavenging.processing = false;
        talloc_free(tmp_mem);
        NT_STATUS_NOT_OK_RETURN(status);
 
        tmp_mem = talloc_new(service);
-       service->scavenging.processing = True;
+       NT_STATUS_HAVE_NO_MEMORY(tmp_mem);
+       service->scavenging.processing = true;
        status = wreplsrv_scavenging_replica_active_records(service, tmp_mem);
-       service->scavenging.processing = False;
+       service->scavenging.processing = false;
        talloc_free(tmp_mem);
        NT_STATUS_NOT_OK_RETURN(status);