Remove "idmap alloc config : range" parameter
[amitay/samba.git] / source3 / winbindd / idmap_tdb.c
index e5f605361b4ebb8028f5ce6f2312dbfffa5cf82e..2b9520d54da4d3d29b0558323f039a41de5ac79c 100644 (file)
@@ -318,6 +318,7 @@ static NTSTATUS idmap_tdb_alloc_init( const char *params )
        uid_t high_uid = 0;
        gid_t low_gid = 0;
        gid_t high_gid = 0;
+       uint32_t low_id, high_id;
 
        /* use our own context here */
        ctx = talloc_new(NULL);
@@ -335,67 +336,47 @@ static NTSTATUS idmap_tdb_alloc_init( const char *params )
        talloc_free(ctx);
 
        /* load ranges */
-       idmap_tdb_state.low_uid = 0;
-       idmap_tdb_state.high_uid = 0;
-       idmap_tdb_state.low_gid = 0;
-       idmap_tdb_state.high_gid = 0;
-
-       range = lp_parm_const_string(-1, "idmap alloc config", "range", NULL);
-       if (range && range[0]) {
-               unsigned low_id, high_id;
-
-               if (sscanf(range, "%u - %u", &low_id, &high_id) == 2) {
-                       if (low_id < high_id) {
-                               idmap_tdb_state.low_gid = idmap_tdb_state.low_uid = low_id;
-                               idmap_tdb_state.high_gid = idmap_tdb_state.high_uid = high_id;
-                       } else {
-                               DEBUG(1, ("ERROR: invalid idmap alloc range [%s]", range));
-                       }
-               } else {
-                       DEBUG(1, ("ERROR: invalid syntax for idmap alloc config:range [%s]", range));
-               }
-       }
 
-       /* Create high water marks for group and user id */
-       if (lp_idmap_uid(&low_uid, &high_uid)) {
-               idmap_tdb_state.low_uid = low_uid;
-               idmap_tdb_state.high_uid = high_uid;
+       if (!lp_idmap_uid(&low_uid, &high_uid)
+           || !lp_idmap_gid(&low_gid, &high_gid)) {
+               DEBUG(1, ("idmap uid or idmap gid missing\n"));
+               return NT_STATUS_UNSUCCESSFUL;
        }
 
-       if (lp_idmap_gid(&low_gid, &high_gid)) {
-               idmap_tdb_state.low_gid = low_gid;
-               idmap_tdb_state.high_gid = high_gid;
-       }
+       idmap_tdb_state.low_uid = low_uid;
+       idmap_tdb_state.high_uid = high_uid;
+       idmap_tdb_state.low_gid = low_gid;
+       idmap_tdb_state.high_gid = high_gid;
 
        if (idmap_tdb_state.high_uid <= idmap_tdb_state.low_uid) {
                DEBUG(1, ("idmap uid range missing or invalid\n"));
                DEBUGADD(1, ("idmap will be unable to map foreign SIDs\n"));
                return NT_STATUS_UNSUCCESSFUL;
-       } else {
-               uint32 low_id;
-
-               if (((low_id = tdb_fetch_int32(idmap_alloc_tdb, HWM_USER)) == -1) ||
-                   (low_id < idmap_tdb_state.low_uid)) {
-                       if (tdb_store_int32(idmap_alloc_tdb, HWM_USER, idmap_tdb_state.low_uid) == -1) {
-                               DEBUG(0, ("Unable to initialise user hwm in idmap database\n"));
-                               return NT_STATUS_INTERNAL_DB_ERROR;
-                       }
-               }
        }
 
        if (idmap_tdb_state.high_gid <= idmap_tdb_state.low_gid) {
                DEBUG(1, ("idmap gid range missing or invalid\n"));
                DEBUGADD(1, ("idmap will be unable to map foreign SIDs\n"));
                return NT_STATUS_UNSUCCESSFUL;
-       } else {
-               uint32 low_id;
-
-               if (((low_id = tdb_fetch_int32(idmap_alloc_tdb, HWM_GROUP)) == -1) ||
-                   (low_id < idmap_tdb_state.low_gid)) {
-                       if (tdb_store_int32(idmap_alloc_tdb, HWM_GROUP, idmap_tdb_state.low_gid) == -1) {
-                               DEBUG(0, ("Unable to initialise group hwm in idmap database\n"));
-                               return NT_STATUS_INTERNAL_DB_ERROR;
-                       }
+       }
+
+       if (((low_id = tdb_fetch_int32(idmap_alloc_tdb, HWM_USER)) == -1) ||
+           (low_id < idmap_tdb_state.low_uid)) {
+               if (tdb_store_int32(idmap_alloc_tdb, HWM_USER,
+                                   idmap_tdb_state.low_uid) == -1) {
+                       DEBUG(0, ("Unable to initialise user hwm in idmap "
+                                 "database\n"));
+                       return NT_STATUS_INTERNAL_DB_ERROR;
+               }
+       }
+
+       if (((low_id = tdb_fetch_int32(idmap_alloc_tdb, HWM_GROUP)) == -1) ||
+           (low_id < idmap_tdb_state.low_gid)) {
+               if (tdb_store_int32(idmap_alloc_tdb, HWM_GROUP,
+                                   idmap_tdb_state.low_gid) == -1) {
+                       DEBUG(0, ("Unable to initialise group hwm in idmap "
+                                 "database\n"));
+                       return NT_STATUS_INTERNAL_DB_ERROR;
                }
        }
 
@@ -585,7 +566,7 @@ struct idmap_tdb_context {
  Initialise idmap database. 
 *****************************/
 
-static NTSTATUS idmap_tdb_db_init(struct idmap_domain *dom)
+static NTSTATUS idmap_tdb_db_init(struct idmap_domain *dom, const char *params)
 {
        NTSTATUS ret;
        struct idmap_tdb_context *ctx;
@@ -619,7 +600,6 @@ static NTSTATUS idmap_tdb_db_init(struct idmap_domain *dom)
        }
 
        dom->private_data = ctx;
-       dom->initialized = True;
 
        talloc_free(config_option);
        return NT_STATUS_OK;
@@ -774,14 +754,6 @@ static NTSTATUS idmap_tdb_unixids_to_sids(struct idmap_domain *dom, struct id_ma
        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++) {
@@ -820,14 +792,6 @@ static NTSTATUS idmap_tdb_sids_to_unixids(struct idmap_domain *dom, struct id_ma
        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++) {
@@ -868,14 +832,6 @@ static NTSTATUS idmap_tdb_set_mapping(struct idmap_domain *dom, const struct id_
        char *ksidstr, *kidstr;
        fstring tmp;
 
-       /* 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;
        }
@@ -983,14 +939,6 @@ static NTSTATUS idmap_tdb_remove_mapping(struct idmap_domain *dom, const struct
        char *ksidstr, *kidstr;
        fstring tmp;
 
-       /* 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;
        }
@@ -1171,14 +1119,6 @@ static NTSTATUS idmap_tdb_dump_data(struct idmap_domain *dom, struct id_map **ma
        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);
 
        data = TALLOC_ZERO_P(ctx, struct dump_data);
@@ -1229,6 +1169,8 @@ NTSTATUS idmap_tdb_init(void)
 {
        NTSTATUS ret;
 
+       DEBUG(10, ("calling idmap_tdb_init\n"));
+
        /* FIXME: bad hack to actually register also the alloc_tdb module without changining configure.in */
        ret = idmap_alloc_tdb_init();
        if (! NT_STATUS_IS_OK(ret)) {