2 * Copyright (c) 2010 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>
20 #include <sys/param.h>
31 #endif /* STDC_HEADERS */
33 # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
37 #endif /* HAVE_STRING_H */
40 #endif /* HAVE_STRINGS_H */
43 #endif /* HAVE_UNISTD_H */
51 #include "sudo_plugin.h"
55 * Sample sudoers group plugin that uses an extra group file with the
56 * same format as /etc/group.
66 static sudo_printf_t sudo_log;
68 extern void mysetgrfile(const char *);
69 extern void mysetgrent(void);
70 extern void myendgrent(void);
71 extern struct group *mygetgrnam(const char *);
74 sample_init(int version, sudo_printf_t sudo_printf, char *const argv[])
78 sudo_log = sudo_printf;
80 if (GROUP_API_VERSION_GET_MAJOR(version) != GROUP_API_VERSION_MAJOR) {
81 sudo_log(SUDO_CONV_ERROR_MSG,
82 "sample_group: incompatible major version %d, expected %d\n",
83 GROUP_API_VERSION_GET_MAJOR(version),
84 GROUP_API_VERSION_MAJOR);
88 /* Sanity check the specified group file. */
89 if (argv == NULL || argv[0] == NULL) {
90 sudo_log(SUDO_CONV_ERROR_MSG,
91 "sample_group: path to group file not specified\n");
94 if (stat(argv[0], &sb) != 0) {
95 sudo_log(SUDO_CONV_ERROR_MSG,
96 "sample_group: %s: %s\n", argv[0], strerror(errno));
99 if ((sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
100 sudo_log(SUDO_CONV_ERROR_MSG,
101 "%s must be only be writable by owner\n", argv[0]);
105 mysetgrfile(argv[0]);
118 * Returns TRUE if "user" is a member of "group", else FALSE.
121 sample_query(const char *user, const char *group, const struct passwd *pwd)
126 grp = mygetgrnam(group);
128 for (member = grp->gr_mem; *member != NULL; member++) {
129 if (strcasecmp(user, *member) == 0)
137 struct sudoers_group_plugin group_plugin = {