2 * Copyright (c) 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
30 #endif /* STDC_HEADERS */
34 # include "compat/stdbool.h"
35 #endif /* HAVE_STDBOOL_H */
37 # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
41 #endif /* HAVE_STRING_H */
44 #endif /* HAVE_STRINGS_H */
47 #endif /* HAVE_UNISTD_H */
55 #include "sudo_plugin.h"
59 * Sample sudoers group plugin that uses an extra group file with the
60 * same format as /etc/group.
63 static sudo_printf_t sudo_log;
65 extern void mysetgrfile(const char *);
66 extern void mysetgrent(void);
67 extern void myendgrent(void);
68 extern struct group *mygetgrnam(const char *);
71 sample_init(int version, sudo_printf_t sudo_printf, char *const argv[])
75 sudo_log = sudo_printf;
77 if (GROUP_API_VERSION_GET_MAJOR(version) != GROUP_API_VERSION_MAJOR) {
78 sudo_log(SUDO_CONV_ERROR_MSG,
79 "group_file: incompatible major version %d, expected %d\n",
80 GROUP_API_VERSION_GET_MAJOR(version),
81 GROUP_API_VERSION_MAJOR);
85 /* Sanity check the specified group file. */
86 if (argv == NULL || argv[0] == NULL) {
87 sudo_log(SUDO_CONV_ERROR_MSG,
88 "group_file: path to group file not specified\n");
91 if (stat(argv[0], &sb) != 0) {
92 sudo_log(SUDO_CONV_ERROR_MSG,
93 "group_file: %s: %s\n", argv[0], strerror(errno));
96 if ((sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
97 sudo_log(SUDO_CONV_ERROR_MSG,
98 "%s must be only be writable by owner\n", argv[0]);
102 mysetgrfile(argv[0]);
115 * Returns true if "user" is a member of "group", else false.
118 sample_query(const char *user, const char *group, const struct passwd *pwd)
123 grp = mygetgrnam(group);
125 for (member = grp->gr_mem; *member != NULL; member++) {
126 if (strcasecmp(user, *member) == 0)
134 __dso_public struct sudoers_group_plugin group_plugin = {