[Pkg-wmaker-commits] [wmbiff] 68/77: cleanup to use grabCommandOutput in passwordMgr instead of duplicating the popen/fgets/pclose code
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Thu Aug 20 03:01:18 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to tag wmbiff_0_4_0
in repository wmbiff.
commit 3fc335a5f7846165b6f860659b27cec64566652b
Author: bluehal <bluehal>
Date: Sat Apr 27 08:54:01 2002 +0000
cleanup to use grabCommandOutput in passwordMgr instead of duplicating the popen/fgets/pclose code
---
wmbiff/Client.h | 5 +++--
wmbiff/ShellClient.c | 23 +++++++++++------------
wmbiff/passwordMgr.c | 39 +++++++++++++++------------------------
3 files changed, 29 insertions(+), 38 deletions(-)
diff --git a/wmbiff/Client.h b/wmbiff/Client.h
index 4f60f84..f092e98 100644
--- a/wmbiff/Client.h
+++ b/wmbiff/Client.h
@@ -1,11 +1,11 @@
-/* $Id: Client.h,v 1.20 2002/04/27 08:29:59 bluehal Exp $ */
+/* $Id: Client.h,v 1.21 2002/04/27 08:54:01 bluehal Exp $ */
/* Author : Scott Holden ( scotth at thezone.net )
Modified : Yong-iL Joh ( tolkien at mizi.com )
Modified : Jorge Garc�a ( Jorge.Garcia at uv.es )
*
* Email Checker Pop3/Imap4/Licq/Gicu/mbox/maildir/finger
*
- * Last Updated : $Date: 2002/04/27 08:29:59 $
+ * Last Updated : $Date: 2002/04/27 08:54:01 $
*
*/
@@ -88,6 +88,7 @@ FILE *openMailbox(Pop3 pc, const char *mbox_filename);
char *backtickExpand(Pop3 pc, const char *path);
int fileHasChanged(const char *mbox_filename, time_t * atime,
time_t * mtime, off_t * size);
+int grabCommandOutput(Pop3 pc, const char *command, char **output);
/* _NONE is for silent operation. _ERROR is for things that should
be printed assuming that the user might possibly see them. _INFO is
diff --git a/wmbiff/ShellClient.c b/wmbiff/ShellClient.c
index aaa7714..23971f0 100644
--- a/wmbiff/ShellClient.c
+++ b/wmbiff/ShellClient.c
@@ -65,35 +65,33 @@ static int kind_pclose(FILE * F, const char *command, Pop3 pc)
to fail */
SH_DM(pc, DEBUG_ERROR, "pclose '%s' failed: %s\n",
command, strerror(errno));
- return (-1);
} else {
SH_DM(pc, DEBUG_ERROR,
"'%s' exited with non-zero status %d\n", command,
exit_status);
- return (-1);
}
}
- return (0);
+ return (exit_status);
}
-char *grabCommandOutput(Pop3 pc, const char *command)
+int grabCommandOutput(Pop3 pc, const char *command, char **output)
{
FILE *F;
char linebuf[512];
SH_DM(pc, DEBUG_INFO, "Executing '%s'\n", command);
+ *output = NULL;
if ((F = kind_popen(command, "r")) == NULL) {
- return NULL;
+ return -1;
}
if (fgets(linebuf, 512, F) == NULL) {
SH_DM(pc, DEBUG_ERROR,
"fgets: unable to read the output of '%s': %s\n", command,
strerror(errno));
- kind_pclose(F, command, pc);
- return NULL;
+ } else {
+ chomp(linebuf);
+ *output = strdup(linebuf);
}
- chomp(linebuf);
- kind_pclose(F, command, pc);
- return (strdup(linebuf));
+ return (kind_pclose(F, command, pc));
}
char *backtickExpand(Pop3 pc, const char *path)
@@ -113,7 +111,7 @@ char *backtickExpand(Pop3 pc, const char *path)
strncat(bigbuffer, path, tickstart - path);
command = strdup(tickstart + 1);
command[tickend - tickstart - 1] = '\0';
- commandoutput = grabCommandOutput(pc, command);
+ (void) grabCommandOutput(pc, command, &commandoutput);
free(command);
if (commandoutput != NULL) {
strcat(bigbuffer, commandoutput);
@@ -138,7 +136,8 @@ int shellCmdCheck(Pop3 pc)
/* fetch the first line of input */
pc->TextStatus[0] = '\0';
- if ((commandOutput = grabCommandOutput(pc, pc->path)) == NULL) {
+ (void) grabCommandOutput(pc, pc->path, &commandOutput);
+ if (commandOutput == NULL) {
return -1;
}
SH_DM(pc, DEBUG_INFO, "'%s' returned '%s'\n", pc->path, commandOutput);
diff --git a/wmbiff/passwordMgr.c b/wmbiff/passwordMgr.c
index 5e4ea1d..2d991f1 100644
--- a/wmbiff/passwordMgr.c
+++ b/wmbiff/passwordMgr.c
@@ -105,18 +105,19 @@ const char *passwordFor(const char *username,
if (pc->askpass != NULL) {
/* check that the executed file is a good one. */
if (permissions_ok(pc, pc->askpass)) {
- char buf[255];
- FILE *fp;
- int exit_status;
- strcpy(p->user, username);
- strcpy(p->server, servername);
- sprintf(buf, "%s 'password for wmbiff: %s@%s'",
+ char command[255];
+ char *password_ptr;
+ sprintf(command, "%s 'password for wmbiff: %s@%s'",
pc->askpass, username, servername);
- DM(pc, DEBUG_INFO, "passmgr: invoking %s\n", buf);
- fp = popen(buf, "r");
+ (void) grabCommandOutput(pc, command, &password_ptr);
+ /* it's not clear what to do with the exit
+ status, though we can get it from
+ grabCommandOutput if needed to deal with some
+ programs that will print a message but exit
+ non-zero on error */
- if (fgets(p->password, 32, fp) == NULL) {
+ if (password_ptr == NULL) {
/* this likely means that the user cancelled, and doesn't
want us to keep asking about the password. */
DM(pc, DEBUG_ERROR,
@@ -127,21 +128,12 @@ const char *passwordFor(const char *username,
exit(EXIT_FAILURE);
}
- exit_status = pclose(fp);
- if (exit_status != 0) {
- if (exit_status == -1) {
- /* an expected case with the signal handler */
- DM(pc, DEBUG_INFO,
- "passmgr: pclose from '%s' failed: %s\n", buf,
- strerror(errno));
- } else {
- DM(pc, DEBUG_ERROR,
- "passmgr: '%s' returned non-zero exit status %d\n",
- buf, exit_status);
- }
- }
+ strcpy(p->user, username);
+ strcpy(p->server, servername);
+ strncpy(p->password, password_ptr, 31);
+ p->password[31] = '\0'; /* force a null termination */
+ free(password_ptr);
- chomp(p->password);
p->next = pass_list;
pass_list = p;
return (p->password);
@@ -150,4 +142,3 @@ const char *passwordFor(const char *username,
return (NULL);
}
-
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbiff.git
More information about the Pkg-wmaker-commits
mailing list