This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dogroup.c
88 lines (74 loc) · 1.96 KB
/
dogroup.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
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <nss.h>
#include <grp.h>
static int group_index = 0;
void
start_group_index ()
{
group_index = 0;
}
void
increment_group_index ()
{
group_index += 1;
}
int
get_group_index ()
{
return group_index;
}
enum nss_status
do_group (char *content, char *name, struct group *result_buf,
char *buf, size_t buflen, int *errnop, int *_)
{
char *gr_name = strsep (&content, ":");
char *gr_gid = strsep (&content, ":");
char *gr_passwd = strsep (&content,":");
syslog (LOG_NOTICE, "content [%s] name %s gid %d password %s", content, gr_name, atoi (gr_gid), gr_passwd);
memset (buf, 0, buflen);
result_buf->gr_name = strcpy (buf, gr_name);
result_buf->gr_gid = atoi (gr_gid);
result_buf->gr_passwd = strcpy (buf + strlen (gr_name) + 1, gr_passwd);
char *start_mem = (buf + strlen (gr_name) + strlen(gr_passwd) + 2);
char **members;
char *member;
size_t lengths= 0;
int member_count = 0;
size_t member_size = 0;
size_t strings_offset = 0;
//for count member
char *copy_content = strdup (content);
member = strsep (&content, ",");
if(member == NULL)
{
result_buf->gr_mem = (char **)(uintptr_t)start_mem;
}
else
{
//count members
while(strsep (©_content, ",") != NULL)
{
member_size += 1;
}
free (copy_content);
strings_offset = (member_size + 1) * sizeof(char *);
members = (char**) start_mem ;
members[0] = start_mem + strings_offset;
strcpy (members[0], member);
lengths = strlen (member);
member_count += 1;
while((member = strsep (&content, ",")) != NULL)
{
members[member_count] = members[member_count - 1] + lengths + strlen (member) + 1;
strcpy (members[member_count], member);
member_count += 1;
}
members[member_count] = NULL;
result_buf->gr_mem = (char **)(uintptr_t)start_mem;
}
free(copy_content);
return NSS_STATUS_SUCCESS;
}