diff options
Diffstat (limited to 'rubbos/app/httpd-2.0.64/srclib/apr/user')
14 files changed, 934 insertions, 0 deletions
diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/netware/groupinfo.c b/rubbos/app/httpd-2.0.64/srclib/apr/user/netware/groupinfo.c new file mode 100644 index 00000000..a671121f --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/netware/groupinfo.c @@ -0,0 +1,60 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_strings.h" +#include "apr_portable.h" +#include "apr_user.h" +#include "apr_private.h" +#ifdef HAVE_GRP_H +#include <grp.h> +#endif +#if APR_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#if APR_HAVE_UNISTD_H +#include <unistd.h> /* for _POSIX_THREAD_SAFE_FUNCTIONS */ +#endif + +APR_DECLARE(apr_status_t) apr_gid_name_get(char **groupname, apr_gid_t groupid, + apr_pool_t *p) +{ + return APR_ENOTIMPL; +} + +APR_DECLARE(apr_status_t) apr_gid_get(apr_gid_t *groupid, + const char *groupname, apr_pool_t *p) +{ + return APR_ENOTIMPL; +} + +/* Deprecated */ +APR_DECLARE(apr_status_t) apr_get_groupname(char **groupname, + apr_gid_t groupid, apr_pool_t *p) +{ + return apr_gid_name_get(groupname, groupid, p); +} + +APR_DECLARE(apr_status_t) apr_group_name_get(char **groupname, + apr_gid_t groupid, apr_pool_t *p) +{ + return apr_gid_name_get(groupname, groupid, p); +} + +APR_DECLARE(apr_status_t) apr_get_groupid(apr_gid_t *groupid, + const char *groupname, apr_pool_t *p) +{ + return apr_gid_get(groupid, groupname, p); +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/netware/userinfo.c b/rubbos/app/httpd-2.0.64/srclib/apr/user/netware/userinfo.c new file mode 100644 index 00000000..94b42ae4 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/netware/userinfo.c @@ -0,0 +1,98 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_strings.h" +#include "apr_portable.h" +#include "apr_user.h" +#include "apr_private.h" +#ifdef HAVE_PWD_H +#include <pwd.h> +#endif +#if APR_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#if APR_HAVE_UNISTD_H +#include <unistd.h> /* for _POSIX_THREAD_SAFE_FUNCTIONS */ +#endif + +#define PWBUF_SIZE 512 + +static apr_status_t getpwnam_safe(const char *username, + struct passwd *pw, + char pwbuf[PWBUF_SIZE]) +{ + return APR_ENOTIMPL; +} + +APR_DECLARE(apr_status_t) apr_uid_homepath_get(char **dirname, + const char *username, + apr_pool_t *p) +{ + return APR_ENOTIMPL; +} + + + +APR_DECLARE(apr_status_t) apr_uid_current(apr_uid_t *uid, + apr_gid_t *gid, + apr_pool_t *p) +{ + return APR_ENOTIMPL; +} + + + + +APR_DECLARE(apr_status_t) apr_uid_get(apr_uid_t *uid, apr_gid_t *gid, + const char *username, apr_pool_t *p) +{ + return APR_ENOTIMPL; +} + +APR_DECLARE(apr_status_t) apr_uid_name_get(char **username, apr_uid_t userid, + apr_pool_t *p) +{ + return APR_ENOTIMPL; +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_get_home_directory(char **dirname, + const char *username, + apr_pool_t *p) +{ + return apr_uid_homepath_get(dirname, username, p); +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_get_userid(apr_uid_t *uid, apr_gid_t *gid, + const char *username, apr_pool_t *p) +{ + return apr_uid_get(uid, gid, username, p); +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_current_userid(apr_uid_t *uid, + apr_gid_t *gid, + apr_pool_t *p) +{ + return apr_uid_current(uid, gid, p); +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_get_username(char **username, apr_uid_t userid, apr_pool_t *p) +{ + return apr_uid_name_get(username, userid, p); +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/.libs/groupinfo.o b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/.libs/groupinfo.o Binary files differnew file mode 100644 index 00000000..fcf49822 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/.libs/groupinfo.o diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/.libs/userinfo.o b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/.libs/userinfo.o Binary files differnew file mode 100644 index 00000000..d8007d69 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/.libs/userinfo.o diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/Makefile b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/Makefile new file mode 100644 index 00000000..1a98e0ec --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/Makefile @@ -0,0 +1,13 @@ +srcdir = . + + +TARGETS = userinfo.lo groupinfo.lo + +# bring in rules.mk for standard functionality +include /bottlenecks/rubbos/app/httpd-2.0.64/srclib/apr/build/apr_rules.mk + +INCDIR=../../include +DEFOSDIR=$(INCDIR)/arch/unix +INCLUDES=-I$(INCDIR) -I$(DEFOSDIR) + +# DO NOT REMOVE diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/Makefile.in b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/Makefile.in new file mode 100644 index 00000000..100498f5 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/Makefile.in @@ -0,0 +1,13 @@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +TARGETS = userinfo.lo groupinfo.lo + +# bring in rules.mk for standard functionality +@INCLUDE_RULES@ + +INCDIR=../../include +DEFOSDIR=$(INCDIR)/arch/@DEFAULT_OSDIR@ +INCLUDES=-I$(INCDIR) -I$(DEFOSDIR) + +# DO NOT REMOVE diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/groupinfo.c b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/groupinfo.c new file mode 100644 index 00000000..8df3df85 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/groupinfo.c @@ -0,0 +1,108 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_strings.h" +#include "apr_portable.h" +#include "apr_user.h" +#include "apr_private.h" +#ifdef HAVE_GRP_H +#include <grp.h> +#endif +#if APR_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#if APR_HAVE_UNISTD_H +#include <unistd.h> /* for _POSIX_THREAD_SAFE_FUNCTIONS */ +#endif + +APR_DECLARE(apr_status_t) apr_gid_name_get(char **groupname, apr_gid_t groupid, + apr_pool_t *p) +{ + struct group *gr; +#ifndef BEOS + +#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) + struct group grp; + char grbuf[512]; + apr_status_t rv; + + /* See comment in getpwnam_safe on error handling. */ + rv = getgrgid_r(groupid, &grp, grbuf, sizeof(grbuf), &gr); + if (rv) { + return rv; + } + if (gr == NULL) { + return APR_ENOENT; + } +#else + errno = 0; + if ((gr = getgrgid(groupid)) == NULL) { + return errno ? errno : APR_ENOENT; + } +#endif + *groupname = apr_pstrdup(p, gr->gr_name); +#endif + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_gid_get(apr_gid_t *groupid, + const char *groupname, apr_pool_t *p) +{ + struct group *gr; +#ifndef BEOS + +#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRNAM_R) + struct group grp; + char grbuf[512]; + apr_status_t rv; + + /* See comment in getpwnam_safe on error handling. */ + rv = getgrnam_r(groupname, &grp, grbuf, sizeof(grbuf), &gr); + if (rv) { + return rv; + } + if (gr == NULL) { + return APR_ENOENT; + } +#else + errno = 0; + if ((gr = getgrnam(groupname)) == NULL) { + return errno ? errno : APR_ENOENT; + } +#endif + *groupid = gr->gr_gid; +#endif + return APR_SUCCESS; +} + +/* Deprecated */ +APR_DECLARE(apr_status_t) apr_get_groupname(char **groupname, + apr_gid_t groupid, apr_pool_t *p) +{ + return apr_gid_name_get(groupname, groupid, p); +} + +APR_DECLARE(apr_status_t) apr_group_name_get(char **groupname, + apr_gid_t groupid, apr_pool_t *p) +{ + return apr_gid_name_get(groupname, groupid, p); +} + +APR_DECLARE(apr_status_t) apr_get_groupid(apr_gid_t *groupid, + const char *groupname, apr_pool_t *p) +{ + return apr_gid_get(groupid, groupname, p); +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/groupinfo.lo b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/groupinfo.lo new file mode 100644 index 00000000..815b0412 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/groupinfo.lo @@ -0,0 +1,12 @@ +# groupinfo.lo - a libtool object file +# Generated by ltmain.sh - GNU libtool 1.5.26 (1.1220.2.493 2008/02/01 16:58:18) +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/groupinfo.o' + +# Name of the non-PIC object. +non_pic_object='groupinfo.o' + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/groupinfo.o b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/groupinfo.o Binary files differnew file mode 100644 index 00000000..5ae3c860 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/groupinfo.o diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/userinfo.c b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/userinfo.c new file mode 100644 index 00000000..f50f8053 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/userinfo.c @@ -0,0 +1,177 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_strings.h" +#include "apr_portable.h" +#include "apr_user.h" +#include "apr_private.h" +#ifdef HAVE_PWD_H +#include <pwd.h> +#endif +#if APR_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#if APR_HAVE_UNISTD_H +#include <unistd.h> /* for _POSIX_THREAD_SAFE_FUNCTIONS */ +#endif +#define APR_WANT_MEMFUNC +#include "apr_want.h" + +#define PWBUF_SIZE 512 + +static apr_status_t getpwnam_safe(const char *username, + struct passwd *pw, + char pwbuf[PWBUF_SIZE]) +{ + struct passwd *pwptr; +#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) + apr_status_t rv; + + /* POSIX defines getpwnam_r() et al to return the error number + * rather than set errno, and requires pwptr to be set to NULL if + * the entry is not found, imply that "not found" is not an error + * condition; some implementations do return 0 with pwptr set to + * NULL. */ + rv = getpwnam_r(username, pw, pwbuf, PWBUF_SIZE, &pwptr); + if (rv) { + return rv; + } + if (pwptr == NULL) { + return APR_ENOENT; + } +#else + /* Some platforms (e.g. FreeBSD 4.x) do not set errno on NULL "not + * found" return values for the non-threadsafe function either. */ + errno = 0; + if ((pwptr = getpwnam(username)) != NULL) { + memcpy(pw, pwptr, sizeof *pw); + } + else { + return errno ? errno : APR_ENOENT; + } +#endif + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_uid_homepath_get(char **dirname, + const char *username, + apr_pool_t *p) +{ + struct passwd pw; + char pwbuf[PWBUF_SIZE]; + apr_status_t rv; + + if ((rv = getpwnam_safe(username, &pw, pwbuf)) != APR_SUCCESS) + return rv; + +#ifdef OS2 + /* Need to manually add user name for OS/2 */ + *dirname = apr_pstrcat(p, pw.pw_dir, pw.pw_name, NULL); +#else + *dirname = apr_pstrdup(p, pw.pw_dir); +#endif + return APR_SUCCESS; +} + + + +APR_DECLARE(apr_status_t) apr_uid_current(apr_uid_t *uid, + apr_gid_t *gid, + apr_pool_t *p) +{ + *uid = getuid(); + *gid = getgid(); + + return APR_SUCCESS; +} + + + + +APR_DECLARE(apr_status_t) apr_uid_get(apr_uid_t *uid, apr_gid_t *gid, + const char *username, apr_pool_t *p) +{ + struct passwd pw; + char pwbuf[PWBUF_SIZE]; + apr_status_t rv; + + if ((rv = getpwnam_safe(username, &pw, pwbuf)) != APR_SUCCESS) + return rv; + + *uid = pw.pw_uid; + *gid = pw.pw_gid; + + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_uid_name_get(char **username, apr_uid_t userid, + apr_pool_t *p) +{ + struct passwd *pw; +#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWUID_R) + struct passwd pwd; + char pwbuf[PWBUF_SIZE]; + apr_status_t rv; + + rv = getpwuid_r(userid, &pwd, pwbuf, sizeof(pwbuf), &pw); + if (rv) { + return rv; + } + + if (pw == NULL) { + return APR_ENOENT; + } + +#else + errno = 0; + if ((pw = getpwuid(userid)) == NULL) { + return errno ? errno : APR_ENOENT; + } +#endif + *username = apr_pstrdup(p, pw->pw_name); + return APR_SUCCESS; +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_get_home_directory(char **dirname, + const char *username, + apr_pool_t *p) +{ + return apr_uid_homepath_get(dirname, username, p); +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_get_userid(apr_uid_t *uid, apr_gid_t *gid, + const char *username, apr_pool_t *p) +{ + return apr_uid_get(uid, gid, username, p); +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_current_userid(apr_uid_t *uid, + apr_gid_t *gid, + apr_pool_t *p) +{ + return apr_uid_current(uid, gid, p); +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_get_username(char **username, apr_uid_t userid, + apr_pool_t *p) +{ + return apr_uid_name_get(username, userid, p); +} + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/userinfo.lo b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/userinfo.lo new file mode 100644 index 00000000..9ac20075 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/userinfo.lo @@ -0,0 +1,12 @@ +# userinfo.lo - a libtool object file +# Generated by ltmain.sh - GNU libtool 1.5.26 (1.1220.2.493 2008/02/01 16:58:18) +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/userinfo.o' + +# Name of the non-PIC object. +non_pic_object='userinfo.o' + diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/userinfo.o b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/userinfo.o Binary files differnew file mode 100644 index 00000000..47290d17 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/unix/userinfo.o diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/win32/groupinfo.c b/rubbos/app/httpd-2.0.64/srclib/apr/user/win32/groupinfo.c new file mode 100644 index 00000000..784409fc --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/win32/groupinfo.c @@ -0,0 +1,124 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_strings.h" +#include "apr_portable.h" +#include "apr_user.h" +#include "apr_private.h" +#if APR_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +APR_DECLARE(apr_status_t) apr_gid_get(apr_gid_t *gid, + const char *groupname, apr_pool_t *p) +{ +#ifdef _WIN32_WCE + return APR_ENOTIMPL; +#else + SID_NAME_USE sidtype; + char anydomain[256]; + char *domain; + DWORD sidlen = 0; + DWORD domlen = sizeof(anydomain); + DWORD rv; + char *pos; + + if (pos = strchr(groupname, '/')) { + domain = apr_pstrndup(p, groupname, pos - groupname); + groupname = pos + 1; + } + else if (pos = strchr(groupname, '\\')) { + domain = apr_pstrndup(p, groupname, pos - groupname); + groupname = pos + 1; + } + else { + domain = NULL; + } + /* Get nothing on the first pass ... need to size the sid buffer + */ + rv = LookupAccountName(domain, groupname, domain, &sidlen, + anydomain, &domlen, &sidtype); + if (sidlen) { + /* Give it back on the second pass + */ + *gid = apr_palloc(p, sidlen); + domlen = sizeof(anydomain); + rv = LookupAccountName(domain, groupname, *gid, &sidlen, + anydomain, &domlen, &sidtype); + } + if (!sidlen || !rv) { + return apr_get_os_error(); + } + return APR_SUCCESS; +#endif +} + +APR_DECLARE(apr_status_t) apr_gid_name_get(char **groupname, apr_gid_t groupid, apr_pool_t *p) +{ +#ifdef _WIN32_WCE + *groupname = apr_pstrdup(p, "Administrators"); +#else + SID_NAME_USE type; + char name[MAX_PATH], domain[MAX_PATH]; + DWORD cbname = sizeof(name), cbdomain = sizeof(domain); + if (!groupid) + return APR_EINVAL; + if (!LookupAccountSid(NULL, groupid, name, &cbname, domain, &cbdomain, &type)) + return apr_get_os_error(); + if (type != SidTypeGroup && type != SidTypeWellKnownGroup + && type != SidTypeAlias) + return APR_EINVAL; + *groupname = apr_pstrdup(p, name); +#endif + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_gid_compare(apr_gid_t left, apr_gid_t right) +{ + if (!left || !right) + return APR_EINVAL; +#ifndef _WIN32_WCE + if (!IsValidSid(left) || !IsValidSid(right)) + return APR_EINVAL; + if (!EqualSid(left, right)) + return APR_EMISMATCH; +#endif + return APR_SUCCESS; +} + +/* Deprecated */ +APR_DECLARE(apr_status_t) apr_get_groupname(char **groupname, + apr_gid_t groupid, apr_pool_t *p) +{ + return apr_gid_name_get(groupname, groupid, p); +} + +APR_DECLARE(apr_status_t) apr_group_name_get(char **groupname, + apr_gid_t groupid, apr_pool_t *p) +{ + return apr_gid_name_get(groupname, groupid, p); +} + +APR_DECLARE(apr_status_t) apr_get_groupid(apr_gid_t *gid, + const char *groupname, apr_pool_t *p) +{ + return apr_gid_get(gid, groupname, p); +} + +APR_DECLARE(apr_status_t) apr_compare_groups(apr_gid_t left, apr_gid_t right) +{ + return apr_gid_compare(left, right); +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/user/win32/userinfo.c b/rubbos/app/httpd-2.0.64/srclib/apr/user/win32/userinfo.c new file mode 100644 index 00000000..61087f34 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/user/win32/userinfo.c @@ -0,0 +1,317 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "apr_private.h" +#include "apr_strings.h" +#include "apr_portable.h" +#include "apr_user.h" +#include "apr_arch_file_io.h" +#if APR_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#ifndef _WIN32_WCE +/* Internal sid binary to string translation, see MSKB Q131320. + * Several user related operations require our SID to access + * the registry, but in a string format. All error handling + * depends on IsValidSid(), which internally we better test long + * before we get here! + */ +void get_sid_string(char *buf, int blen, apr_uid_t id) +{ + PSID_IDENTIFIER_AUTHORITY psia; + DWORD nsa; + DWORD sa; + int slen; + + /* Determine authority values (these is a big-endian value, + * and NT records the value as hex if the value is > 2^32.) + */ + psia = GetSidIdentifierAuthority(id); + nsa = (DWORD)(psia->Value[5]) + ((DWORD)(psia->Value[4]) << 8) + + ((DWORD)(psia->Value[3]) << 16) + ((DWORD)(psia->Value[2]) << 24); + sa = (DWORD)(psia->Value[1]) + ((DWORD)(psia->Value[0]) << 8); + if (sa) { + slen = apr_snprintf(buf, blen, "S-%lu-0x%04x%08x", + SID_REVISION, sa, nsa); + } else { + slen = apr_snprintf(buf, blen, "S-%lu-%lu", + SID_REVISION, nsa); + } + + /* Now append all the subauthority strings. + */ + nsa = *GetSidSubAuthorityCount(id); + for (sa = 0; sa < nsa; ++sa) { + slen += apr_snprintf(buf + slen, blen - slen, "-%lu", + *GetSidSubAuthority(id, sa)); + } +} +#endif +/* Query the ProfileImagePath from the version-specific branch, where the + * regkey uses the user's name on 9x, and user's sid string on NT. + */ +APR_DECLARE(apr_status_t) apr_uid_homepath_get(char **dirname, + const char *username, + apr_pool_t *p) +{ +#ifdef _WIN32_WCE + *dirname = apr_pstrdup(p, "/My Documents"); + return APR_SUCCESS; +#else + apr_status_t rv; + char regkey[MAX_PATH * 2]; + char *fixch; + DWORD keylen; + DWORD type; + HKEY key; + + if (apr_os_level >= APR_WIN_NT) { + apr_uid_t uid; + apr_gid_t gid; + + if ((rv = apr_uid_get(&uid, &gid, username, p)) != APR_SUCCESS) + return rv; + + strcpy(regkey, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\" + "ProfileList\\"); + keylen = strlen(regkey); + get_sid_string(regkey + keylen, sizeof(regkey) - keylen, uid); + } + else { + strcpy(regkey, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" + "ProfileList\\"); + keylen = strlen(regkey); + apr_cpystrn(regkey + keylen, username, sizeof(regkey) - keylen); + + } + + if ((rv = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey, 0, + KEY_QUERY_VALUE, &key)) != ERROR_SUCCESS) + return APR_FROM_OS_ERROR(rv); + +#if APR_HAS_UNICODE_FS + IF_WIN_OS_IS_UNICODE + { + + keylen = sizeof(regkey); + rv = RegQueryValueExW(key, L"ProfileImagePath", NULL, &type, + (void*)regkey, &keylen); + RegCloseKey(key); + if (rv != ERROR_SUCCESS) + return APR_FROM_OS_ERROR(rv); + if (type == REG_SZ) { + char retdir[MAX_PATH]; + if ((rv = unicode_to_utf8_path(retdir, sizeof(retdir), + (apr_wchar_t*)regkey)) != APR_SUCCESS) + return rv; + *dirname = apr_pstrdup(p, retdir); + } + else if (type == REG_EXPAND_SZ) { + apr_wchar_t path[MAX_PATH]; + char retdir[MAX_PATH]; + ExpandEnvironmentStringsW((apr_wchar_t*)regkey, path, + sizeof(path) / 2); + if ((rv = unicode_to_utf8_path(retdir, sizeof(retdir), path)) + != APR_SUCCESS) + return rv; + *dirname = apr_pstrdup(p, retdir); + } + else + return APR_ENOENT; + } +#endif +#if APR_HAS_ANSI_FS + ELSE_WIN_OS_IS_ANSI + { + keylen = sizeof(regkey); + rv = RegQueryValueEx(key, "ProfileImagePath", NULL, &type, + (void*)regkey, &keylen); + RegCloseKey(key); + if (rv != ERROR_SUCCESS) + return APR_FROM_OS_ERROR(rv); + if (type == REG_SZ) { + *dirname = apr_pstrdup(p, regkey); + } + else if (type == REG_EXPAND_SZ) { + char path[MAX_PATH]; + ExpandEnvironmentStrings(regkey, path, sizeof(path)); + *dirname = apr_pstrdup(p, path); + } + else + return APR_ENOENT; + } +#endif /* APR_HAS_ANSI_FS */ + for (fixch = *dirname; *fixch; ++fixch) + if (*fixch == '\\') + *fixch = '/'; + return APR_SUCCESS; +#endif /* _WIN32_WCE */ +} + +APR_DECLARE(apr_status_t) apr_uid_current(apr_uid_t *uid, + apr_gid_t *gid, + apr_pool_t *p) +{ +#ifdef _WIN32_WCE + return APR_ENOTIMPL; +#else + HANDLE threadtok; + DWORD needed; + TOKEN_USER *usr; + TOKEN_PRIMARY_GROUP *grp; + + if(!OpenProcessToken(GetCurrentProcess(), STANDARD_RIGHTS_READ | READ_CONTROL | TOKEN_QUERY, &threadtok)) { + return apr_get_os_error(); + } + + *uid = NULL; + if (!GetTokenInformation(threadtok, TokenUser, NULL, 0, &needed) + && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) + && (usr = apr_palloc(p, needed)) + && GetTokenInformation(threadtok, TokenUser, usr, needed, &needed)) + *uid = usr->User.Sid; + else + return apr_get_os_error(); + + if (!GetTokenInformation(threadtok, TokenPrimaryGroup, NULL, 0, &needed) + && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) + && (grp = apr_palloc(p, needed)) + && GetTokenInformation(threadtok, TokenPrimaryGroup, grp, needed, &needed)) + *gid = grp->PrimaryGroup; + else + return apr_get_os_error(); + + return APR_SUCCESS; +#endif +} + +APR_DECLARE(apr_status_t) apr_uid_get(apr_uid_t *uid, apr_gid_t *gid, + const char *username, apr_pool_t *p) +{ +#ifdef _WIN32_WCE + return APR_ENOTIMPL; +#else + SID_NAME_USE sidtype; + char anydomain[256]; + char *domain; + DWORD sidlen = 0; + DWORD domlen = sizeof(anydomain); + DWORD rv; + char *pos; + + if (pos = strchr(username, '/')) { + domain = apr_pstrndup(p, username, pos - username); + username = pos + 1; + } + else if (pos = strchr(username, '\\')) { + domain = apr_pstrndup(p, username, pos - username); + username = pos + 1; + } + else { + domain = NULL; + } + /* Get nothing on the first pass ... need to size the sid buffer + */ + rv = LookupAccountName(domain, username, domain, &sidlen, + anydomain, &domlen, &sidtype); + if (sidlen) { + /* Give it back on the second pass + */ + *uid = apr_palloc(p, sidlen); + domlen = sizeof(anydomain); + rv = LookupAccountName(domain, username, *uid, &sidlen, + anydomain, &domlen, &sidtype); + } + if (!sidlen || !rv) { + return apr_get_os_error(); + } + /* There doesn't seem to be a simple way to retrieve the primary group sid + */ + *gid = NULL; + return APR_SUCCESS; +#endif +} + +APR_DECLARE(apr_status_t) apr_uid_name_get(char **username, apr_uid_t userid, + apr_pool_t *p) +{ +#ifdef _WIN32_WCE + *username = apr_pstrdup(p, "Administrator"); + return APR_SUCCESS; +#else + SID_NAME_USE type; + char name[MAX_PATH], domain[MAX_PATH]; + DWORD cbname = sizeof(name), cbdomain = sizeof(domain); + if (!userid) + return APR_EINVAL; + if (!LookupAccountSid(NULL, userid, name, &cbname, domain, &cbdomain, &type)) + return apr_get_os_error(); + if (type != SidTypeUser && type != SidTypeAlias && type != SidTypeWellKnownGroup) + return APR_EINVAL; + *username = apr_pstrdup(p, name); + return APR_SUCCESS; +#endif +} + +APR_DECLARE(apr_status_t) apr_uid_compare(apr_uid_t left, apr_uid_t right) +{ + if (!left || !right) + return APR_EINVAL; +#ifndef _WIN32_WCE + if (!IsValidSid(left) || !IsValidSid(right)) + return APR_EINVAL; + if (!EqualSid(left, right)) + return APR_EMISMATCH; +#endif + return APR_SUCCESS; +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_get_home_directory(char **dirname, + const char *username, + apr_pool_t *p) +{ + return apr_uid_homepath_get(dirname, username, p); +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_get_userid(apr_uid_t *uid, apr_gid_t *gid, + const char *username, apr_pool_t *p) +{ + return apr_uid_get(uid, gid, username, p); +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_current_userid(apr_uid_t *uid, + apr_gid_t *gid, + apr_pool_t *p) +{ + return apr_uid_current(uid, gid, p); +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_compare_users(apr_uid_t left, apr_uid_t right) +{ + return apr_uid_compare(left, right); +} + +/* deprecated */ +APR_DECLARE(apr_status_t) apr_get_username(char **username, apr_uid_t userid, + apr_pool_t *p) +{ + return apr_uid_name_get(username, userid, p); +} |