[53210] trunk/base/src/pextlib1.0/Pextlib.c
toby at macports.org
toby at macports.org
Wed Jul 1 00:32:49 PDT 2009
Revision: 53210
http://trac.macports.org/changeset/53210
Author: toby at macports.org
Date: 2009-07-01 00:32:47 -0700 (Wed, 01 Jul 2009)
Log Message:
-----------
Delete the 'sudo' command, doesn't look like anything uses it.
Modified Paths:
--------------
trunk/base/src/pextlib1.0/Pextlib.c
Modified: trunk/base/src/pextlib1.0/Pextlib.c
===================================================================
--- trunk/base/src/pextlib1.0/Pextlib.c 2009-07-01 06:51:52 UTC (rev 53209)
+++ trunk/base/src/pextlib1.0/Pextlib.c 2009-07-01 07:32:47 UTC (rev 53210)
@@ -375,151 +375,6 @@
return status;
}
-int SudoCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
-{
- char *buf;
- struct linebuf circbuf[CBUFSIZ];
- size_t linelen;
- char *args[4];
- char *cmdstring, *passwd;
- FILE *pdes;
- int fdset[2];
- int fline, pos, ret;
- pid_t pid;
- Tcl_Obj *errbuf;
- Tcl_Obj *tcl_result;
-
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "password command");
- return TCL_ERROR;
- }
- passwd = Tcl_GetString(objv[1]);
- cmdstring = Tcl_GetString(objv[2]);
-
- if (pipe(fdset) == -1)
- return TCL_ERROR;
-
- /*
- * Fork a child to run the command, in a popen() like fashion -
- * popen() itself is not used because stderr is also desired.
- */
- pid = fork();
- if (pid == -1)
- return TCL_ERROR;
- if (pid == 0) {
- dup2(fdset[0], STDIN_FILENO);
- dup2(fdset[1], STDOUT_FILENO);
- dup2(fdset[1], STDERR_FILENO);
- args[0] = "sudo";
- args[1] = "-S";
- args[2] = cmdstring;
- args[3] = NULL;
- execve("/usr/bin/sudo", args, environ);
- /* Now throw away the privs we just acquired */
- args[1] = "-k";
- args[2] = NULL;
- execve("/usr/bin/sudo", args, environ);
- _exit(1);
- } else {
- write(fdset[1], passwd, strlen(passwd));
- write(fdset[1], "\n", 1);
- close(fdset[1]);
- }
- pdes = fdopen(fdset[0], "r");
-
- /* read from simulated popen() pipe */
- pos = 0;
- bzero(circbuf, sizeof(circbuf));
- while ((buf = fgetln(pdes, &linelen)) != NULL) {
- char *sbuf;
- int slen;
-
- /*
- * Allocate enough space to insert a terminating
- * '\0' if the line is not terminated with a '\n'
- */
- if (buf[linelen - 1] == '\n')
- slen = linelen;
- else
- slen = linelen + 1;
-
- if (circbuf[pos].len == 0)
- sbuf = malloc(slen);
- else {
- sbuf = realloc(circbuf[pos].line, slen);
- }
-
- if (sbuf == NULL) {
- for (fline = pos; pos < fline + CBUFSIZ; pos++) {
- if (circbuf[pos % CBUFSIZ].len != 0)
- free(circbuf[pos % CBUFSIZ].line);
- }
- return TCL_ERROR;
- }
-
- memcpy(sbuf, buf, linelen);
- /* terminate line with '\0',replacing '\n' if it exists */
- sbuf[slen - 1] = '\0';
-
- circbuf[pos].line = sbuf;
- circbuf[pos].len = slen;
-
- if (pos++ == CBUFSIZ - 1)
- pos = 0;
- ret = ui_info(interp, sbuf);
- if (ret != TCL_OK) {
- for (fline = pos; pos < fline + CBUFSIZ; pos++) {
- if (circbuf[pos % CBUFSIZ].len != 0)
- free(circbuf[pos % CBUFSIZ].line);
- }
- return ret;
- }
- }
- fclose(pdes);
-
- if (wait(&ret) != pid)
- return TCL_ERROR;
- if (WIFEXITED(ret)) {
- if (WEXITSTATUS(ret) == 0)
- return TCL_OK;
- else {
- /* Copy the contents of the circular buffer to errbuf */
- Tcl_Obj* errorCode;
- errbuf = Tcl_NewStringObj(NULL, 0);
- for (fline = pos; pos < fline + CBUFSIZ; pos++) {
- if (circbuf[pos % CBUFSIZ].len == 0)
- continue; /* skip empty lines */
-
- /* Append line, minus trailing NULL */
- Tcl_AppendToObj(errbuf, circbuf[pos % CBUFSIZ].line,
- circbuf[pos % CBUFSIZ].len - 1);
-
- /* Re-add previously stripped newline */
- Tcl_AppendToObj(errbuf, "\n", 1);
- free(circbuf[pos % CBUFSIZ].line);
- }
-
- /* set errorCode [list CHILDSTATUS <pid> <code>] */
- errorCode = Tcl_NewListObj(0, NULL);
- Tcl_ListObjAppendElement(interp, errorCode, Tcl_NewStringObj("CHILDSTATUS", -1));
- Tcl_ListObjAppendElement(interp, errorCode, Tcl_NewIntObj(pid));
- Tcl_ListObjAppendElement(interp, errorCode, Tcl_NewIntObj(WEXITSTATUS(ret)));
- Tcl_SetObjErrorCode(interp, errorCode);
-
- /* set result */
- tcl_result = Tcl_NewStringObj("sudo command \"", -1);
- Tcl_AppendToObj(tcl_result, cmdstring, -1);
- Tcl_AppendToObj(tcl_result, "\" returned error ", -1);
- Tcl_AppendObjToObj(tcl_result, Tcl_NewIntObj(WEXITSTATUS(ret)));
- Tcl_AppendToObj(tcl_result, "\nCommand output: ", -1);
- Tcl_AppendObjToObj(tcl_result, errbuf);
- Tcl_SetObjResult(interp, tcl_result);
- return TCL_ERROR;
- }
- } else
- return TCL_ERROR;
-}
-
int FlockCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
static const char errorstr[] = "use one of \"-shared\", \"-exclusive\", or \"-unlock\", and optionally \"-noblock\"";
@@ -1066,7 +921,6 @@
Tcl_CreateObjCommand(interp, "rmd160", RMD160Cmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "sha1", SHA1Cmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "umask", UmaskCmd, NULL, NULL);
- Tcl_CreateObjCommand(interp, "sudo", SudoCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "pipe", PipeCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "curl", CurlCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "symlink", CreateSymlinkCmd, NULL, NULL);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090701/48ff2923/attachment-0001.html>
More information about the macports-changes
mailing list