92 if ((p = getpwnam(username)) ==
nullptr) {
94 fprintf(stderr,
"ERROR: User does not exist '%s'\n", username);
98 if ((g = getgrgid(p->pw_gid)) !=
nullptr) {
99 if ((strcmp(groupname, g->gr_name)) == 0)
116 if ((g = getgrnam(groupname)) ==
nullptr) {
117 fprintf(stderr,
"ERROR: Group does not exist '%s'\n", groupname);
120 while (*(g->gr_mem) !=
nullptr) {
121 if (strcmp(*((g->gr_mem)++), username) == 0) {
132 fprintf(stderr,
"Usage: %s -g group1 [-g group2 ...] [-p] [-s]\n\n",
134 fprintf(stderr,
"-g group\n");
136 " The group name or id that the user must belong in order to\n");
138 " be allowed to authenticate.\n");
140 "-p Verify primary user group as well\n");
142 "-s Strip NT domain from usernames\n");
144 "-r Strip Kerberos realm from usernames\n");
150 char *user, *suser, *p;
152 char **grents =
nullptr;
153 int check_pw = 0, ch, ngroups = 0, i, j = 0, strip_dm = 0, strip_rm = 0;
156 setvbuf(stdout,
nullptr, _IOLBF, 0);
159 while ((ch =
getopt(argc, argv,
"dsrpg:")) != -1) {
174 grents = (
char**)realloc(grents,
sizeof(*grents) * (ngroups+1));
180 fprintf(stderr,
"Unknown option '-%c'.\n",
optopt);
182 fprintf(stderr,
"Unknown option character `\\x%x'.\n",
optopt);
191 fprintf(stderr,
"FATAL: Unknown option '%s'\n", argv[
optind]);
197 if ((p = strchr(buf,
'\n')) ==
nullptr) {
199 fprintf(stderr,
"ERROR: %s: Too large: %s\n", argv[0], buf);
200 while (fgets(buf,
sizeof(buf), stdin)) {
201 fprintf(stderr,
"ERROR: %s: Too large..: %s\n", argv[0], buf);
202 if (strchr(buf,
'\n') !=
nullptr)
209 if ((p = strtok(buf,
" ")) ==
nullptr) {
216 suser = strchr(user,
'\\');
217 if (!suser) suser = strchr(user,
'/');
218 if (suser && suser[1]) user = suser + 1;
221 suser = strchr(user,
'@');
222 if (suser) *suser =
'\0';
225 while ((p = strtok(
nullptr,
" ")) !=
nullptr) {
234 for (i = 0; i < ngroups; ++i) {
#define HELPER_INPUT_BUFFER
int main(int argc, char *argv[])
static int validate_user_gr(char *username, char *groupname)
static void usage(char *program)
static int validate_user_pw(char *username, char *groupname)
int getopt(int nargc, char *const *nargv, const char *ostr)
void rfc1738_unescape(char *url)