aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2003-01-10 22:42:05 +0000
committerKen Raeburn <raeburn@mit.edu>2003-01-10 22:42:05 +0000
commit1f55e6f6211626f3c3dd099dc2a33d9eb4da146b (patch)
tree11bda807ca826fff3b5f3c58a55c3fbb72f888d7 /src/util
parent42ea0da3fdab0a82051b6049387709952cc1a7af (diff)
downloadkrb5-1f55e6f6211626f3c3dd099dc2a33d9eb4da146b.zip
krb5-1f55e6f6211626f3c3dd099dc2a33d9eb4da146b.tar.gz
krb5-1f55e6f6211626f3c3dd099dc2a33d9eb4da146b.tar.bz2
Use passwd entry for ~ expansion if $HOME isn't set.
Also fix a minor logic bug in checking file access. ticket: 1237 status: open git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15110 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util')
-rw-r--r--src/util/profile/ChangeLog8
-rw-r--r--src/util/profile/configure.in2
-rw-r--r--src/util/profile/prof_file.c53
3 files changed, 43 insertions, 20 deletions
diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog
index 7a45fa9..ad59217 100644
--- a/src/util/profile/ChangeLog
+++ b/src/util/profile/ChangeLog
@@ -1,5 +1,13 @@
2003-01-10 Ken Raeburn <raeburn@mit.edu>
+ * configure.in: Check for pwd.h.
+ * prof_file.c: Include pwd.h if available.
+ (profile_open_file) [HAVE_PWD_H]: If $HOME isn't set, look up the
+ home directory in the passwd file. Expand the filename before
+ checking against the cache.
+ (profile_open_file) [SHARE_TREE_DATA]: Fix the sense of the test
+ for read access.
+
* configure.in: Use V5_AC_OUTPUT_MAKEFILE instead of
K5_GEN_MAKEFILE and K5_AC_OUTPUT.
diff --git a/src/util/profile/configure.in b/src/util/profile/configure.in
index 8a275d3..142d23b 100644
--- a/src/util/profile/configure.in
+++ b/src/util/profile/configure.in
@@ -4,7 +4,7 @@ AC_C_CONST
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
-AC_CHECK_HEADERS(unistd.h stdlib.h)
+AC_CHECK_HEADERS(unistd.h stdlib.h pwd.h)
AC_CHECK_FUNCS(stat access strdup)
AC_PROG_AWK
KRB5_BUILD_LIBOBJS
diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c
index 22470cc..a71c44f 100644
--- a/src/util/profile/prof_file.c
+++ b/src/util/profile/prof_file.c
@@ -17,6 +17,9 @@
#include <sys/stat.h>
#include <errno.h>
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
#if defined(_WIN32)
#include <io.h>
@@ -91,6 +94,7 @@ errcode_t profile_open_file(filespec, ret_prof)
char *home_env = 0;
unsigned int len;
prf_data_t data;
+ char *expanded_filename;
prf = malloc(sizeof(struct _prf_file_t));
if (!prf)
@@ -98,18 +102,45 @@ errcode_t profile_open_file(filespec, ret_prof)
memset(prf, 0, sizeof(struct _prf_file_t));
prf->magic = PROF_MAGIC_FILE;
+ len = strlen(filespec)+1;
+ if (filespec[0] == '~' && filespec[1] == '/') {
+ home_env = getenv("HOME");
+#ifdef HAVE_PWD_H
+ if (home_env == NULL) {
+ uid_t uid;
+ struct passwd *pw;
+
+ uid = getuid();
+ pw = getpwuid(uid);
+ if (pw != NULL && pw->pw_dir[0] != 0)
+ home_env = pw->pw_dir;
+ }
+#endif
+ if (home_env)
+ len += strlen(home_env);
+ }
+ expanded_filename = malloc(len);
+ if (expanded_filename == 0)
+ return errno;
+ if (home_env) {
+ strcpy(expanded_filename, home_env);
+ strcat(expanded_filename, filespec+1);
+ } else
+ memcpy(expanded_filename, filespec, len);
+
#ifdef SHARE_TREE_DATA
(void) prof_mutex_lock(&g_shared_trees_mutex);
for (data = g_shared_trees; data; data = data->next) {
- if (!strcmp(data->filespec, filespec)
+ if (!strcmp(data->filespec, expanded_filename)
/* Check that current uid has read access. */
- && r_access(data->filespec) == 0)
+ && r_access(data->filespec))
break;
}
if (data) {
retval = profile_update_file_data(data);
data->refcount++;
(void) prof_mutex_unlock(&g_shared_trees_mutex);
+ free(expanded_filename);
prf->data = data;
*ret_prof = prf;
return retval;
@@ -129,23 +160,7 @@ errcode_t profile_open_file(filespec, ret_prof)
data->magic = PROF_MAGIC_FILE_DATA;
data->refcount = 1;
data->comment = 0;
-
- len = strlen(filespec)+1;
- if (filespec[0] == '~' && filespec[1] == '/') {
- home_env = getenv("HOME");
- if (home_env)
- len += strlen(home_env);
- }
- data->filespec = malloc(len);
- if (!data->filespec) {
- free(prf);
- return ENOMEM;
- }
- if (home_env) {
- strcpy(data->filespec, home_env);
- strcat(data->filespec, filespec+1);
- } else
- strcpy(data->filespec, filespec);
+ data->filespec = expanded_filename;
retval = profile_update_file(prf);
if (retval) {