On Tue, Oct 21, 2014 at 11:14:47AM +0200, Pavel Reichl wrote:
On 10/20/2014 10:42 PM, Jakub Hrozek wrote:
>+void test_get_user_num(void **state)
>+{
>+ uid_t uid;
>+ gid_t gid;
>+ errno_t ret;
>+
>+ ret = sss_user_by_name_or_uid("123", &uid, &gid);
>+ assert_int_equal(ret, EOK);
>+ assert_int_equal(uid, 123);
>+ assert_int_equal(gid, 123);
gid 123 ?
>+}
>+
>+void test_get_user_str(void **state)
>+{
>+ uid_t uid;
>+ gid_t gid;
>+ errno_t ret;
>+
>+ ret = sss_user_by_name_or_uid("sssd", &uid, &gid);
>+ assert_int_equal(ret, EOK);
>+ assert_int_equal(uid, 123);
>+ assert_int_equal(gid, 456);
gid 456 ?
>+}
>+
[snip]
>+
>+errno_t sss_user_by_name_or_uid(const char *input, uid_t *_uid, gid_t *_gid)
>+{
>+ uid_t uid;
>+ gid_t gid;
>+ errno_t ret;
>+ char *endptr;
>+ struct passwd *pwd;
>+
I believe we should null errno here.
OK
>+ /* Try if it's an ID first */
>+ uid = strtouint32(input, &endptr, 10);
>+ gid = uid;
I'm sorry I don't understand why setting gid to uid in case that numeric
value is passed is the right thing to do. I think we should get the value of
gid from db all the time.
OK, calling getpwuid sounds like the right thing to do. I'll send new
patches -- thanks!
I suppose it's on purpose as we have tests (which I tried to ask
you
yesterday) that verify this behaviour, but I think that value of gid should
not matter whether we ask for it using uid or username.
Thanks for explaining.
>+ if (errno != 0 || *endptr != '\0') {
>+ ret = errno;
>+ if (ret == ERANGE) {
>+ DEBUG(SSSDBG_OP_FAILURE,
>+ "UID [%s] is out of range.\n", input);
>+ return ret;
>+ }
>+
>+ /* Nope, maybe a username? */
>+ pwd = getpwnam(input);
>+ if (pwd == NULL) {
>+ DEBUG(SSSDBG_OP_FAILURE,
>+ "[%s] is neither a valid UID nor a user name which could be
"
>+ "resolved by getpwnam().\n", input);
>+ return EINVAL;
>+ }
>+
>+ uid = pwd->pw_uid;
>+ gid = pwd->pw_gid;
>+ }
>+
>+ if (_uid) {
>+ *_uid = uid;
>+ }
>+
>+ if (_gid) {
>+ *_gid = gid;
>+ }
>+ return EOK;
>+}
_______________________________________________
sssd-devel mailing list
sssd-devel(a)lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/sssd-devel