1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
#include "apr_errno.h"
19
#include "apr_general.h"
23
static void uid_current(abts_case *tc, void *data)
28
APR_ASSERT_SUCCESS(tc, "apr_uid_current failed",
29
apr_uid_current(&uid, &gid, p));
32
static void username(abts_case *tc, void *data)
36
apr_uid_t retreived_uid;
37
apr_gid_t retreived_gid;
40
APR_ASSERT_SUCCESS(tc, "apr_uid_current failed",
41
apr_uid_current(&uid, &gid, p));
43
APR_ASSERT_SUCCESS(tc, "apr_uid_name_get failed",
44
apr_uid_name_get(&uname, uid, p));
45
ABTS_PTR_NOTNULL(tc, uname);
47
APR_ASSERT_SUCCESS(tc, "apr_uid_get failed",
48
apr_uid_get(&retreived_uid, &retreived_gid, uname, p));
50
APR_ASSERT_SUCCESS(tc, "apr_uid_compare failed",
51
apr_uid_compare(uid, retreived_uid));
53
/* ### this fudge was added for Win32 but makes the test return NotImpl
54
* on Unix if run as root, when !gid is also true. */
55
if (!gid || !retreived_gid) {
56
/* The function had no way to recover the gid (this would have been
57
* an ENOTIMPL if apr_uid_ functions didn't try to double-up and
58
* also return apr_gid_t values, which was bogus.
61
ABTS_NOT_IMPL(tc, "Groups from apr_uid_current");
64
ABTS_NOT_IMPL(tc, "Groups from apr_uid_get");
69
APR_ASSERT_SUCCESS(tc, "apr_gid_compare failed",
70
apr_gid_compare(gid, retreived_gid));
76
static void groupname(abts_case *tc, void *data)
80
apr_gid_t retreived_gid;
83
APR_ASSERT_SUCCESS(tc, "apr_uid_current failed",
84
apr_uid_current(&uid, &gid, p));
86
APR_ASSERT_SUCCESS(tc, "apr_gid_name_get failed",
87
apr_gid_name_get(&gname, gid, p));
88
ABTS_PTR_NOTNULL(tc, gname);
90
APR_ASSERT_SUCCESS(tc, "apr_gid_get failed",
91
apr_gid_get(&retreived_gid, gname, p));
93
APR_ASSERT_SUCCESS(tc, "apr_gid_compare failed",
94
apr_gid_compare(gid, retreived_gid));
99
static void fail_userinfo(abts_case *tc, void *data)
109
rv = apr_uid_name_get(&tmp, uid, p);
110
ABTS_ASSERT(tc, "apr_uid_name_get should fail or "
111
"return a user name",
112
rv != APR_SUCCESS || tmp != NULL);
116
rv = apr_gid_name_get(&tmp, gid, p);
117
ABTS_ASSERT(tc, "apr_gid_name_get should fail or "
118
"return a group name",
119
rv != APR_SUCCESS || tmp != NULL);
123
rv = apr_gid_get(&gid, "I_AM_NOT_A_GROUP", p);
124
ABTS_ASSERT(tc, "apr_gid_get should fail or "
125
"set a group number",
126
rv != APR_SUCCESS || gid == 424242);
130
rv = apr_uid_get(&uid, &gid, "I_AM_NOT_A_USER", p);
131
ABTS_ASSERT(tc, "apr_gid_get should fail or "
132
"set a user and group number",
133
rv != APR_SUCCESS || uid == 424242 || gid == 4242442);
137
rv = apr_uid_homepath_get(&tmp, "I_AM_NOT_A_USER", p);
138
ABTS_ASSERT(tc, "apr_uid_homepath_get should fail or "
140
rv != APR_SUCCESS || tmp != NULL);
144
static void fail_userinfo(abts_case *tc, void *data)
146
ABTS_NOT_IMPL(tc, "Users are not opaque integers on this platform");
151
static void users_not_impl(abts_case *tc, void *data)
153
ABTS_NOT_IMPL(tc, "Users not implemented on this platform");
157
abts_suite *testuser(abts_suite *suite)
159
suite = ADD_SUITE(suite)
162
abts_run_test(suite, users_not_impl, NULL);
164
abts_run_test(suite, uid_current, NULL);
165
abts_run_test(suite, username, NULL);
166
abts_run_test(suite, groupname, NULL);
167
abts_run_test(suite, fail_userinfo, NULL);