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

« back to all changes in this revision

Viewing changes to srclib/apr/user/unix/groupinfo.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 "apr_strings.h"
 
18
#include "apr_portable.h"
 
19
#include "apr_user.h"
 
20
#include "apr_private.h"
 
21
#ifdef HAVE_GRP_H
 
22
#include <grp.h>
 
23
#endif
 
24
#if APR_HAVE_SYS_TYPES_H
 
25
#include <sys/types.h>
 
26
#endif
 
27
#if APR_HAVE_UNISTD_H
 
28
#include <unistd.h> /* for _POSIX_THREAD_SAFE_FUNCTIONS */
 
29
#endif
 
30
 
 
31
APR_DECLARE(apr_status_t) apr_gid_name_get(char **groupname, apr_gid_t groupid,
 
32
                                           apr_pool_t *p)
 
33
{
 
34
    struct group *gr;
 
35
 
 
36
#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
 
37
    struct group grp;
 
38
    char grbuf[512];
 
39
    apr_status_t rv;
 
40
 
 
41
    /* See comment in getpwnam_safe on error handling. */
 
42
    rv = getgrgid_r(groupid, &grp, grbuf, sizeof(grbuf), &gr);
 
43
    if (rv) {
 
44
        return rv;
 
45
    }
 
46
    if (gr == NULL) {
 
47
        return APR_ENOENT;
 
48
    }
 
49
#else
 
50
    errno = 0;
 
51
    if ((gr = getgrgid(groupid)) == NULL) {
 
52
        return errno ? errno : APR_ENOENT;
 
53
    }
 
54
#endif
 
55
    *groupname = apr_pstrdup(p, gr->gr_name);
 
56
    return APR_SUCCESS;
 
57
}
 
58
  
 
59
APR_DECLARE(apr_status_t) apr_gid_get(apr_gid_t *groupid, 
 
60
                                      const char *groupname, apr_pool_t *p)
 
61
{
 
62
    struct group *gr;
 
63
 
 
64
#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRNAM_R)
 
65
    struct group grp;
 
66
    char grbuf[512];
 
67
    apr_status_t rv;
 
68
 
 
69
    /* See comment in getpwnam_safe on error handling. */
 
70
    rv = getgrnam_r(groupname, &grp, grbuf, sizeof(grbuf), &gr);
 
71
    if (rv) {
 
72
        return rv;
 
73
    }
 
74
    if (gr == NULL) {
 
75
        return APR_ENOENT;
 
76
    }
 
77
#else
 
78
    errno = 0;
 
79
    if ((gr = getgrnam(groupname)) == NULL) {
 
80
        return errno ? errno : APR_ENOENT;
 
81
    }
 
82
#endif
 
83
    *groupid = gr->gr_gid;
 
84
    return APR_SUCCESS;
 
85
}