File tools/Makefile changed (mode: 100644) (index 106077c..33a806f) |
... |
... |
OBJS := \ |
9 |
9 |
../common/tools.o ../common/info.o ../common/decode_text.o \ |
../common/tools.o ../common/info.o ../common/decode_text.o \ |
10 |
10 |
../common/sctools.o ../common/bin2struct.o |
../common/sctools.o ../common/bin2struct.o |
11 |
11 |
|
|
12 |
|
ALL_TOOLS := nd-cert-notify |
|
|
12 |
|
ALL_TOOLS := nd-cert-notify nd-cert-info |
13 |
13 |
|
|
14 |
14 |
all: $(ALL_TOOLS) |
all: $(ALL_TOOLS) |
15 |
15 |
|
|
16 |
16 |
nd-cert-notify: nd-cert-notify.c Makefile $(COMMON_H) $(OBJS) |
nd-cert-notify: nd-cert-notify.c Makefile $(COMMON_H) $(OBJS) |
17 |
17 |
$(CC) $(CFLAGS) $@.c -o $@ $(OBJS) $(CURL_LIBS) |
$(CC) $(CFLAGS) $@.c -o $@ $(OBJS) $(CURL_LIBS) |
18 |
18 |
|
|
|
19 |
|
nd-cert-info: nd-cert-info.c Makefile $(COMMON_H) $(OBJS) |
|
20 |
|
$(CC) $(CFLAGS) $@.c -o $@ $(OBJS) |
|
21 |
|
|
19 |
22 |
.PHONY: clean |
.PHONY: clean |
20 |
23 |
clean: |
clean: |
21 |
24 |
@rm -f $(ALL_TOOLS) |
@rm -f $(ALL_TOOLS) |
File tools/nd-cert-info.c added (mode: 100644) (index 0000000..1ce7c5a) |
|
1 |
|
#include <libgen.h> |
|
2 |
|
#include <stdarg.h> |
|
3 |
|
#include <stdio.h> |
|
4 |
|
|
|
5 |
|
#include <bin2struct.h> |
|
6 |
|
#include <sctools.h> |
|
7 |
|
#include <tools.h> |
|
8 |
|
|
|
9 |
|
void xlog(const unsigned int level, const char *format, ...) |
|
10 |
|
{ |
|
11 |
|
(void) level; |
|
12 |
|
(void) format; |
|
13 |
|
} |
|
14 |
|
|
|
15 |
|
static int user_cb(const unsigned int uid, const char *user_dir) |
|
16 |
|
{ |
|
17 |
|
glob_t certs; |
|
18 |
|
int r, ret = 0; |
|
19 |
|
|
|
20 |
|
fprintf(stdout, "uid=%u user_dir=[%s]\n", uid, user_dir); |
|
21 |
|
|
|
22 |
|
r = nd_load_certs(&certs, uid); |
|
23 |
|
if (r <= 0) |
|
24 |
|
return 1; |
|
25 |
|
for (unsigned int i = 0; i < certs.gl_pathc; i++) { |
|
26 |
|
unsigned char data[4096]; |
|
27 |
|
r = load_dir_file(data, sizeof(data), certs.gl_pathv[i], "data"); |
|
28 |
|
if (r == -1) { |
|
29 |
|
ret = 1; |
|
30 |
|
break; |
|
31 |
|
} |
|
32 |
|
|
|
33 |
|
struct ninedogs_cert cert; |
|
34 |
|
r = nd_bin2struct_cert(&cert, data, r); |
|
35 |
|
if (r == -1) { |
|
36 |
|
ret = 1; |
|
37 |
|
break; |
|
38 |
|
} |
|
39 |
|
|
|
40 |
|
char not_before[32], not_after[32]; |
|
41 |
|
nd_ts_to_str(not_before, sizeof(not_before), cert.not_before); |
|
42 |
|
nd_ts_to_str(not_after, sizeof(not_after), cert.not_after); |
|
43 |
|
fprintf(stdout, " subject=[%s]" |
|
44 |
|
"\n path=[%s]" |
|
45 |
|
"\n issuer=[%s]" |
|
46 |
|
"\n serial=[%s]" |
|
47 |
|
"\n %s -> %s\n", |
|
48 |
|
cert.subj, cert.path, cert.issuer, cert.serial, not_before, not_after); |
|
49 |
|
|
|
50 |
|
glob_t users; |
|
51 |
|
r = nd_load_cert_users(&users, certs.gl_pathv[i]); |
|
52 |
|
if (r == -1) { |
|
53 |
|
ret = 1; |
|
54 |
|
break; |
|
55 |
|
} |
|
56 |
|
fprintf(stdout, " Users:\n"); |
|
57 |
|
for (unsigned j = 0; j < users.gl_pathc; j++) { |
|
58 |
|
unsigned char data[4096]; |
|
59 |
|
int r = load_file(data, sizeof(data), users.gl_pathv[j]); |
|
60 |
|
if (r == -1) { |
|
61 |
|
ret = 1; |
|
62 |
|
break; |
|
63 |
|
} |
|
64 |
|
struct ninedogs_app app; |
|
65 |
|
r = nd_bin2struct_app(&app, data, r); |
|
66 |
|
if (r == -1) { |
|
67 |
|
ret = 1; |
|
68 |
|
break; |
|
69 |
|
} |
|
70 |
|
|
|
71 |
|
char *q = dirname(users.gl_pathv[j]); |
|
72 |
|
char *user_client_id = basename(q); q = dirname(q); |
|
73 |
|
char cmd[4096], sts[64]; |
|
74 |
|
nd_app_nice(cmd, sizeof(cmd), app.cmdline, app.cmdline_len); |
|
75 |
|
nd_ts_to_str(sts, sizeof(sts), app.ts / 1000); |
|
76 |
|
fprintf(stdout, " user_client_id=[%s] last=%s" |
|
77 |
|
"\n cmdline=[%s]\n", |
|
78 |
|
user_client_id, sts, cmd); |
|
79 |
|
} |
|
80 |
|
globfree(&users); |
|
81 |
|
fprintf(stdout, "\n"); |
|
82 |
|
if (ret == 1) |
|
83 |
|
break; |
|
84 |
|
} |
|
85 |
|
globfree(&certs); |
|
86 |
|
|
|
87 |
|
return ret; |
|
88 |
|
} |
|
89 |
|
|
|
90 |
|
int main(void) |
|
91 |
|
{ |
|
92 |
|
return nd_for_each_user(user_cb); |
|
93 |
|
} |
File tools/nd-cert-notify.c changed (mode: 100644) (index 395742f..f8529de) |
... |
... |
static int user_cb(const unsigned int uid, const char *user_dir) |
113 |
113 |
|
|
114 |
114 |
unsigned char data[4096]; |
unsigned char data[4096]; |
115 |
115 |
int r = load_file(data, sizeof(data), users.gl_pathv[j]); |
int r = load_file(data, sizeof(data), users.gl_pathv[j]); |
116 |
|
if (r == -1) |
|
117 |
|
return -1; |
|
|
116 |
|
if (r == -1) { |
|
117 |
|
ret = -1; |
|
118 |
|
break; |
|
119 |
|
} |
118 |
120 |
struct ninedogs_app app; |
struct ninedogs_app app; |
119 |
121 |
r = nd_bin2struct_app(&app, data, r); |
r = nd_bin2struct_app(&app, data, r); |
120 |
122 |
if (r == -1) { |
if (r == -1) { |