summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixInit.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2007-07-31 10:04:28 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2007-07-31 10:04:28 (GMT)
commit6c15ea3d78e54b7f60df39abef2d6ddd13fdc334 (patch)
treee14defd2b6cac3f15f78aa102d36b75e26ebab42 /unix/tclUnixInit.c
parentf82900cff8398c8d63ab4557833bdf0d9ba13d3a (diff)
downloadtcl-6c15ea3d78e54b7f60df39abef2d6ddd13fdc334.zip
tcl-6c15ea3d78e54b7f60df39abef2d6ddd13fdc334.tar.gz
tcl-6c15ea3d78e54b7f60df39abef2d6ddd13fdc334.tar.bz2
* unix/tclUnixInit.c (TclpSetVariables): Use the thread-safe getpwuid
replacement to fill the tcl_platform(user) field as it is not subject to spoofing.
Diffstat (limited to 'unix/tclUnixInit.c')
-rw-r--r--unix/tclUnixInit.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c
index d4f1003..3d554d9 100644
--- a/unix/tclUnixInit.c
+++ b/unix/tclUnixInit.c
@@ -7,7 +7,7 @@
* Copyright (c) 1999 by Scriptics Corporation.
* All rights reserved.
*
- * RCS: @(#) $Id: tclUnixInit.c,v 1.70 2007/04/23 20:35:55 das Exp $
+ * RCS: @(#) $Id: tclUnixInit.c,v 1.71 2007/07/31 10:04:28 dkf Exp $
*/
#include "tclInt.h"
@@ -415,7 +415,8 @@ TclpInitPlatform(void)
/*
* Find local symbols. Don't report an error if we fail.
*/
- (void) dlopen (NULL, RTLD_NOW); /* INTL: Native. */
+
+ (void) dlopen(NULL, RTLD_NOW); /* INTL: Native. */
#endif
/*
@@ -441,6 +442,7 @@ TclpInitPlatform(void)
#ifdef GET_DARWIN_RELEASE
{
struct utsname name;
+
if (!uname(&name)) {
tclMacOSXDarwinRelease = strtol(name.release, NULL, 10);
}
@@ -762,7 +764,6 @@ TclpSetVariables(
struct utsname name;
#endif
int unameOK;
- CONST char *user;
Tcl_DString ds;
#ifdef HAVE_COREFOUNDATION
@@ -772,6 +773,7 @@ TclpSetVariables(
/*
* Set msgcat fallback locale to current CFLocale identifier.
*/
+
CFLocaleRef localeRef;
if (CFLocaleCopyCurrent != NULL && CFLocaleGetIdentifier != NULL &&
@@ -790,11 +792,10 @@ TclpSetVariables(
}
CFRelease(localeRef);
}
-#endif
+#endif /* MAC_OS_X_VERSION_MAX_ALLOWED > 1020 */
if (MacOSXGetLibraryPath(interp, MAXPATHLEN, tclLibPath) == TCL_OK) {
CONST char *str;
- Tcl_DString ds;
CFBundleRef bundleRef;
Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
@@ -912,12 +913,12 @@ TclpSetVariables(
Tcl_SetVar2(interp, "tcl_platform", "osVersion", name.release,
TCL_GLOBAL_ONLY|TCL_APPEND_VALUE);
-#endif
+#endif /* DJGPP */
}
Tcl_SetVar2(interp, "tcl_platform", "machine", name.machine,
TCL_GLOBAL_ONLY);
}
-#endif
+#endif /* !NO_UNAME */
if (!unameOK) {
Tcl_SetVar2(interp, "tcl_platform", "os", "", TCL_GLOBAL_ONLY);
Tcl_SetVar2(interp, "tcl_platform", "osVersion", "", TCL_GLOBAL_ONLY);
@@ -925,19 +926,24 @@ TclpSetVariables(
}
/*
- * Copy USER or LOGNAME environment variable into tcl_platform(user).
+ * Copy the username of the real user (according to getuid()) into
+ * tcl_platform(user).
*/
- Tcl_DStringInit(&ds);
- user = TclGetEnv("USER", &ds);
- if (user == NULL) {
- user = TclGetEnv("LOGNAME", &ds);
- if (user == NULL) {
+ {
+ struct passwd *pwEnt = TclpGetPwUid(getuid());
+ const char *user;
+
+ if (pwEnt == NULL) {
user = "";
+ Tcl_DStringInit(&ds); /* ensure cleanliness */
+ } else {
+ user = Tcl_ExternalToUtfDString(NULL, pwEnt->pw_name, -1, &ds);
}
+
+ Tcl_SetVar2(interp, "tcl_platform", "user", user, TCL_GLOBAL_ONLY);
+ Tcl_DStringFree(&ds);
}
- Tcl_SetVar2(interp, "tcl_platform", "user", user, TCL_GLOBAL_ONLY);
- Tcl_DStringFree(&ds);
}
/*