-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuavoadmins-ssh-authorized-keys.c
More file actions
72 lines (60 loc) · 2.26 KB
/
puavoadmins-ssh-authorized-keys.c
File metadata and controls
72 lines (60 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* puavoadmins
* Copyright (C) 2014, 2015 Opinsys
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Standard libarary includes. */
#include <stdio.h>
#include <string.h>
/* Local includes. */
#include "orgjson.h"
int main(const int argc, const char *const *const argv)
{
orgjson_t *orgjson;
struct orgjson_error error;
int retval;
if (argc != 2) {
fprintf(stderr, "ERROR: invalid number of arguments, "
"expetected 1, got %d\n", argc - 1);
return 1;
}
orgjson = orgjson_load(&error);
if (!orgjson) {
fprintf(stderr, "ERROR: failed to load puavoadmin database: %s\n",
error.text);
return 1;
}
for (size_t i = 0; i < orgjson_get_owner_count(orgjson); ++i) {
struct orgjson_owner owner;
if (!orgjson_get_owner(orgjson, i, &owner, &error)) {
fprintf(stderr, "ERROR: failed to get entry from "
"puavoadmin database by id %zd: %s\n",
i, error.text);
retval = 1;
goto out;
}
if (!strcmp(owner.username, argv[1])) {
if (owner.ssh_public_key)
printf("%s\n", owner.ssh_public_key);
retval = 0;
goto out;
}
}
fprintf(stderr, "ERROR: Puavo administrator '%s' not found\n", argv[1]);
retval = 1;
out:
orgjson_free(orgjson);
orgjson = NULL;
return retval;
}