summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2010-10-18 20:23:48 +0200
committerStephen Gallagher <sgallagh@redhat.com>2010-10-22 10:49:01 -0400
commit59216d82123688ae360757bf8c5eb77236555416 (patch)
treee0912a525054b6cac17ef74b07978ac13446391c
parent8a46f4c638abbdc1dde41e0e5e9688bd19cd253a (diff)
downloadsssd2-59216d82123688ae360757bf8c5eb77236555416.tar.gz
sssd2-59216d82123688ae360757bf8c5eb77236555416.tar.xz
sssd2-59216d82123688ae360757bf8c5eb77236555416.zip
Use unsigned long for conversion to id_t
We used strtol() on a number of places to convert into uid_t or gid_t from a string representation such as LDAP attribute, but on some platforms, unsigned long might be necessary to store big id_t values. This patch converts to using strtoul() instead.
-rw-r--r--src/providers/ldap/ldap_id.c4
-rw-r--r--src/providers/ldap/sdap_async_accounts.c46
-rw-r--r--src/providers/proxy/proxy.c4
-rw-r--r--src/util/find_uid.c8
4 files changed, 22 insertions, 40 deletions
diff --git a/src/providers/ldap/ldap_id.c b/src/providers/ldap/ldap_id.c
index f0e96677..5a9f5755 100644
--- a/src/providers/ldap/ldap_id.c
+++ b/src/providers/ldap/ldap_id.c
@@ -201,7 +201,7 @@ static void users_get_done(struct tevent_req *subreq)
case BE_FILTER_IDNUM:
errno = 0;
- uid = (uid_t)strtol(state->name, &endptr, 0);
+ uid = (uid_t) strtoul(state->name, &endptr, 0);
if (errno || *endptr || (state->name == endptr)) {
tevent_req_error(req, errno);
return;
@@ -422,7 +422,7 @@ static void groups_get_done(struct tevent_req *subreq)
case BE_FILTER_IDNUM:
errno = 0;
- gid = (gid_t)strtol(state->name, &endptr, 0);
+ gid = (gid_t) strtoul(state->name, &endptr, 0);
if (errno || *endptr || (state->name == endptr)) {
tevent_req_error(req, errno);
return;
diff --git a/src/providers/ldap/sdap_async_accounts.c b/src/providers/ldap/sdap_async_accounts.c
index bc242719..0244d93e 100644
--- a/src/providers/ldap/sdap_async_accounts.c
+++ b/src/providers/ldap/sdap_async_accounts.c
@@ -57,7 +57,7 @@ static struct tevent_req *sdap_save_user_send(TALLOC_CTX *memctx,
const char *gecos;
const char *homedir;
const char *shell;
- long int l;
+ unsigned long l;
uid_t uid;
gid_t gid;
struct sysdb_attrs *user_attrs;
@@ -111,21 +111,15 @@ static struct tevent_req *sdap_save_user_send(TALLOC_CTX *memctx,
if (el->num_values == 0) shell = NULL;
else shell = (const char *)el->values[0].data;
- ret = sysdb_attrs_get_el(state->attrs,
- opts->user_map[SDAP_AT_USER_UID].sys_name, &el);
- if (ret) goto fail;
- if (el->num_values == 0) {
+ ret = sysdb_attrs_get_ulong(attrs,
+ opts->user_map[SDAP_AT_USER_UID].sys_name,
+ &l);
+ if (ret != EOK) {
DEBUG(1, ("no uid provided for [%s] in domain [%s].\n",
state->name, dom->name));
ret = EINVAL;
goto fail;
}
- errno = 0;
- l = strtol((const char *)el->values[0].data, NULL, 0);
- if (errno) {
- ret = EINVAL;
- goto fail;
- }
uid = l;
/* check that the uid is valid for this domain */
@@ -136,21 +130,15 @@ static struct tevent_req *sdap_save_user_send(TALLOC_CTX *memctx,
goto fail;
}
- ret = sysdb_attrs_get_el(state->attrs,
- opts->user_map[SDAP_AT_USER_GID].sys_name, &el);
- if (ret) goto fail;
- if (el->num_values == 0) {
+ ret = sysdb_attrs_get_ulong(attrs,
+ opts->user_map[SDAP_AT_USER_GID].sys_name,
+ &l);
+ if (ret != EOK) {
DEBUG(1, ("no gid provided for [%s] in domain [%s].\n",
state->name, dom->name));
ret = EINVAL;
goto fail;
}
- errno = 0;
- l = strtol((const char *)el->values[0].data, NULL, 0);
- if (errno) {
- ret = EINVAL;
- goto fail;
- }
gid = l;
/* check that the gid is valid for this domain */
@@ -830,7 +818,7 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
struct sdap_save_group_state *state;
struct ldb_message_element *el;
struct sysdb_attrs *group_attrs;
- long int l;
+ unsigned long l;
gid_t gid;
int ret;
@@ -852,21 +840,15 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
}
state->name = (const char *)el->values[0].data;
- ret = sysdb_attrs_get_el(attrs,
- opts->group_map[SDAP_AT_GROUP_GID].sys_name, &el);
- if (ret) goto fail;
- if (el->num_values == 0) {
+ ret = sysdb_attrs_get_ulong(attrs,
+ opts->group_map[SDAP_AT_GROUP_GID].sys_name,
+ &l);
+ if (ret != EOK) {
DEBUG(1, ("no gid provided for [%s] in domain [%s].\n",
state->name, dom->name));
ret = EINVAL;
goto fail;
}
- errno = 0;
- l = strtol((const char *)el->values[0].data, NULL, 0);
- if (errno) {
- ret = EINVAL;
- goto fail;
- }
gid = l;
/* check that the gid is valid for this domain */
diff --git a/src/providers/proxy/proxy.c b/src/providers/proxy/proxy.c
index 8bdc94aa..144ab45f 100644
--- a/src/providers/proxy/proxy.c
+++ b/src/providers/proxy/proxy.c
@@ -2823,7 +2823,7 @@ static void proxy_get_account_info(struct be_req *breq)
} else {
char *endptr;
errno = 0;
- uid = (uid_t)strtol(ar->filter_value, &endptr, 0);
+ uid = (uid_t) strtoul(ar->filter_value, &endptr, 0);
if (errno || *endptr || (ar->filter_value == endptr)) {
return proxy_reply(breq, DP_ERR_FATAL,
EINVAL, "Invalid attr type");
@@ -2878,7 +2878,7 @@ static void proxy_get_account_info(struct be_req *breq)
} else {
char *endptr;
errno = 0;
- gid = (gid_t)strtol(ar->filter_value, &endptr, 0);
+ gid = (gid_t) strtoul(ar->filter_value, &endptr, 0);
if (errno || *endptr || (ar->filter_value == endptr)) {
return proxy_reply(breq, DP_ERR_FATAL,
EINVAL, "Invalid attr type");
diff --git a/src/util/find_uid.c b/src/util/find_uid.c
index 02d66863..bd62b123 100644
--- a/src/util/find_uid.c
+++ b/src/util/find_uid.c
@@ -132,10 +132,10 @@ static errno_t get_uid_from_pid(const pid_t pid, uid_t *uid)
*e = '\0';
}
errno = 0;
- num = strtol(p, &endptr, 10);
+ num = strtoul(p, &endptr, 10);
error = errno;
- if (error == ERANGE) {
- DEBUG(1, ("strtol failed [%s].\n", strerror(error)));
+ if (error != 0) {
+ DEBUG(1, ("strtoul failed [%s].\n", strerror(error)));
return error;
}
if (*endptr != '\0') {
@@ -143,7 +143,7 @@ static errno_t get_uid_from_pid(const pid_t pid, uid_t *uid)
return EINVAL;
}
- if (num < 0 || num >= INT_MAX) {
+ if (num >= UINT32_MAX) {
DEBUG(1, ("uid out of range.\n"));
return ERANGE;
}