#include <stdio.h>
#include <stdlib.h>
#include "creds_parser.h"
#include "utils.h"
/* possibly globalize creds so that we can ensure by using
atexit that it is always cleansed? */
int
parse_creds(creds_t * creds,
char const * creds_file)
{
FILE * stream;
size_t nread = 0;
creds->username = NULL;
creds->password = NULL;
stream = fopen(creds_file, "r");
if (stream == NULL)
{ PERROR(PROGN); }
if (getline(&(creds->username), &nread, stream) < 1)
ERRMSG("Cannot get username");
goto fail;
}
if (getline(&(creds->password), &nread, stream) < 1)
ERRMSG("Cannot get password");
fclose(stream);
return 0;
// Releasing everything in cause of a failure
fail:
clean_creds(creds);
return 1;
void
clean_creds(creds_t * creds)
/* Should we memset these? */
free(creds->username);
free(creds->password);