|
|
|
@ -223,66 +223,3 @@ char *password_get(const char *hostname, const char *user,
|
|
|
|
|
|
|
|
|
|
return password; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* password_eval() |
|
|
|
|
* |
|
|
|
|
* see password.h |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#define LINEBUFSIZE 501 |
|
|
|
|
int password_eval(const char *arg, char **buf, char **errstr) |
|
|
|
|
{ |
|
|
|
|
FILE *eval; |
|
|
|
|
size_t bufsize; |
|
|
|
|
size_t len; |
|
|
|
|
|
|
|
|
|
*buf = NULL; |
|
|
|
|
*errstr = NULL; |
|
|
|
|
errno = 0; |
|
|
|
|
bufsize = 1; /* Account for the null character. */ |
|
|
|
|
|
|
|
|
|
if (!(eval = popen(arg, "r"))) |
|
|
|
|
{ |
|
|
|
|
if (errno == 0) |
|
|
|
|
{ |
|
|
|
|
errno = ENOMEM; |
|
|
|
|
} |
|
|
|
|
*errstr = xasprintf(_("cannot evaluate '%s': %s"), arg, strerror(errno)); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
do |
|
|
|
|
{ |
|
|
|
|
bufsize += LINEBUFSIZE; |
|
|
|
|
*buf = xrealloc(*buf, bufsize); |
|
|
|
|
if (!fgets(&(*buf)[bufsize - LINEBUFSIZE - 1], LINEBUFSIZE + 1, eval)) |
|
|
|
|
{ |
|
|
|
|
*errstr = xasprintf(_("cannot read output of '%s'"), arg); |
|
|
|
|
pclose(eval); |
|
|
|
|
free(*buf); |
|
|
|
|
*buf = NULL; |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
len = strlen(*buf); |
|
|
|
|
if (len > 0 && (*buf)[len - 1] == '\n') |
|
|
|
|
{ |
|
|
|
|
/* Read only the first line. */ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
while (!feof(eval)); |
|
|
|
|
pclose(eval); |
|
|
|
|
|
|
|
|
|
if (len > 0 && (*buf)[len - 1] == '\n') |
|
|
|
|
{ |
|
|
|
|
(*buf)[len - 1] = '\0'; |
|
|
|
|
if (len - 1 > 0 && (*buf)[len - 2] == '\r') |
|
|
|
|
{ |
|
|
|
|
(*buf)[len - 2] = '\0'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|