about summary refs log tree commit diff
path: root/src/libs6/s6_accessrules_keycheck_uidgid.c
blob: 5ff9137bc4da45a4cf1c722522b602957065f6f2 (plain) (blame)
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
/* ISC license. */

#include <unistd.h>

#include <skalibs/uint64.h>
#include <skalibs/types.h>
#include <s6/accessrules.h>

s6_accessrules_result_t s6_accessrules_keycheck_uidgid (void const *key, void const *data, s6_accessrules_params_t *params, s6_accessrules_backend_func_ref check1)
{
  uidgid_t const *uidgid = key ;
  char fmt[4 + UINT64_FMT] = "uid/" ;
  s6_accessrules_result_t r ;
  if (uidgid->left == geteuid())
  {
    r = (*check1)("uid/self", 8, data, params) ;
    if (r != S6_ACCESSRULES_NOTFOUND) return r ;
  }
  r = (*check1)(fmt, 4 + uid_fmt(fmt+4, uidgid->left), data, params) ;
  if (r != S6_ACCESSRULES_NOTFOUND) return r ;
  if (uidgid->right == getegid())
  {
    r = (*check1)("gid/self", 8, data, params) ;
    if (r != S6_ACCESSRULES_NOTFOUND) return r ;
  }
  fmt[0] = 'g' ;
  r = (*check1)(fmt, 4 + gid_fmt(fmt+4, uidgid->right), data, params) ;
  if (r != S6_ACCESSRULES_NOTFOUND) return r ;
  return (*check1)("uid/default", 11, data, params) ;
}