/[pdpsoft]/trunk/grid-mw-security/cgul/environ/environ.h
ViewVC logotype

Contents of /trunk/grid-mw-security/cgul/environ/environ.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1449 - (show annotations) (download) (as text)
Tue Feb 2 02:35:46 2010 UTC (11 years, 11 months ago) by msalle
File MIME type: text/x-csrc
File size: 5044 byte(s)
- added new function setenv_dst() adding a name, value pair to the dst
  environment, similar to add_namevalue()

- check explicitly that whitelists aren't NULL, which lead to a segfault...


1 /**
2 * Copyright (c) Members of the EGEE Collaboration. 2010.
3 * See http://www.eu-egee.org/partners/ for details on the copyright
4 * holders.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Authors: Oscar Koeroo, Mischa Sall\'e, Aram Verstegen
19 * NIKHEF Amsterdam, the Netherlands
20 * <grid-mw-security@nikhef.nl>
21 */
22
23 #include <unistd.h>
24
25 extern char **environ;
26
27 #ifndef MAXENVVARNAMELEN
28 #define MAXENVVARNAMELEN 16384
29 #endif
30
31 /**
32 * returns number of entries in NULL terminated string array, such as argv and
33 * environ(7). In case list is NULL it also returns 0.
34 */
35 int strarrlen(const char **list);
36
37 /**
38 * Returns the length of the name part of the var=value pair or -1 when there is
39 * no '=' sign.
40 */
41 int getvarnamelen(const char *varname);
42
43 /**
44 * Finds name for given var=value pair in namevalue. varname is a buffer
45 * which will contain the result and has space for maxvarnamelen chars.
46 * Returns integer, negative on error, -1 on no '=' sign, -2 name too long;
47 * 0 success
48 */
49 int getvarname(char *varname,const int maxvarnamelen, const char *namevalue);
50
51 /**
52 * Finds index in **src matching variable name, in case of no match (including
53 * env==NULL) returns -1
54 */
55 int getvarindex(const char **src, const char *varname);
56
57 /**
58 * Finds the value of varname in src list. Returns NULL when no match, incl.
59 * NULL valued src or varname.
60 */
61 char *getenv_src(const char **src, char *varname);
62
63 /**
64 * As unsetenv(3) but using var=value pair, specified in namevalue. The maximum
65 * var length is MAXVARNAMELEN. See also putenv(3).
66 * Returns integer, 0 on success, negative on error.
67 */
68 int unsetenvpair(const char *namevalue);
69
70 /**
71 * Clears the entire environment
72 * Returns integer, -1 on error, 0 on success
73 */
74 int clear_env(void);
75
76 /*
77 * Clears the environment of all variables starting with pattern, case
78 * INsensitive.
79 * Returns number of cleaned entries, -1 on error.
80 */
81 int clear_env_pattern(const char *pattern);
82
83 /**
84 * Returns a duplicate of src. In case dst!=NULL it will be used and should be
85 * big enough. Otherwise space is malloced.
86 */
87 char **copy_env(char **dst,const char **src);
88
89 /**
90 * Same as copy_env() but first unsets all environment variables starting with
91 * MALLOC, case INsensitive.
92 */
93 char **safe_copy_env(char **dst,const char **src);
94
95 /**
96 * Creates a list of the var=value pairs from src which have varname in list.
97 * If it fails NULL is returned. This can also be done using add_src_list()
98 * using dst==NULL, but this is more efficiently coded. All new entries are
99 * strdup-ed from those in src.
100 */
101 char **copy_src_list(const char **src,const char **list);
102
103 /**
104 * Adds to dst the var=value pairs from src which have varname in list.
105 * All entries will be strdup-ed from those in src.
106 * If dst is NULL, it will create a new one. dst will be realloc-ed. If it fails
107 * NULL is returned, when failure occurs later on, dst will be returned, being
108 * equal to the original src but at a different memory location.
109 * See also copy_src_list() which is more efficient when dst is NULL !
110 */
111 char **add_src_list(char **dst,const char **src,const char **list);
112
113 /**
114 * adds var=value pair to dst. If the variable already exists, it's entry is
115 * replaced. Otherwise dst is realloc-ed and a new entry is added, the resulting
116 * array is returned. In case of error NULL is returned and dst is unchanged.
117 * namevalue is strdup-ed into dst and hence can be freed by the caller (unlike
118 * putenv(3p) )
119 */
120 char **add_namevalue(char **dst,const char *namevalue);
121
122 /**
123 * adds name=value pair to dst, as in setenv() with a 'external environment' .
124 * If the variable already exists, it's entry is replaced. Otherwise dst is
125 * realloc-ed and a new entry is added, the resulting array is returned. In case
126 * of error NULL is returned and dst is unchanged. name and value can be freed
127 * by the caller (unlike putenv(3p) )
128 */
129 char **setenv_dst(char **dst,const char *name, const char *value);
130
131 /**
132 * Adds to the current environment the var=value pairs from src which have
133 * varname in list. Returns number of entries added or -1 on error.
134 * NOTE: putenv doesn't reserve new memory so src should NOT be
135 * free()d.
136 */
137 int putenv_src_list(char **src,const char **list);
138
139 /**
140 * Adds to the current environment the var=value pairs from src which start with
141 * pattern. Returns number of entries added or -1 on error.
142 * NOTE: putenv doesn't reserve new memory so src should NOT be
143 * free()d.
144 */
145 int putenv_src_pattern(char **src,const char *pattern);
146

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28