Go Back

0 /*

1 * ISC License

2 * Copyright (c) 2023 RMF <rawmonk@firemail.cc>

3 */

4 #include <stdio.h>

5 #include <stdlib.h>

6 #include <time.h>

7 #include <string.h>

8 #include "macro.h"

9 #include "strlcpy.h"

10 #include "error.h"

11 #define KNOWN_HOSTS_INTERNAL

12 #include "known_hosts.h"

13 #define ABOUT_INTERNAL

14 #include "about.h"

15

16 int about_known_hosts_arg(const char *param) {

17 int ret;

18 if ((ret = known_hosts_forget(param))) return ret;

19 if ((ret = known_hosts_rewrite())) return ret;

20 return 0;

21 }

22

23 int about_known_hosts(char **out, size_t *length_out) {

24

25 char *data = NULL;

26 size_t length = 0;

27 size_t i;

28 const char title[] = "# Known hosts\n\n";

29

30 if (!(data = dyn_strcat(data, &length, V(header)))) goto fail;

31 if (!(data = dyn_strcat(data, &length, V(title)))) goto fail;

32

33 for (i = 0; i < HT_SIZE; i++) {

34 struct known_host *ptr;

35 for (ptr = known_hosts[i]; ptr; ptr = ptr->next) {

36 char buf[1024], from[64], to[64];

37 int len;

38 struct tm *tm;

39

40 tm = localtime(&ptr->start);

41 strftime(V(from), "%Y/%m/%d %H:%M:%S", tm);

42

43 tm = localtime(&ptr->end);

44 strftime(V(to), "%Y/%m/%d %H:%M:%S", tm);

45

46 len = snprintf(V(buf),

47 "* %s\n> Hash: %s\n"

48 "> From: %s\n> Expiration: %s\n"

49 "=>/%ld Forget\n\n",

50 ptr->host, ptr->hash,

51 from, to, i) + 1;

52 if (!(data = dyn_strcat(data, &length, buf, len)))

53 goto fail;

54 }

55 }

56

57 *out = data;

58 *length_out = length;

59 return 0;

60 fail:

61 free(data);

62 return ERROR_MEMORY_FAILURE;

63 }

64