Remove "idmap alloc config : range" parameter
[amitay/samba.git] / source3 / winbindd / idmap_tdb2.c
index ab89e615f780d98cd1e7b36d04d6a97c0a4a0c69..cb5e9ec6d408bac846e6cc8e0820a46c94ce8581 100644 (file)
@@ -128,62 +128,46 @@ static NTSTATUS idmap_tdb2_alloc_load(void)
        uid_t high_uid = 0;
        gid_t low_gid = 0;
        gid_t high_gid = 0;
-
-       /* load ranges */
-       idmap_tdb2_state.low_uid = 0;
-       idmap_tdb2_state.high_uid = 0;
-       idmap_tdb2_state.low_gid = 0;
-       idmap_tdb2_state.high_gid = 0;
+       uint32 low_id, high_id;
 
        /* see if a idmap script is configured */
-       idmap_tdb2_state.idmap_script = lp_parm_const_string(-1, "idmap", "script", NULL);
+       idmap_tdb2_state.idmap_script = lp_parm_const_string(-1, "idmap",
+                                                            "script", NULL);
 
        if (idmap_tdb2_state.idmap_script) {
-               DEBUG(1, ("using idmap script '%s'\n", idmap_tdb2_state.idmap_script));
-       }
-
-       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_tdb2_state.low_gid = idmap_tdb2_state.low_uid = low_id;
-                               idmap_tdb2_state.high_gid = idmap_tdb2_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));
-               }
+               DEBUG(1, ("using idmap script '%s'\n",
+                         idmap_tdb2_state.idmap_script));
        }
 
+       /* load ranges */
+
        /* Create high water marks for group and user id */
-       if (lp_idmap_uid(&low_uid, &high_uid)) {
-               idmap_tdb2_state.low_uid = low_uid;
-               idmap_tdb2_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_tdb2_state.low_gid = low_gid;
-               idmap_tdb2_state.high_gid = high_gid;
-       }
+       idmap_tdb2_state.low_uid = low_uid;
+       idmap_tdb2_state.high_uid = high_uid;
+       idmap_tdb2_state.low_gid = low_gid;
+       idmap_tdb2_state.high_gid = high_gid;
 
        if (idmap_tdb2_state.high_uid <= idmap_tdb2_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 = dbwrap_fetch_int32(idmap_tdb2_perm,
-                                                 HWM_USER)) == -1) ||
-                   (low_id < idmap_tdb2_state.low_uid)) {
-                       if (dbwrap_store_int32(
-                                   idmap_tdb2_perm, HWM_USER,
-                                   idmap_tdb2_state.low_uid) == -1) {
-                               DEBUG(0, ("Unable to initialise user hwm in idmap database\n"));
-                               return NT_STATUS_INTERNAL_DB_ERROR;
-                       }
+       }
+
+       if (((low_id = dbwrap_fetch_int32(idmap_tdb2_perm,
+                                         HWM_USER)) == -1) ||
+           (low_id < idmap_tdb2_state.low_uid)) {
+               if (dbwrap_store_int32(
+                           idmap_tdb2_perm, HWM_USER,
+                           idmap_tdb2_state.low_uid) == -1) {
+                       DEBUG(0, ("Unable to initialise user hwm in idmap "
+                                 "database\n"));
+                       return NT_STATUS_INTERNAL_DB_ERROR;
                }
        }
 
@@ -191,18 +175,17 @@ static NTSTATUS idmap_tdb2_alloc_load(void)
                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 = dbwrap_fetch_int32(idmap_tdb2_perm,
-                                                 HWM_GROUP)) == -1) ||
-                   (low_id < idmap_tdb2_state.low_gid)) {
-                       if (dbwrap_store_int32(
-                                   idmap_tdb2_perm, HWM_GROUP,
-                                   idmap_tdb2_state.low_gid) == -1) {
-                               DEBUG(0, ("Unable to initialise group hwm in idmap database\n"));
-                               return NT_STATUS_INTERNAL_DB_ERROR;
-                       }
+       }
+
+       if (((low_id = dbwrap_fetch_int32(idmap_tdb2_perm,
+                                         HWM_GROUP)) == -1) ||
+           (low_id < idmap_tdb2_state.low_gid)) {
+               if (dbwrap_store_int32(
+                           idmap_tdb2_perm, HWM_GROUP,
+                           idmap_tdb2_state.low_gid) == -1) {
+                       DEBUG(0, ("Unable to initialise group hwm in idmap "
+                                 "database\n"));
+                       return NT_STATUS_INTERNAL_DB_ERROR;
                }
        }
 
@@ -431,7 +414,8 @@ static NTSTATUS tdb2_delete_bystring(const char *keystr)
 /*
   Initialise idmap database. 
 */
-static NTSTATUS idmap_tdb2_db_init(struct idmap_domain *dom)
+static NTSTATUS idmap_tdb2_db_init(struct idmap_domain *dom,
+                                  const char *params)
 {
        NTSTATUS ret;
        struct idmap_tdb2_context *ctx;
@@ -464,7 +448,6 @@ static NTSTATUS idmap_tdb2_db_init(struct idmap_domain *dom)
        }
 
        dom->private_data = ctx;
-       dom->initialized = True;
 
        talloc_free(config_option);
        return NT_STATUS_OK;
@@ -725,14 +708,6 @@ static NTSTATUS idmap_tdb2_unixids_to_sids(struct idmap_domain *dom, struct id_m
        NTSTATUS ret;
        int i;
 
-       /* make sure we initialized */
-       if ( ! dom->initialized) {
-               ret = idmap_tdb2_db_init(dom);
-               if ( ! NT_STATUS_IS_OK(ret)) {
-                       return ret;
-               }
-       }
-
        ctx = talloc_get_type(dom->private_data, struct idmap_tdb2_context);
 
        for (i = 0; ids[i]; i++) {
@@ -770,14 +745,6 @@ static NTSTATUS idmap_tdb2_sids_to_unixids(struct idmap_domain *dom, struct id_m
        NTSTATUS ret;
        int i;
 
-       /* make sure we initialized */
-       if ( ! dom->initialized) {
-               ret = idmap_tdb2_db_init(dom);
-               if ( ! NT_STATUS_IS_OK(ret)) {
-                       return ret;
-               }
-       }
-
        ctx = talloc_get_type(dom->private_data, struct idmap_tdb2_context);
 
        for (i = 0; ids[i]; i++) {
@@ -819,14 +786,6 @@ static NTSTATUS idmap_tdb2_set_mapping(struct idmap_domain *dom, const struct id
        struct db_record *update_lock = NULL;
        struct db_record *rec = NULL;
 
-       /* make sure we initialized */
-       if ( ! dom->initialized) {
-               ret = idmap_tdb2_db_init(dom);
-               if ( ! NT_STATUS_IS_OK(ret)) {
-                       return ret;
-               }
-       }
-
        if (!map || !map->sid) {
                return NT_STATUS_INVALID_PARAMETER;
        }