7 /* dictionary manager interface to environment variables
9 /* #include <dict_env.h>
11 /* DICT *dict_env_open(name, dummy, dict_flags)
16 /* dict_env_open() opens the environment variable array and
17 /* makes it accessible via the generic operations documented
18 /* in dict_open(3). The \fIname\fR and \fIdummy\fR arguments
21 /* dict(3) generic dictionary manager
22 /* safe_getenv(3) safe getenv() interface
26 /* The Secure Mailer license must be distributed with this software.
29 /* IBM T.J. Watson Research
31 /* Yorktown Heights, NY 10598, USA
37 #include <stdio.h> /* sprintf() prototype */
42 /* Utility library. */
47 #include "stringops.h"
51 /* dict_env_update - update environment array */
53 static void dict_env_update(DICT
*dict
, const char *name
, const char *value
)
57 * Optionally fold the key.
59 if (dict
->flags
& DICT_FLAG_FOLD_FIX
) {
60 if (dict
->fold_buf
== 0)
61 dict
->fold_buf
= vstring_alloc(10);
62 vstring_strcpy(dict
->fold_buf
, name
);
63 name
= lowercase(vstring_str(dict
->fold_buf
));
65 if (setenv(name
, value
, 1))
66 msg_fatal("setenv: %m");
69 /* dict_env_lookup - access environment array */
71 static const char *dict_env_lookup(DICT
*dict
, const char *name
)
76 * Optionally fold the key.
78 if (dict
->flags
& DICT_FLAG_FOLD_FIX
) {
79 if (dict
->fold_buf
== 0)
80 dict
->fold_buf
= vstring_alloc(10);
81 vstring_strcpy(dict
->fold_buf
, name
);
82 name
= lowercase(vstring_str(dict
->fold_buf
));
84 return (safe_getenv(name
));
87 /* dict_env_close - close environment dictionary */
89 static void dict_env_close(DICT
*dict
)
92 vstring_free(dict
->fold_buf
);
96 /* dict_env_open - make association with environment array */
98 DICT
*dict_env_open(const char *name
, int unused_flags
, int dict_flags
)
102 dict
= dict_alloc(DICT_TYPE_ENVIRON
, name
, sizeof(*dict
));
103 dict
->lookup
= dict_env_lookup
;
104 dict
->update
= dict_env_update
;
105 dict
->close
= dict_env_close
;
106 dict
->flags
= dict_flags
| DICT_FLAG_FIXED
;
107 if (dict_flags
& DICT_FLAG_FOLD_FIX
)
108 dict
->fold_buf
= vstring_alloc(10);
109 return (DICT_DEBUG (dict
));