r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[vlendec/samba-autobuild/.git] / source3 / nsswitch / idmap_tdb.c
index 73db1def0ce844571cd053ed43bda002c55cd98e..97000689fa1d70c7e3520829c046020a48fc0291 100644 (file)
@@ -10,7 +10,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
    
    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,
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -19,8 +19,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    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"
 */
 
 #include "includes.h"
@@ -586,7 +585,7 @@ struct idmap_tdb_context {
  Initialise idmap database. 
 *****************************/
 
  Initialise idmap database. 
 *****************************/
 
-static NTSTATUS idmap_tdb_db_init(struct idmap_domain *dom, const char *compat_params)
+static NTSTATUS idmap_tdb_db_init(struct idmap_domain *dom)
 {
        NTSTATUS ret;
        struct idmap_tdb_context *ctx;
 {
        NTSTATUS ret;
        struct idmap_tdb_context *ctx;
@@ -620,6 +619,7 @@ static NTSTATUS idmap_tdb_db_init(struct idmap_domain *dom, const char *compat_p
        }
 
        dom->private_data = ctx;
        }
 
        dom->private_data = ctx;
+       dom->initialized = True;
 
        talloc_free(config_option);
        return NT_STATUS_OK;
 
        talloc_free(config_option);
        return NT_STATUS_OK;
@@ -772,6 +772,14 @@ static NTSTATUS idmap_tdb_unixids_to_sids(struct idmap_domain *dom, struct id_ma
        NTSTATUS ret;
        int i;
 
        NTSTATUS ret;
        int i;
 
+       /* make sure we initialized */
+       if ( ! dom->initialized) {
+               ret = idmap_tdb_db_init(dom);
+               if ( ! NT_STATUS_IS_OK(ret)) {
+                       return ret;
+               }
+       }
+
        ctx = talloc_get_type(dom->private_data, struct idmap_tdb_context);
 
        for (i = 0; ids[i]; i++) {
        ctx = talloc_get_type(dom->private_data, struct idmap_tdb_context);
 
        for (i = 0; ids[i]; i++) {
@@ -810,6 +818,14 @@ static NTSTATUS idmap_tdb_sids_to_unixids(struct idmap_domain *dom, struct id_ma
        NTSTATUS ret;
        int i;
 
        NTSTATUS ret;
        int i;
 
+       /* make sure we initialized */
+       if ( ! dom->initialized) {
+               ret = idmap_tdb_db_init(dom);
+               if ( ! NT_STATUS_IS_OK(ret)) {
+                       return ret;
+               }
+       }
+
        ctx = talloc_get_type(dom->private_data, struct idmap_tdb_context);
 
        for (i = 0; ids[i]; i++) {
        ctx = talloc_get_type(dom->private_data, struct idmap_tdb_context);
 
        for (i = 0; ids[i]; i++) {
@@ -849,6 +865,14 @@ static NTSTATUS idmap_tdb_set_mapping(struct idmap_domain *dom, const struct id_
        TDB_DATA ksid, kid, data;
        char *ksidstr, *kidstr;
 
        TDB_DATA ksid, kid, data;
        char *ksidstr, *kidstr;
 
+       /* make sure we initialized */
+       if ( ! dom->initialized) {
+               ret = idmap_tdb_db_init(dom);
+               if ( ! NT_STATUS_IS_OK(ret)) {
+                       return ret;
+               }
+       }
+
        if (!map || !map->sid) {
                return NT_STATUS_INVALID_PARAMETER;
        }
        if (!map || !map->sid) {
                return NT_STATUS_INVALID_PARAMETER;
        }
@@ -954,6 +978,14 @@ static NTSTATUS idmap_tdb_remove_mapping(struct idmap_domain *dom, const struct
        TDB_DATA ksid, kid, data;
        char *ksidstr, *kidstr;
 
        TDB_DATA ksid, kid, data;
        char *ksidstr, *kidstr;
 
+       /* make sure we initialized */
+       if ( ! dom->initialized) {
+               ret = idmap_tdb_db_init(dom);
+               if ( ! NT_STATUS_IS_OK(ret)) {
+                       return ret;
+               }
+       }
+
        if (!map || !map->sid) {
                return NT_STATUS_INVALID_PARAMETER;
        }
        if (!map || !map->sid) {
                return NT_STATUS_INVALID_PARAMETER;
        }
@@ -1133,9 +1165,17 @@ static NTSTATUS idmap_tdb_dump_data(struct idmap_domain *dom, struct id_map **ma
        struct dump_data *data;
        NTSTATUS ret = NT_STATUS_OK;
 
        struct dump_data *data;
        NTSTATUS ret = NT_STATUS_OK;
 
+       /* make sure we initialized */
+       if ( ! dom->initialized) {
+               ret = idmap_tdb_db_init(dom);
+               if ( ! NT_STATUS_IS_OK(ret)) {
+                       return ret;
+               }
+       }
+
        ctx = talloc_get_type(dom->private_data, struct idmap_tdb_context);
 
        ctx = talloc_get_type(dom->private_data, struct idmap_tdb_context);
 
-       data = talloc_zero(ctx, struct dump_data);
+       data = TALLOC_ZERO_P(ctx, struct dump_data);
        if ( ! data) {
                DEBUG(0, ("Out of memory!\n"));
                return NT_STATUS_NO_MEMORY;
        if ( ! data) {
                DEBUG(0, ("Out of memory!\n"));
                return NT_STATUS_NO_MEMORY;