summaryrefslogtreecommitdiffstats
path: root/lib/libutil/login_progok.c
blob: 6ef2cf44c1aec7c871b0bd97b7ad5adf71a0f6b8 (plain)
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
#include <sys/types.h>
#include <login_cap.h>
#include <pwd.h>
#include <string.h>

int
login_progok(uid_t uid, const char *prog)
{
  login_cap_t *lc;
  const struct passwd *pwd;
  char **data;

  pwd = getpwuid(uid);
  if (!pwd)
    return 0;			/* How did that happen ? - we can't run */

  lc = login_getpwclass(pwd);
  if (!lc)
    return 1;			/* We're missing login.conf ? - we can run */

  data = login_getcaplist(lc, "prog.allow", NULL);
  if (data) 
    for (; *data; data++)
      if (!strcmp(*data, prog)) {
        login_close(lc);
	return 1;		/* We're in prog.allow - we can run */
      }

  data = login_getcaplist(lc, "prog.deny", NULL);
  if (data) 
    for (; *data; data++)
      if (!strcmp(*data, prog)) {
        login_close(lc);
	return 0;		/* We're in prog.deny - we can't run */
      }

  login_close(lc);
  return 1;			/* We're not mentioned anywhere - we can run */
}
OpenPOWER on IntegriCloud