MCPcopy Create free account
hub / github.com/F-Stack/f-stack / setclassenvironment

Function setclassenvironment

tools/libutil/login_class.c:197–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195
196
197void
198setclassenvironment(login_cap_t *lc, const struct passwd * pwd, int paths)
199{
200 struct login_vars *vars = paths ? pathvars : envars;
201 int hlen = pwd ? strlen(pwd->pw_dir) : 0;
202 int nlen = pwd ? strlen(pwd->pw_name) : 0;
203 char pch = 0;
204
205 if (hlen && pwd->pw_dir[hlen-1] != '/')
206 ++pch;
207
208 while (vars->tag != NULL) {
209 const char * var = paths ? login_getpath(lc, vars->tag, NULL)
210 : login_getcapstr(lc, vars->tag, NULL, NULL);
211
212 char * np = substvar(var, pwd, hlen, pch, nlen);
213
214 if (np != NULL) {
215 setenv(vars->var, np, vars->overwrite);
216 free(np);
217 } else if (vars->def != NULL) {
218 setenv(vars->var, vars->def, 0);
219 }
220 ++vars;
221 }
222
223 /*
224 * If we're not processing paths, then see if there is a setenv list by
225 * which the admin and/or user may set an arbitrary set of env vars.
226 */
227 if (!paths) {
228 const char **set_env = login_getcaplist(lc, "setenv", ",");
229
230 if (set_env != NULL) {
231 while (*set_env != NULL) {
232 char *p = strchr(*set_env, '=');
233
234 if (p != NULL) { /* Discard invalid entries */
235 char *np;
236
237 *p++ = '\0';
238 if ((np = substvar(p, pwd, hlen, pch, nlen)) != NULL) {
239 setenv(*set_env, np, 1);
240 free(np);
241 }
242 }
243 ++set_env;
244 }
245 }
246 }
247}
248
249
250static int

Callers 1

setlogincontextFunction · 0.85

Calls 6

login_getpathFunction · 0.85
login_getcapstrFunction · 0.85
substvarFunction · 0.85
login_getcaplistFunction · 0.85
strchrFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected