[BACK]Return to env.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / doas

Diff for /src/usr.bin/doas/env.c between version 1.6 and 1.7

version 1.6, 2017/04/06 21:12:06 version 1.7, 2019/06/16 18:16:34
Line 24 
Line 24 
 #include <err.h>  #include <err.h>
 #include <unistd.h>  #include <unistd.h>
 #include <errno.h>  #include <errno.h>
   #include <pwd.h>
   
 #include "doas.h"  #include "doas.h"
   
Line 38 
Line 39 
         u_int count;          u_int count;
 };  };
   
   static void fillenv(struct env *env, const char **envlist);
   
 static int  static int
 envcmp(struct envnode *a, struct envnode *b)  envcmp(struct envnode *a, struct envnode *b)
 {  {
Line 68 
Line 71 
         free(node);          free(node);
 }  }
   
   static void
   addnode(struct env *env, const char *key, const char *value)
   {
           struct envnode *node;
   
           node = createnode(key, value);
           RB_INSERT(envtree, &env->root, node);
           env->count++;
   }
   
 static struct env *  static struct env *
 createenv(const struct rule *rule)  createenv(const struct rule *rule, const struct passwd *mypw,
       const struct passwd *targpw)
 {  {
         struct env *env;          struct env *env;
         u_int i;          u_int i;
Line 80 
Line 94 
         RB_INIT(&env->root);          RB_INIT(&env->root);
         env->count = 0;          env->count = 0;
   
           addnode(env, "DOAS_USER", mypw->pw_name);
   
         if (rule->options & KEEPENV) {          if (rule->options & KEEPENV) {
                 extern const char **environ;                  extern const char **environ;
   
Line 108 
Line 124 
                                 env->count++;                                  env->count++;
                         }                          }
                 }                  }
           } else {
                   static const char *copyset[] = {
                           "DISPLAY", "TERM",
                           NULL
                   };
   
                   addnode(env, "HOME", targpw->pw_dir);
                   addnode(env, "LOGNAME", targpw->pw_name);
                   addnode(env, "PATH", getenv("PATH"));
                   addnode(env, "SHELL", targpw->pw_shell);
                   addnode(env, "USER", targpw->pw_name);
   
                   fillenv(env, copyset);
         }          }
   
         return env;          return env;
Line 186 
Line 215 
 }  }
   
 char **  char **
 prepenv(const struct rule *rule)  prepenv(const struct rule *rule, const struct passwd *mypw,
       const struct passwd *targpw)
 {  {
         static const char *safeset[] = {  
                 "DISPLAY", "HOME", "LOGNAME", "MAIL",  
                 "PATH", "TERM", "USER", "USERNAME",  
                 NULL  
         };  
         struct env *env;          struct env *env;
   
         env = createenv(rule);          env = createenv(rule, mypw, targpw);
   
         /* if we started with blank, fill some defaults then apply rules */  
         if (!(rule->options & KEEPENV))  
                 fillenv(env, safeset);  
         if (rule->envlist)          if (rule->envlist)
                 fillenv(env, rule->envlist);                  fillenv(env, rule->envlist);
   

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7