~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/test/testuser.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
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
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
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.
 
15
 */
 
16
 
 
17
#include "testutil.h"
 
18
#include "apr_errno.h"
 
19
#include "apr_general.h"
 
20
#include "apr_user.h"
 
21
 
 
22
#if APR_HAS_USER
 
23
static void uid_current(abts_case *tc, void *data)
 
24
{
 
25
    apr_uid_t uid;
 
26
    apr_gid_t gid;
 
27
 
 
28
    APR_ASSERT_SUCCESS(tc, "apr_uid_current failed",
 
29
                       apr_uid_current(&uid, &gid, p));
 
30
}
 
31
 
 
32
static void username(abts_case *tc, void *data)
 
33
{
 
34
    apr_uid_t uid;
 
35
    apr_gid_t gid;
 
36
    apr_uid_t retreived_uid;
 
37
    apr_gid_t retreived_gid;
 
38
    char *uname = NULL;
 
39
 
 
40
    APR_ASSERT_SUCCESS(tc, "apr_uid_current failed",
 
41
                       apr_uid_current(&uid, &gid, p));
 
42
   
 
43
    APR_ASSERT_SUCCESS(tc, "apr_uid_name_get failed",
 
44
                       apr_uid_name_get(&uname, uid, p));
 
45
    ABTS_PTR_NOTNULL(tc, uname);
 
46
 
 
47
    APR_ASSERT_SUCCESS(tc, "apr_uid_get failed",
 
48
                       apr_uid_get(&retreived_uid, &retreived_gid, uname, p));
 
49
 
 
50
    APR_ASSERT_SUCCESS(tc, "apr_uid_compare failed",
 
51
                       apr_uid_compare(uid, retreived_uid));
 
52
#ifdef WIN32
 
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.
 
59
         */
 
60
        if (!gid) {
 
61
            ABTS_NOT_IMPL(tc, "Groups from apr_uid_current");
 
62
        }
 
63
        else {
 
64
            ABTS_NOT_IMPL(tc, "Groups from apr_uid_get");
 
65
        }        
 
66
    }
 
67
    else {
 
68
#endif
 
69
        APR_ASSERT_SUCCESS(tc, "apr_gid_compare failed",
 
70
                           apr_gid_compare(gid, retreived_gid));
 
71
#ifdef WIN32
 
72
    }
 
73
#endif
 
74
}
 
75
 
 
76
static void groupname(abts_case *tc, void *data)
 
77
{
 
78
    apr_uid_t uid;
 
79
    apr_gid_t gid;
 
80
    apr_gid_t retreived_gid;
 
81
    char *gname = NULL;
 
82
 
 
83
    APR_ASSERT_SUCCESS(tc, "apr_uid_current failed",
 
84
                       apr_uid_current(&uid, &gid, p));
 
85
 
 
86
    APR_ASSERT_SUCCESS(tc, "apr_gid_name_get failed",
 
87
                       apr_gid_name_get(&gname, gid, p));
 
88
    ABTS_PTR_NOTNULL(tc, gname);
 
89
 
 
90
    APR_ASSERT_SUCCESS(tc, "apr_gid_get failed",
 
91
                       apr_gid_get(&retreived_gid, gname, p));
 
92
 
 
93
    APR_ASSERT_SUCCESS(tc, "apr_gid_compare failed",
 
94
                       apr_gid_compare(gid, retreived_gid));
 
95
}
 
96
 
 
97
#ifndef WIN32
 
98
 
 
99
static void fail_userinfo(abts_case *tc, void *data)
 
100
{
 
101
    apr_uid_t uid;
 
102
    apr_gid_t gid;
 
103
    apr_status_t rv;
 
104
    char *tmp;
 
105
 
 
106
    errno = 0;
 
107
    gid = uid = 9999999;
 
108
    tmp = NULL;
 
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);
 
113
 
 
114
    errno = 0;
 
115
    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);
 
120
 
 
121
    gid = 424242;
 
122
    errno = 0;
 
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);
 
127
 
 
128
    gid = uid = 424242;
 
129
    errno = 0;
 
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);
 
134
 
 
135
    errno = 0;
 
136
    tmp = NULL;
 
137
    rv = apr_uid_homepath_get(&tmp, "I_AM_NOT_A_USER", p);
 
138
    ABTS_ASSERT(tc, "apr_uid_homepath_get should fail or "
 
139
                "set a path name",
 
140
                rv != APR_SUCCESS || tmp != NULL);
 
141
}
 
142
 
 
143
#else
 
144
static void fail_userinfo(abts_case *tc, void *data)
 
145
{
 
146
    ABTS_NOT_IMPL(tc, "Users are not opaque integers on this platform");
 
147
}
 
148
#endif
 
149
 
 
150
#else
 
151
static void users_not_impl(abts_case *tc, void *data)
 
152
{
 
153
    ABTS_NOT_IMPL(tc, "Users not implemented on this platform");
 
154
}
 
155
#endif
 
156
 
 
157
abts_suite *testuser(abts_suite *suite)
 
158
{
 
159
    suite = ADD_SUITE(suite)
 
160
 
 
161
#if !APR_HAS_USER
 
162
    abts_run_test(suite, users_not_impl, NULL);
 
163
#else
 
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);
 
168
#endif
 
169
 
 
170
    return suite;
 
171
}