Browse Source

remove password_eval() which moved to eval()

pull/84/head
Martin Lambers 2 months ago
parent
commit
e16c5d9d42
  1. 63
      src/password.c
  2. 9
      src/password.h

63
src/password.c

@ -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;
}

9
src/password.h

@ -44,13 +44,4 @@ char *password_get(const char *hostname, const char *user,
int consult_netrc,
int getpass_only_via_tty);
/*
* password_eval()
*
* Evaluates command in 'arg' and stores result in 'buf' (which is allocated).
* Returns non-zero if command execution failed, otherwise zero. On error,
* *errstr will contain an error string.
*/
int password_eval(const char *arg, char **buf, char **errstr);
#endif

Loading…
Cancel
Save