|
Packit Service |
20376f |
#include "common.h"
|
|
Packit Service |
20376f |
#include <stdio.h>
|
|
Packit Service |
20376f |
#include <string.h>
|
|
Packit Service |
20376f |
#include <errno.h>
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Shamelessly borrowed from http://stackoverflow.com/questions/3417837/
|
|
Packit Service |
20376f |
* with permission of the original author, Martin Pool.
|
|
Packit Service |
20376f |
* http://sourcefrog.net/weblog/software/languages/C/unused.html
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
#ifdef UNUSED
|
|
Packit Service |
20376f |
#elif defined(__GNUC__)
|
|
Packit Service |
20376f |
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
|
|
Packit Service |
20376f |
#elif defined(__LCLINT__)
|
|
Packit Service |
20376f |
# define UNUSED(x) /*@unused@*/ x
|
|
Packit Service |
20376f |
#else
|
|
Packit Service |
20376f |
# define UNUSED(x) x
|
|
Packit Service |
20376f |
#endif
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
static int readline(char **out)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
int c, error = 0, length = 0, allocated = 0;
|
|
Packit Service |
20376f |
char *line = NULL;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
errno = 0;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
while ((c = getchar()) != EOF) {
|
|
Packit Service |
20376f |
if (length == allocated) {
|
|
Packit Service |
20376f |
allocated += 16;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if ((line = realloc(line, allocated)) == NULL) {
|
|
Packit Service |
20376f |
error = -1;
|
|
Packit Service |
20376f |
goto error;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (c == '\n')
|
|
Packit Service |
20376f |
break;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
line[length++] = c;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (errno != 0) {
|
|
Packit Service |
20376f |
error = -1;
|
|
Packit Service |
20376f |
goto error;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
line[length] = '\0';
|
|
Packit Service |
20376f |
*out = line;
|
|
Packit Service |
20376f |
line = NULL;
|
|
Packit Service |
20376f |
error = length;
|
|
Packit Service |
20376f |
error:
|
|
Packit Service |
20376f |
free(line);
|
|
Packit Service |
20376f |
return error;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int cred_acquire_cb(git_cred **out,
|
|
Packit Service |
20376f |
const char * UNUSED(url),
|
|
Packit Service |
20376f |
const char * UNUSED(username_from_url),
|
|
Packit Service |
20376f |
unsigned int UNUSED(allowed_types),
|
|
Packit Service |
20376f |
void * UNUSED(payload))
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
char *username = NULL, *password = NULL;
|
|
Packit Service |
20376f |
int error;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
printf("Username: ");
|
|
Packit Service |
20376f |
if (readline(&username) < 0) {
|
|
Packit Service |
20376f |
fprintf(stderr, "Unable to read username: %s", strerror(errno));
|
|
Packit Service |
20376f |
return -1;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* Yup. Right there on your terminal. Careful where you copy/paste output. */
|
|
Packit Service |
20376f |
printf("Password: ");
|
|
Packit Service |
20376f |
if (readline(&password) < 0) {
|
|
Packit Service |
20376f |
fprintf(stderr, "Unable to read password: %s", strerror(errno));
|
|
Packit Service |
20376f |
free(username);
|
|
Packit Service |
20376f |
return -1;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
error = git_cred_userpass_plaintext_new(out, username, password);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
free(username);
|
|
Packit Service |
20376f |
free(password);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
return error;
|
|
Packit Service |
20376f |
}
|