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 89 90
|
/*
* Copyright (c) 2014 Balabit
* Copyright (c) 2014 Gergely Nagy <algernon@balabit.hu>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*/
static formatter_map_t group_field_map[] =
{
{ "name", _getent_format_string, offsetof(struct group, gr_name) },
{ "gid", _getent_format_uid_gid, offsetof(struct group, gr_gid) },
{ "members", _getent_format_array_at_location, offsetof(struct group, gr_mem) },
{ NULL, NULL, 0 }
};
static gboolean
tf_getent_group(gchar *key, gchar *member_name, GString *result)
{
struct group grp;
struct group *res;
char *buf;
long bufsize;
int s;
gint64 d;
gboolean is_num, r;
bufsize = 16384;
buf = g_malloc(bufsize);
if ((is_num = parse_int64(key, &d)) == TRUE)
s = getgrgid_r((gid_t)d, &grp, buf, bufsize, &res);
else
s = getgrnam_r(key, &grp, buf, bufsize, &res);
if (res == NULL && s != 0)
{
msg_error("$(getent group) failed",
evt_tag_str("key", key),
evt_tag_error("errno"));
g_free(buf);
return FALSE;
}
if (member_name == NULL)
{
if (is_num)
member_name = "name";
else
member_name = "gid";
}
if (res == NULL)
{
g_free(buf);
return FALSE;
}
s = _find_formatter(group_field_map, member_name);
if (s == -1)
{
msg_error("$(getent group): unknown member",
evt_tag_str("key", key),
evt_tag_str("member", member_name));
g_free(buf);
return FALSE;
}
r = group_field_map[s].format(member_name,
((uint8_t *)res) + group_field_map[s].offset,
result);
g_free(buf);
return r;
}
|