DragonFly submit List (threaded) for 2005-09
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]
[PATCH] corrected setenv|putenv rc checking (lib)
Index: libutil/login_cap.h
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/lib/libutil/login_cap.h,v
retrieving revision 1.3
diff -u -r1.3 login_cap.h
--- libutil/login_cap.h 12 Nov 2003 20:21:31 -0000 1.3
+++ libutil/login_cap.h 30 Sep 2005 11:51:34 -0000
@@ -116,7 +116,7 @@
int setclasscontext (const char*, unsigned int);
int setusercontext (login_cap_t*, const struct passwd*, uid_t, unsigned int);
void setclassresources (login_cap_t *);
-void setclassenvironment (login_cap_t *, const struct passwd *, int);
+int setclassenvironment (login_cap_t *, const struct passwd *, int);
/* Most of these functions are deprecated */
int auth_approve (login_cap_t*, const char*, const char*);
Index: libutil/login_class.3
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/lib/libutil/login_class.3,v
retrieving revision 1.2
diff -u -r1.2 login_class.3
--- libutil/login_class.3 17 Jun 2003 04:26:52 -0000 1.2
+++ libutil/login_class.3 30 Sep 2005 12:10:11 -0000
@@ -40,7 +40,7 @@
.Fn setusercontext "login_cap_t *lc" "const struct passwd *pwd" "uid_t uid" "unsigned int flags"
.Ft void
.Fn setclassresources "login_cap_t *lc"
-.Ft void
+.Ft int
.Fn setclassenvironment "login_cap_t *lc" "const struct passwd *pwd" "int paths"
.Sh DESCRIPTION
These functions provide a higher level interface to the login class
@@ -172,6 +172,8 @@
functions are subsets of the setcontext functions above, but may
be useful in isolation.
.Sh RETURN VALUES
+.Fn setclassenvironment
+,
.Fn setclasscontext
and
.Fn setusercontext
@@ -180,6 +182,13 @@
or resources, a message is reported to
.Xr syslog 3 ,
with LOG_ERR priority and directed to the currently active facility.
+.Sh ERRORS
+.Bl -tag -width Er
+.It Bq Er ENOMEM
+The function
+.Fn setclassenvironment
+failed because it were unable to allocate memory for the environment.
+.El
.Sh SEE ALSO
.Xr setgid 2 ,
.Xr setlogin 2 ,
Index: libutil/login_class.c
===================================================================
RCS file: /mnt/share/dragonfly-cvs/src/lib/libutil/login_class.c,v
retrieving revision 1.4
diff -u -r1.4 login_class.c
--- libutil/login_class.c 4 Mar 2005 04:31:11 -0000 1.4
+++ libutil/login_class.c 30 Sep 2005 12:04:42 -0000
@@ -192,7 +192,7 @@
}
-void
+int
setclassenvironment(login_cap_t *lc, const struct passwd * pwd, int paths)
{
struct login_vars *vars = paths ? pathvars : envars;
@@ -210,10 +210,17 @@
char * np = substvar(var, pwd, hlen, pch, nlen);
if (np != NULL) {
- setenv(vars->var, np, vars->overwrite);
+ if (setenv(vars->var, np, vars->overwrite) != 0) {
+ syslog(LOG_ERR, "setclassenvironment: %m");
+ free(np);
+ return -1;
+ }
free(np);
} else if (vars->def != NULL) {
- setenv(vars->var, vars->def, 0);
+ if (setenv(vars->var, vars->def, 0) != 0) {
+ syslog(LOG_ERR, "setclassenvironment: %m");
+ return -1;
+ }
}
++vars;
}
@@ -234,7 +241,10 @@
*p++ = '\0';
if ((np = substvar(p, pwd, hlen, pch, nlen)) != NULL) {
- setenv(*set_env, np, 1);
+ if (setenv(*set_env, np, 1) != 0) {
+ free(np);
+ return -1;
+ }
free(np);
}
}
@@ -242,6 +252,7 @@
}
}
}
+ return 0;
}
@@ -280,8 +291,9 @@
static mode_t
setlogincontext(login_cap_t *lc, const struct passwd *pwd,
- mode_t mymask, unsigned long flags)
+ mode_t mymask, unsigned long flags, int *errcode)
{
+ *errcode = 0;
if (lc) {
/* Set resources */
if (flags & LOGIN_SETRESOURCES)
@@ -290,11 +302,15 @@
if (flags & LOGIN_SETUMASK)
mymask = (mode_t)login_getcapnum(lc, "umask", mymask, mymask);
/* Set paths */
- if (flags & LOGIN_SETPATH)
- setclassenvironment(lc, pwd, 1);
+ if (flags & LOGIN_SETPATH) {
+ if (setclassenvironment(lc, pwd, 1) == -1)
+ *errcode = -1;
+ }
/* Set environment */
- if (flags & LOGIN_SETENV)
- setclassenvironment(lc, pwd, 0);
+ if (flags & LOGIN_SETENV) {
+ if (setclassenvironment(lc, pwd, 0) == -1)
+ *errcode = -1;
+ }
}
return mymask;
}
@@ -324,6 +340,7 @@
#ifndef __NETBSD_SYSCALLS
struct rtprio rtp;
#endif
+ int errcode;
if (lc == NULL) {
if (pwd != NULL && (lc = login_getpwclass(pwd)) != NULL)
@@ -389,7 +406,11 @@
}
mymask = (flags & LOGIN_SETUMASK) ? umask(LOGIN_DEFUMASK) : 0;
- mymask = setlogincontext(lc, pwd, mymask, flags);
+ mymask = setlogincontext(lc, pwd, mymask, flags, &errcode);
+ if (errcode == -1) {
+ login_close(llc);
+ return -1;
+ }
login_close(llc);
/* This needs to be done after anything that needs root privs */
@@ -402,7 +423,11 @@
* Now, we repeat some of the above for the user's private entries
*/
if ((lc = login_getuserclass(pwd)) != NULL) {
- mymask = setlogincontext(lc, pwd, mymask, flags);
+ mymask = setlogincontext(lc, pwd, mymask, flags, &errcode);
+ if (errcode == -1) {
+ login_close(lc);
+ return -1;
+ }
login_close(lc);
}
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]