Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit 17eaab6

Browse files
author
Tuxx
committed
Using our own pam file now, so we do not get faillock lockouts.
[auto] go fmt applied to staged files
1 parent cf2031f commit 17eaab6

File tree

5 files changed

+64
-65
lines changed

5 files changed

+64
-65
lines changed

Makefile

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ INSTALL_PATH := /usr/local/bin
88
GIT_COMMIT := $(shell git rev-parse --short HEAD)
99
BUILD_DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
1010
VERSION := $(shell git describe --tags --always --dirty)
11+
TAG_VERSION := $(shell git describe --tags --abbrev=0 | sed 's/^v//')
1112

1213
# ldflags for embedding version info
1314
LDFLAGS := -ldflags="-s -w \
1415
-X github.com/tuxx/fancylock/internal.Version=$(VERSION) \
1516
-X github.com/tuxx/fancylock/internal.Commit=$(GIT_COMMIT) \
1617
-X github.com/tuxx/fancylock/internal.BuildDate=$(BUILD_DATE)"
1718

18-
.PHONY: all clean native package install check-go $(ARCHES)
19+
.PHONY: all clean native install check-go $(ARCHES) package aur
1920

2021
all: check-go $(ARCHES)
2122

@@ -26,46 +27,34 @@ $(DIST):
2627
mkdir -p $(DIST)
2728

2829
check-go:
29-
@command -v go >/dev/null 2>&1 || { echo >&2 "Go is not installed. Please install Go before continuing."; exit 1; }
30+
@command -v go >/dev/null 2>&1 || { echo >&2 "Go is not installed."; exit 1; }
3031

3132
$(ARCHES): | $(BIN)
32-
GOOS=linux GOARCH=$@ CGO_ENABLED=1 go build $(LDFLAGS) -o $(BIN)/$(APP)-linux-$@ main.go
33+
GOOS=linux GOARCH=$@ CGO_ENABLED=1 go build $(LDFLAGS) -o "$(BIN)/$(APP)-linux-$@" main.go
3334

3435
native: check-go | $(BIN)
35-
CGO_ENABLED=1 go build $(LDFLAGS) -o $(BIN)/$(APP)-native main.go
36+
CGO_ENABLED=1 go build $(LDFLAGS) -o "$(BIN)/$(APP)-native" main.go
3637

37-
package: | $(DIST)
38+
package: all | $(DIST)
3839
@for arch in $(ARCHES); do \
39-
if [ -f $(BIN)/$(APP)-linux-$$arch ]; then \
40-
tar -czvf $(DIST)/$(APP)-linux-$$arch.tar.gz -C $(BIN) $(APP)-linux-$$arch; \
41-
fi \
40+
[ -f "$(BIN)/$(APP)-linux-$$arch" ] && \
41+
tar -czvf "$(DIST)/$(APP)-linux-$$arch.tar.gz" -C "$(BIN)" "$(APP)-linux-$$arch"; \
4242
done
43-
@if [ -f $(BIN)/$(APP)-native ]; then \
44-
tar -czvf $(DIST)/$(APP)-native.tar.gz -C $(BIN) $(APP)-native; \
43+
@if [ -f "$(BIN)/$(APP)-native" ]; then \
44+
tar -czvf "$(DIST)/$(APP)-native.tar.gz" -C "$(BIN)" "$(APP)-native"; \
4545
fi
46+
cp "$(BIN)/$(APP)-linux-amd64" "$(DIST)/"
47+
tar -C "$(DIST)" -czf "$(DIST)/$(APP)-linux-amd64.tar.gz" "$(APP)-linux-amd64"
4648

4749
install: native
48-
@install -Dm755 $(BIN)/$(APP)-native $(INSTALL_PATH)/$(APP)
50+
@install -Dm755 "$(BIN)/$(APP)-native" "$(INSTALL_PATH)/$(APP)"
4951
@echo "Installed $(APP)-native to $(INSTALL_PATH)/$(APP)"
50-
51-
clean:
52-
rm -rf $(BIN) $(DIST)
53-
54-
BINARY=fancylock-linux-amd64
55-
DIST_DIR=dist
56-
TAG_VERSION=$(shell git describe --tags --abbrev=0 | sed 's/^v//')
57-
58-
amd64:
59-
mkdir -p bin
60-
GOARCH=amd64 GOOS=linux go build -o bin/$(BINARY) -ldflags="-X 'github.com/tuxx/fancylock/internal.Version=$(TAG_VERSION)'"
61-
62-
package: amd64
63-
mkdir -p $(DIST_DIR)
64-
cp bin/$(BINARY) $(DIST_DIR)/
65-
tar -C $(DIST_DIR) -czf $(DIST_DIR)/$(BINARY).tar.gz $(BINARY)
52+
@install -Dm644 "pam.d/fancylock" "/etc/pam.d/fancylock"
6653

6754
aur: package
6855
mkdir -p packages/aur/fancylock-bin
6956
sed "s/@VERSION@/$(TAG_VERSION)/g" packages/aur/fancylock-bin/PKGBUILD.template > packages/aur/fancylock-bin/PKGBUILD
7057
sed "s/@VERSION@/$(TAG_VERSION)/g" packages/aur/fancylock-bin/.SRCINFO.template > packages/aur/fancylock-bin/.SRCINFO
7158

59+
clean:
60+
rm -rf $(BIN) $(DIST)

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ tar -xzvf fancylock.tar.gz
3434
# Make it executable
3535
chmod +x fancylock-linux-amd64
3636

37+
# Add a pam.d file for fancylock:
38+
sudo curl -L -o /etc/pam.d/fancylock https://raw.githubusercontent.com/tuxx/fancylock/refs/heads/master/pam.d/fancylock
39+
3740
# Optional: install system-wide
3841
sudo mv fancylock-linux-amd64 /usr/local/bin/fancylock
3942

@@ -46,7 +49,7 @@ cat > ~/.config/fancylock/config.json << 'EOF'
4649
"media_dir": "$HOME/Videos",
4750
"lock_screen": false,
4851
"supported_extensions": [".mp4", ".mkv", ".mov", ".avi", ".webm"],
49-
"pam_service": "system-auth",
52+
"pam_service": "fancylock",
5053
"include_images": true,
5154
"image_display_time": 30,
5255
"background_color": "#000000",
@@ -181,7 +184,7 @@ fancylock -c /path/to/config.json
181184
"media_dir": "/home/user/Videos",
182185
"lock_screen": false,
183186
"supported_extensions": [".mp4", ".mkv", ".mov", ".avi", ".webm"],
184-
"pam_service": "system-auth",
187+
"pam_service": "fancylock",
185188
"include_images": true,
186189
"image_display_time": 30,
187190
"background_color": "#000000",

internal/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ func DefaultConfig() Configuration {
1414
homeDir = "/tmp"
1515
}
1616

17+
pamPath := "/etc/pam.d/fancylock"
18+
PamService := "system-auth"
19+
if _, err := os.Stat(pamPath); err == nil {
20+
PamService = "fancylock"
21+
}
22+
1723
return Configuration{
1824
MediaDir: filepath.Join(homeDir, "Videos"),
1925
LockScreen: false,
2026
SupportedExt: []string{".mov", ".mkv", ".mp4", ".avi", ".webm"},
2127
IdleTimeout: 300, // 5 minutes
22-
PamService: "system-auth",
28+
PamService: PamService,
2329
IncludeImages: true,
2430
ImageDisplayTime: 30,
2531
BackgroundColor: "#000000",

internal/lock.go

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"os/user"
9+
"strings"
910
"syscall"
1011

1112
"github.com/msteinert/pam"
@@ -20,14 +21,8 @@ func NewPamAuthenticator(config Configuration) *PamAuthenticator {
2021
username = currentUser.Username
2122
}
2223

23-
// Use default PAM service from config
24-
serviceName := config.PamService
25-
if serviceName == "" {
26-
serviceName = "system-auth"
27-
}
28-
2924
return &PamAuthenticator{
30-
serviceName: serviceName,
25+
serviceName: config.PamService,
3126
username: username,
3227
}
3328
}
@@ -92,52 +87,40 @@ func (a *PamAuthenticator) Authenticate(password string) AuthResult {
9287
}
9388
}
9489

95-
// LockHelper provides common functionality for screen lockers
9690
type LockHelper struct {
97-
config Configuration
9891
authenticator *PamAuthenticator
92+
config Configuration
9993
}
10094

101-
// NewLockHelper creates a new lock helper
95+
// NewLockHelper creates a new helper instance with the given configuration
10296
func NewLockHelper(config Configuration) *LockHelper {
97+
auth := &PamAuthenticator{
98+
serviceName: config.PamService,
99+
username: os.Getenv("USER"),
100+
}
101+
103102
return &LockHelper{
103+
authenticator: auth,
104104
config: config,
105-
authenticator: NewPamAuthenticator(config),
106105
}
107106
}
108107

109-
// RunPreLockCommand executes the configured pre-lock command
108+
// RunPreLockCommand runs the configured pre-lock command (if any)
110109
func (h *LockHelper) RunPreLockCommand() error {
111110
if h.config.PreLockCommand == "" {
112-
return nil // No command to run
113-
}
114-
115-
Info("Running pre-lock command: %s", h.config.PreLockCommand)
116-
output, err := h.RunCommand("sh", "-c", h.config.PreLockCommand)
117-
if err != nil {
118-
Error("Pre-lock command failed: %v - %s", err, output)
119-
return fmt.Errorf("pre-lock command failed: %v", err)
111+
return nil
120112
}
121-
122-
Debug("Pre-lock command output: %s", output)
123-
return nil
113+
Debug("Running pre-lock command: %s", h.config.PreLockCommand)
114+
return runShellCommand(h.config.PreLockCommand)
124115
}
125116

126-
// RunPostLockCommand executes the configured post-lock command
117+
// RunPostLockCommand runs the configured post-lock command (if any)
127118
func (h *LockHelper) RunPostLockCommand() error {
128119
if h.config.PostLockCommand == "" {
129-
return nil // No command to run
130-
}
131-
132-
Info("Running post-lock command: %s", h.config.PostLockCommand)
133-
output, err := h.RunCommand("sh", "-c", h.config.PostLockCommand)
134-
if err != nil {
135-
Error("Post-lock command failed: %v - %s", err, output)
136-
return fmt.Errorf("post-lock command failed: %v", err)
120+
return nil
137121
}
138-
139-
Debug("Post-lock command output: %s", output)
140-
return nil
122+
Debug("Running post-lock command: %s", h.config.PostLockCommand)
123+
return runShellCommand(h.config.PostLockCommand)
141124
}
142125

143126
// CheckUserPermissions verifies that the user has the necessary permissions
@@ -278,3 +261,8 @@ func (p *SecurePassword) Length() int {
278261
defer p.mu.Unlock()
279262
return len(p.data)
280263
}
264+
265+
// runShellCommand executes a shell command string
266+
func runShellCommand(cmd string) error {
267+
return exec.Command("sh", "-c", strings.TrimSpace(cmd)).Run()
268+
}

packages/aur/fancylock-bin/PKGBUILD.template

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,17 @@ sha256sums=('SKIP')
1313

1414
package() {
1515
install -Dm755 fancylock-linux-amd64 "$pkgdir/usr/bin/fancylock"
16+
if [ ! -f /etc/pam.d/fancylock ]; then
17+
install -d "$pkgdir/etc/pam.d"
18+
cat > "$pkgdir/etc/pam.d/fancylock" <<EOF
19+
#%PAM-1.0
20+
# /etc/pam.d/fancylock - PAM configuration for fancylock screen locker
21+
auth required pam_env.so
22+
auth required pam_unix.so try_first_pass
23+
account required pam_nologin.so
24+
account required pam_unix.so
25+
session required pam_limits.so
26+
session required pam_unix.so
27+
EOF
28+
fi
1629
}

0 commit comments

Comments
 (0)