File: usrgrp.h

package info (click to toggle)
xchpst 0.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 304 kB
  • sloc: ansic: 2,792; sh: 75; makefile: 47
file content (53 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* SPDX-License-Identifier: MIT */
/* SPDX-FileCopyrightText: (c) Copyright 2024 Andrew Bower <andrew@bower.uk> */

#ifndef _USRGRP_H
#define _USRGRP_H

#include <stdbool.h>

enum tok_type {
  TOK_NONE = 0,
  TOK_NAME,
  TOK_ID,
};

struct sys_entry {
  char *tok;
  union {
    struct {
      uid_t uid;
      gid_t user_gid;
    };
    gid_t gid;
  };
  enum tok_type tok_type;
  bool resolved;
};

struct users_groups {
  struct sys_entry user;
  struct sys_entry group;
  struct sys_entry *supplemental;
  ssize_t num_supplemental;

  /* Buffers to be freed */
  void *buf_tok;
  char *username;
  char *home;
  char *shell;
};

static inline bool usrgrp_specified(const struct sys_entry *entry) {
  return entry->tok_type != TOK_NONE;
}

int usrgrp_parse(struct users_groups *ug, const char *arg);
int usrgrp_resolve(struct users_groups *ug);
void usrgrp_resolve_uid(struct users_groups *ug, uid_t nid, bool lookup);
void usrgrp_print(FILE *out, const char *what, struct users_groups *ug);
void usrgrp_free(struct users_groups *ug);
int usrgrp_from_env(struct users_groups *ug,
                    const char *uid, const char *gid, const char *gidlist);

#endif