prof_tree.c (profile_node_iterator): Make sure the pointer to the
authorTheodore Tso <tytso@mit.edu>
Sat, 2 Jan 1999 06:38:49 +0000 (06:38 +0000)
committerTheodore Tso <tytso@mit.edu>
Sat, 2 Jan 1999 06:38:49 +0000 (06:38 +0000)
iterator function is non-NULL before checking the magic value.

prof_file.c (profile_open_file): Add ability to parse filenames that
begin with "~/" and substitute it with "$HOME/".

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11096 dc483132-0cff-0310-8789-dd5450dbe970

src/util/profile/ChangeLog
src/util/profile/prof_file.c
src/util/profile/prof_tree.c

index 554357a584d45b370033d05004470a957b10ac9e..035911559dddc8e88e51f302e0191627189dfa51 100644 (file)
@@ -1,3 +1,14 @@
+1998-12-31  Theodore Ts'o  <tytso@rsts-11.mit.edu>
+
+       * prof_tree.c (profile_node_iterator): Make sure the pointer to
+               the iterator function is non-NULL before checking the
+               magic value.
+
+1998-12-15  Theodore Ts'o  <tytso@rsts-11.mit.edu>
+
+       * prof_file.c (profile_open_file): Add ability to parse filenames
+               that begin with "~/" and substitute it with "$HOME/".
+
 1998-12-04  Theodore Ts'o  <tytso@rsts-11.mit.edu>
 
        * prof_get.c: Add new public profile_iterator functions for
index 070cbeffc0c80174a378f3952a917ebee05d35e5..fde68748266af05d1dd3449f0151f7ce92085ed7 100644 (file)
@@ -29,17 +29,29 @@ errcode_t profile_open_file(filename, ret_prof)
 {
        prf_file_t      prf;
        errcode_t       retval;
+       char            *home_env = 0;
+       int             len;
 
        prf = malloc(sizeof(struct _prf_file_t));
        if (!prf)
                return ENOMEM;
        memset(prf, 0, sizeof(struct _prf_file_t));
-       prf->filename = malloc(strlen(filename)+1);
+       len = strlen(filename)+1;
+       if (filename[0] == '~' && filename[1] == '/') {
+               home_env = getenv("HOME");
+               if (home_env)
+                       len += strlen(home_env);
+       }
+       prf->filename = malloc(len);
        if (!prf->filename) {
                free(prf);
                return ENOMEM;
        }
-       strcpy(prf->filename, filename);
+       if (home_env) {
+               strcpy(prf->filename, home_env);
+               strcat(prf->filename, filename+1);
+       } else
+               strcpy(prf->filename, filename);
        prf->magic = PROF_MAGIC_FILE;
 
        retval = profile_update_file(prf);
index ddfa08f4403e0218eae189c52a82f57542222b61..e8257c826fe28be12dc9483c0afbed8d956737d5 100644 (file)
@@ -441,7 +441,7 @@ errcode_t profile_node_iterator(iter_p, ret_node, ret_name, ret_value)
        errcode_t                       retval;
        int                             skip_num = 0;
 
-       if (iter->magic != PROF_MAGIC_ITERATOR)
+       if (!iter || iter->magic != PROF_MAGIC_ITERATOR)
                return PROF_MAGIC_ITERATOR;
        /*
         * If the file has changed, then the node pointer is invalid,