<pre style='margin:0'>
Rainer Müller (raimue) pushed a commit to branch master
in repository macports-base.
</pre>
<p><a href="https://github.com/macports/macports-base/commit/c2a0b5a8c6d3306d6a85c2d7dcb9685462174b2a">https://github.com/macports/macports-base/commit/c2a0b5a8c6d3306d6a85c2d7dcb9685462174b2a</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit c2a0b5a8c6d3306d6a85c2d7dcb9685462174b2a
</span>Author: Rainer Müller <raimue@macports.org>
AuthorDate: Sat Nov 5 02:55:35 2016 +0100
<span style='display:block; white-space:pre;color:#404040;'> UpdateVCS: change HOME when running VCS commands
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Implement getpwuid in Pextlib as wrapper around getpwuid(3).
</span>---
src/macports1.0/macports.tcl | 7 +++
src/pextlib1.0/Pextlib.c | 1 +
src/pextlib1.0/uid.c | 101 +++++++++++++++++++++++++++++++++++++++++++
src/pextlib1.0/uid.h | 1 +
4 files changed, 110 insertions(+)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/macports1.0/macports.tcl b/src/macports1.0/macports.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index 8e5a66a..6443fd6 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/macports1.0/macports.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/macports1.0/macports.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2449,6 +2449,7 @@ proc macports::GetVCSUpdateCmd portDir {
</span> # This proc could probably be generalized and used elsewhere.
#
proc macports::UpdateVCS {cmd portDir} {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ global env
</span> if {[getuid] == 0} {
# Must change egid before dropping root euid.
set oldEGID [getegid]
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2459,6 +2460,10 @@ proc macports::UpdateVCS {cmd portDir} {
</span> set newEUID [name_to_uid [file attributes $portDir -owner]]
seteuid $newEUID
ui_debug "Changed effective user ID from $oldEUID to $newEUID"
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ set oldHOME $env(HOME)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set newHOME [getpwuid $newEUID dir]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set env(HOME) $newHOME
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Changed HOME to $newHOME"
</span> }
ui_debug $cmd
catch {system $cmd} result options
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -2467,6 +2472,8 @@ proc macports::UpdateVCS {cmd portDir} {
</span> ui_debug "Changed effective user ID from $newEUID to $oldEUID"
setegid $oldEGID
ui_debug "Changed effective group ID from $newEGID to $oldEGID"
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ set env(HOME) $oldHOME
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ui_debug "Changed HOME to $oldHOME"
</span> }
return -options $options $result
}
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/pextlib1.0/Pextlib.c b/src/pextlib1.0/Pextlib.c
</span><span style='display:block; white-space:pre;color:#808080;'>index e7d6a34..03e6732 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/pextlib1.0/Pextlib.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/pextlib1.0/Pextlib.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -660,6 +660,7 @@ int Pextlib_Init(Tcl_Interp *interp)
</span> Tcl_CreateObjCommand(interp, "seteuid", seteuidCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "setgid", setgidCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "setegid", setegidCmd, NULL, NULL);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_CreateObjCommand(interp, "getpwuid", getpwuidCmd, NULL, NULL);
</span> Tcl_CreateObjCommand(interp, "name_to_uid", name_to_uidCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "uid_to_name", uid_to_nameCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "uname_to_gid", uname_to_gidCmd, NULL, NULL);
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/pextlib1.0/uid.c b/src/pextlib1.0/uid.c
</span><span style='display:block; white-space:pre;color:#808080;'>index a87f7d8..f2f435b 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/pextlib1.0/uid.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/pextlib1.0/uid.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -202,6 +202,107 @@ int setegidCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_O
</span> return TCL_OK;
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+/**
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * wrapper around getpwuid(3)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * getpwuid <uid> [<field>]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+*/
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int getpwuidCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ uid_t uid;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const char *field = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ struct passwd *pw;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_Obj *result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Check the arg count */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (objc < 2 || objc > 3) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_WrongNumArgs(interp, 1, objv, "getpwuid uid ?field?");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Need to cast uid from int to unsigned int */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (Tcl_GetIntFromObj(interp, objv[1], (int *) &uid) != TCL_OK) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetResult(interp, "invalid uid", TCL_STATIC);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (objc == 3) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ field = Tcl_GetString(objv[2]);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ pw = getpwuid(uid);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (pw == NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ result = Tcl_NewStringObj("getpwuid failed for ", -1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_AppendObjToObj(result, Tcl_NewIntObj(uid));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetObjResult(interp, result);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (field == NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_Obj *reslist;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reslist = Tcl_NewListObj(0, NULL);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj("name", -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj(pw->pw_name, -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj("passwd", -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj(pw->pw_passwd, -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj("uid", -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewIntObj(pw->pw_uid));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj("gid", -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewIntObj(pw->pw_gid));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj("change", -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewLongObj(pw->pw_change));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj("class", -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj(pw->pw_class, -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj("gecos", -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj(pw->pw_gecos, -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj("dir", -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj(pw->pw_dir, -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj("shell", -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj(pw->pw_shell, -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewStringObj("expire", -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_ListObjAppendElement(interp, reslist, Tcl_NewLongObj(pw->pw_expire));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetObjResult(interp, reslist);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (strcmp(field, "name") == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetResult(interp, pw->pw_name, TCL_VOLATILE);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (strcmp(field, "passwd") == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetResult(interp, pw->pw_passwd, TCL_VOLATILE);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (strcmp(field, "uid") == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetObjResult(interp, Tcl_NewIntObj(pw->pw_uid));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (strcmp(field, "gid") == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetObjResult(interp, Tcl_NewIntObj(pw->pw_gid));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (strcmp(field, "change") == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetObjResult(interp, Tcl_NewLongObj(pw->pw_change));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (strcmp(field, "class") == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetResult(interp, pw->pw_class, TCL_VOLATILE);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (strcmp(field, "gecos") == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetResult(interp, pw->pw_gecos, TCL_VOLATILE);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (strcmp(field, "dir") == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetResult(interp, pw->pw_dir, TCL_VOLATILE);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (strcmp(field, "shell") == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetResult(interp, pw->pw_shell, TCL_VOLATILE);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (strcmp(field, "expire") == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetObjResult(interp, Tcl_NewLongObj(pw->pw_expire));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ result = Tcl_NewStringObj("invalid field ", -1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_AppendObjToObj(result, Tcl_NewStringObj(field, -1));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetObjResult(interp, result);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> /*
name_to_uid
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/pextlib1.0/uid.h b/src/pextlib1.0/uid.h
</span><span style='display:block; white-space:pre;color:#808080;'>index 566d5c6..179a3df 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/pextlib1.0/uid.h
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/pextlib1.0/uid.h
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -43,6 +43,7 @@ int setuidCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONS
</span> int seteuidCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
int setgidCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
int setegidCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+int getpwuidCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
</span> int name_to_uidCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
int uid_to_nameCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
int uname_to_gidCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
</pre><pre style='margin:0'>
</pre>