💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › 11dfb138d73e7eb7f4b5207d1c58e… captured on 2024-02-05 at 09:54:26. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-12-28)

-=-=-=-=-=-=-

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 <string.h>

7 #include <dirent.h>

8 #include <unistd.h>

9 #include "macro.h"

10 #include "strlcpy.h"

11 #include "error.h"

12 #include "storage.h"

13 #define ABOUT_INTERNAL

14 #include "about.h"

15

16 int about_certificates_param(const char *param) {

17

18 char path[PATH_MAX];

19 size_t len;

20 FILE *f;

21

22 len = STRLCPY(path, param);

23 if (len >= sizeof(path)) return ERROR_INVALID_ARGUMENT;

24 strlcpy(&path[len], ".crt", sizeof(path) - len);

25 if (!(f = storage_fopen(path, "r"))) return ERROR_INVALID_ARGUMENT;

26 fclose(f);

27 strlcpy(&path[len], ".key", sizeof(path) - len);

28 if (!(f = storage_fopen(path, "r"))) return ERROR_INVALID_ARGUMENT;

29 fclose(f);

30

31 unlinkat(storage_fd, path, 0);

32 strlcpy(&path[len], ".crt", sizeof(path) - len);

33 unlinkat(storage_fd, path, 0);

34 return 0;

35 }

36

37 int about_certificates(char **out, size_t *length_out) {

38

39 char *data = NULL;

40 size_t length = 0;

41 const char title[] = "# Client certificates\n\n";

42 DIR *dir;

43 struct dirent *entry;

44 char host[1024] = {0};

45

46 ASSERT(sizeof(host) > sizeof(entry->d_name))

47

48 if (!(dir = fdopendir(dup(storage_fd)))) return ERROR_ERRNO;

49 rewinddir(dir);

50

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

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

53

54 while ((entry = readdir(dir))) {

55 char *end = entry->d_name + strnlen(V(entry->d_name)) - 4;

56 char buf[sizeof(host) * 2];

57 int len;

58 if (strstr(entry->d_name, ".crt") != end) {

59 if (strstr(entry->d_name, ".key") == end) {

60 strlcpy(host, entry->d_name,

61 end - entry->d_name + 1);

62 }

63 continue;

64 }

65 if (memcmp(host, entry->d_name, end - entry->d_name)) continue;

66 len = snprintf(V(buf), "* %s\n=>%s Delete\n\n", host, host);

67 if (!(data = dyn_strcat(data, &length, buf, len))) goto fail;

68 }

69

70 closedir(dir);

71

72 *out = data;

73 *length_out = length;

74 return 0;

75 fail:

76 closedir(dir);

77 free(data);

78 return ERROR_MEMORY_FAILURE;

79 }

80