67 lines
1.4 KiB
C
67 lines
1.4 KiB
C
|
/*
|
||
|
This software is licensed under GPL-3, as shown in the file LICENSE
|
||
|
Author: Linux Gruppe IRB
|
||
|
Copyright: Linux Gruppe IRB, 2024
|
||
|
*/
|
||
|
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/stat.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <unistd.h>
|
||
|
#include <errno.h>
|
||
|
#include <glib.h>
|
||
|
#include <pwd.h>
|
||
|
|
||
|
#include "authorized_eid.h"
|
||
|
#include "client.h"
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
struct passwd *passwd;
|
||
|
FILE *authorized_eid;
|
||
|
gchar *hash;
|
||
|
CURL *curl;
|
||
|
char *res;
|
||
|
|
||
|
if ((curl = curl_easy_init()) == NULL)
|
||
|
{
|
||
|
fprintf(stderr, "curl_easy_init() failed");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
|
port = 24727;
|
||
|
res = eidResponse(curl);
|
||
|
|
||
|
if (res == NULL)
|
||
|
{
|
||
|
fprintf(stderr, "Did not receive a valid result from the web\n");
|
||
|
exit(-2);
|
||
|
}
|
||
|
|
||
|
hash = g_compute_checksum_for_string(G_CHECKSUM_SHA512, res, strlen(res));
|
||
|
errno = 0;
|
||
|
|
||
|
if ((passwd = getpwuid(geteuid())) == NULL)
|
||
|
{
|
||
|
fprintf(stderr, "Error while trying to find passwd entry for effective UID %u: ", geteuid());
|
||
|
|
||
|
if (errno != 0)
|
||
|
fprintf(stderr, "%s\n", strerror(errno));
|
||
|
else
|
||
|
fprintf(stderr, "No such user\n");
|
||
|
|
||
|
exit(-3);
|
||
|
}
|
||
|
|
||
|
if ((authorized_eid = auth_fopen(passwd, "a")) == NULL)
|
||
|
{
|
||
|
fprintf(stderr, "Could not open german eID card data file for writing\n");
|
||
|
exit(-4);
|
||
|
}
|
||
|
|
||
|
fchmod(fileno(authorized_eid), S_IRUSR | S_IWUSR);
|
||
|
fprintf(authorized_eid, "%s\n", hash);
|
||
|
fclose(authorized_eid);
|
||
|
}
|