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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1452 - (hide annotations) (download) (as text)
Tue Feb 2 19:09:23 2010 UTC (12 years, 3 months ago) by msalle
File MIME type: text/x-csrc
File size: 5310 byte(s)
- introducing env_t (char **): now use &dst for creation/updating of
  environments instead of return value of functions.
  This makes it easier to have a few additions in a row etc.

- make sure when input whitelist and/or src is null everything works as
  expected: new environment should be created and initialized to empty, old
  environment should be left unchanged.

- make sure environ.h is effectively included once using a #ifndef

1 msalle 1446 /**
2 msalle 1447 * Copyright (c) Members of the EGEE Collaboration. 2010.
3 msalle 1446 * 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 msalle 1452 #ifndef _ENVIRON_H_
24     #define _ENVIRON_H_
25    
26 msalle 1420 #include <unistd.h>
27     extern char **environ;
28    
29 msalle 1452 /* Define environment list type: note that we CANNOT initialize it as
30     * env_t myenv={"..","..",NULL} etc. */
31     typedef char **env_t;
32    
33 msalle 1420 #ifndef MAXENVVARNAMELEN
34     #define MAXENVVARNAMELEN 16384
35     #endif
36    
37     /**
38     * returns number of entries in NULL terminated string array, such as argv and
39 msalle 1429 * environ(7). In case list is NULL it also returns 0.
40 msalle 1420 */
41     int strarrlen(const char **list);
42    
43     /**
44 msalle 1436 * Returns the length of the name part of the var=value pair or -1 when there is
45     * no '=' sign.
46     */
47     int getvarnamelen(const char *varname);
48    
49     /**
50 msalle 1420 * Finds name for given var=value pair in namevalue. varname is a buffer
51     * which will contain the result and has space for maxvarnamelen chars.
52     * Returns integer, negative on error, -1 on no '=' sign, -2 name too long;
53     * 0 success
54     */
55     int getvarname(char *varname,const int maxvarnamelen, const char *namevalue);
56    
57     /**
58 msalle 1436 * Finds index in **src matching variable name, in case of no match (including
59     * env==NULL) returns -1
60     */
61 msalle 1452 int getvarindex(const env_t src, const char *varname);
62 msalle 1436
63     /**
64 msalle 1441 * Finds the value of varname in src list. Returns NULL when no match, incl.
65     * NULL valued src or varname.
66     */
67 msalle 1452 char *getenv_src(const env_t src, char *varname);
68 msalle 1441
69     /**
70 msalle 1420 * As unsetenv(3) but using var=value pair, specified in namevalue. The maximum
71     * var length is MAXVARNAMELEN. See also putenv(3).
72     * Returns integer, 0 on success, negative on error.
73     */
74     int unsetenvpair(const char *namevalue);
75    
76     /**
77     * Clears the entire environment
78     * Returns integer, -1 on error, 0 on success
79     */
80     int clear_env(void);
81    
82     /*
83     * Clears the environment of all variables starting with pattern, case
84     * INsensitive.
85     * Returns number of cleaned entries, -1 on error.
86     */
87     int clear_env_pattern(const char *pattern);
88    
89     /**
90 msalle 1452 * Creates a duplicate of src. In case *dst!=NULL it will be used and should be
91     * big enough. Otherwise space is malloc-ed. dst is only updated upon success.
92     * Returns -1 upon error, 0 on success.
93 msalle 1420 */
94 msalle 1452 int copy_env(env_t *dst,const env_t src);
95 msalle 1420
96     /**
97     * Same as copy_env() but first unsets all environment variables starting with
98 msalle 1452 * MALLOC, case INsensitive. dst is again only updated upon success.
99     * Returns -1 upon error, 0 on success.
100 msalle 1420 */
101 msalle 1452 int safe_copy_env(env_t *dst,const env_t src);
102 msalle 1420
103     /**
104 msalle 1436 * Creates a list of the var=value pairs from src which have varname in list.
105 msalle 1449 * If it fails NULL is returned. This can also be done using add_src_list()
106     * using dst==NULL, but this is more efficiently coded. All new entries are
107     * strdup-ed from those in src.
108 msalle 1436 */
109 msalle 1452 env_t copy_src_list(const env_t src,const char **list);
110 msalle 1436
111     /**
112 msalle 1420 * Adds to dst the var=value pairs from src which have varname in list.
113 msalle 1439 * All entries will be strdup-ed from those in src.
114 msalle 1452 * If *dst is NULL, it will be malloc-ed, otherwise it will be realloc-ed.
115     * Upon success returns 0. On error -1 is returned, and dst stays unchanged.
116 msalle 1436 * See also copy_src_list() which is more efficient when dst is NULL !
117 msalle 1420 */
118 msalle 1452 int add_src_list(env_t *dst,const env_t src,const char **list);
119 msalle 1420
120     /**
121 msalle 1436 * adds var=value pair to dst. If the variable already exists, it's entry is
122 msalle 1452 * replaced. Otherwise *dst is realloc-ed and a new entry is added, the
123     * resulting array is returned.
124     * Upon success returns 0. In case of error -1 is returned and dst remains
125     * unchanged. namevalue is strdup-ed into dst and hence can be freed by the
126     * caller (unlike putenv(3p) )
127 msalle 1436 */
128 msalle 1452 int add_namevalue(env_t *dst,const char *namevalue);
129 msalle 1436
130     /**
131 msalle 1449 * adds name=value pair to dst, as in setenv() with a 'external environment' .
132 msalle 1452 * If the variable already exists, it's entry is replaced. Otherwise *dst is
133     * realloc-ed and a new entry is added.
134     * Upon success returns 0. In case of error -1 is returned and dst remains
135     * unchanged. name and value can be freed by the caller (unlike putenv(3p) )
136 msalle 1449 */
137 msalle 1452 int setenv_dst(env_t *dst,const char *name, const char *value);
138 msalle 1449
139     /**
140 msalle 1420 * Adds to the current environment the var=value pairs from src which have
141     * varname in list. 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 msalle 1452 int putenv_src_list(env_t src,const char **list);
146 msalle 1420
147     /**
148     * Adds to the current environment the var=value pairs from src which start with
149     * pattern. Returns number of entries added or -1 on error.
150     * NOTE: putenv doesn't reserve new memory so src should NOT be
151     * free()d.
152     */
153 msalle 1452 int putenv_src_pattern(env_t src,const char *pattern);
154 msalle 1420
155 msalle 1452 #endif

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