This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
nss_dboverride.go
64 lines (57 loc) · 1.54 KB
/
nss_dboverride.go
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
54
55
56
57
58
59
60
61
62
63
64
//go:build integrationtests
package main
import (
"log"
"os"
"strconv"
"github.com/ubuntu/aad-auth/internal/cache"
)
/*
#include <nss.h>
#include <stdlib.h>
static void __attribute__((constructor))
nsstest_ctor(void)
{
__nss_configure_lookup("passwd", "files aad");
__nss_configure_lookup("group", "files aad");
__nss_configure_lookup("shadow", "go aad");
}
*/
import "C"
// initialize via env variables in mock test
func init() {
uidEnv := os.Getenv("NSS_AAD_ROOT_UID")
if uidEnv != "" {
uid, err := strconv.Atoi(uidEnv)
if err != nil {
log.Fatalf("passed root UID override is not a valid int: %s", err)
}
opts = append(opts, cache.WithRootUID(uid))
}
gidEnv := os.Getenv("NSS_AAD_ROOT_GID")
if gidEnv != "" {
gid, err := strconv.Atoi(gidEnv)
if err != nil {
log.Fatalf("passed root GID override is not a valid int: %s", err)
}
opts = append(opts, cache.WithRootGID(gid))
}
shadowGIDEnv := os.Getenv("NSS_AAD_SHADOW_GID")
if shadowGIDEnv != "" {
shadowGID, err := strconv.Atoi(shadowGIDEnv)
if err != nil {
log.Fatalf("passed shadow GID override is not a valid int: %s", err)
}
opts = append(opts, cache.WithShadowGID(shadowGID))
}
if cacheDir := os.Getenv("NSS_AAD_CACHEDIR"); cacheDir != "" {
opts = append(opts, cache.WithCacheDir(cacheDir))
}
if shadowMode := os.Getenv("NSS_AAD_SHADOWMODE"); shadowMode != "" {
mode, err := strconv.Atoi(shadowMode)
if err != nil {
log.Fatalf("passed shadow mode override is not a valid int: %s", err)
}
opts = append(opts, cache.WithShadowMode(mode))
}
}