-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnss_octopass-group_cli.c
80 lines (67 loc) · 2.03 KB
/
nss_octopass-group_cli.c
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
73
74
75
76
77
78
79
80
/* Management linux user and authentication with the organization/team on Github.
Copyright (C) 2017 Tomohisa Oda
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 3 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/>. */
#include "nss_octopass-group.c"
void show_grent(struct group *grent)
{
printf("%s:%s:%d", grent->gr_name, grent->gr_passwd, grent->gr_gid);
const int count = json_array_size(ent_json_root);
int i;
for (i = 0; i < count; i++) {
printf(":%s", grent->gr_mem[i]);
}
if (count == 0) {
printf(":\n");
} else {
printf("\n");
}
}
void call_getgrnam_r(const char *name)
{
enum nss_status status;
struct group grent;
int err = 0;
int buflen = 2048;
char buf[buflen];
status = _nss_octopass_getgrnam_r(name, &grent, buf, buflen, &err);
if (status == NSS_STATUS_SUCCESS) {
show_grent(&grent);
}
}
void call_getgrgid_r(gid_t gid)
{
enum nss_status status;
struct group grent;
int err = 0;
int buflen = 2048;
char buf[buflen];
status = _nss_octopass_getgrgid_r(gid, &grent, buf, buflen, &err);
if (status == NSS_STATUS_SUCCESS) {
show_grent(&grent);
}
}
void call_grlist(void)
{
enum nss_status status;
struct group grent;
int err = 0;
int buflen = 2048;
char buf[buflen];
status = _nss_octopass_setgrent(0);
while (status == NSS_STATUS_SUCCESS) {
status = _nss_octopass_getgrent_r(&grent, buf, buflen, &err);
if (status == NSS_STATUS_SUCCESS) {
show_grent(&grent);
}
}
status = _nss_octopass_endgrent();
}