abi_linux.go RawHistoryFolder
1//go:build linux && (amd64 || arm64)
2
3package pam
4
5import "unsafe"
6
7// Status is a Linux-PAM C int. Only Success indicates success.
8type Status int32
9
10// Linux-PAM statuses from security/_pam_types.h.
11const (
12 Success Status = iota
13 OpenErr
14 SymbolErr
15 ServiceErr
16 SystemErr
17 BufErr
18 PermDenied
19 AuthErr
20 CredInsufficient
21 AuthinfoUnavail
22 UserUnknown
23 Maxtries
24 NewAuthtokReqd
25 AcctExpired
26 SessionErr
27 CredUnavail
28 CredExpired
29 CredErr
30 NoModuleData
31 ConvErr
32 AuthtokErr
33 AuthtokRecoveryErr
34 AuthtokLockBusy
35 AuthtokDisableAging
36 TryAgain
37 Ignore
38 Abort
39 AuthtokExpired
40 ModuleUnknown
41 BadItem
42 ConvAgain
43 Incomplete
44)
45
46// Flags is a Linux-PAM C int.
47type Flags int32
48
49const (
50 Silent Flags = 0x8000
51 DisallowNullAuthtok Flags = 0x0001
52 PromptEchoOff int32 = 1
53 PromptEchoOn int32 = 2
54 ErrorMsg int32 = 3
55 TextInfo int32 = 4
56 MaxNumMsg = 32
57 MaxMsgSize = 512
58 MaxRespSize = 512
59)
60
61// NativeConversation describes a caller-owned C conversation function and native
62// application data. Function must implement:
63// int conv(int, const struct pam_message **, struct pam_response **, void *).
64// Data must be nil or libc-owned memory, NEVER a Go pointer. Function and Data
65// must remain valid through End, including pam_end's cleanup callbacks.
66// This low-level contract is unsafe by design; use StartConversation for the
67// managed bridge instead.
68type NativeConversation struct {
69 Function uintptr
70 Data unsafe.Pointer
71}
72
73// Native Linux LP64 layouts; C int is 32 bits and pointers are 64 bits.
74type nativeMessage struct {
75 Style int32
76 _ [4]byte
77 Text unsafe.Pointer
78}
79
80type nativeResponse struct {
81 Text unsafe.Pointer
82 ReturnCode int32
83 _ [4]byte
84}
85
86type nativeConversation struct {
87 Function uintptr
88 Data unsafe.Pointer
89}
90
91// nativeCookieConversation has the same C layout, but treats appdata as an
92// opaque integer value, never as an address or a Go unsafe.Pointer.
93type nativeCookieConversation struct {
94 Function uintptr
95 Cookie uintptr
96}
97
98// Both supported ABIs require these sizes, offsets and alignments. A mismatch
99// fails compilation, including on the arm64 cross-build without a native host.
100var (
101 _ [16 - unsafe.Sizeof(nativeCookieConversation{})]byte
102 _ [unsafe.Sizeof(nativeCookieConversation{}) - 16]byte
103 _ [8 - unsafe.Offsetof(nativeCookieConversation{}.Cookie)]byte
104 _ [unsafe.Offsetof(nativeCookieConversation{}.Cookie) - 8]byte
105 _ [16 - unsafe.Sizeof(nativeMessage{})]byte
106 _ [unsafe.Sizeof(nativeMessage{}) - 16]byte
107 _ [16 - unsafe.Sizeof(nativeResponse{})]byte
108 _ [unsafe.Sizeof(nativeResponse{}) - 16]byte
109 _ [16 - unsafe.Sizeof(nativeConversation{})]byte
110 _ [unsafe.Sizeof(nativeConversation{}) - 16]byte
111 _ [8 - unsafe.Offsetof(nativeMessage{}.Text)]byte
112 _ [unsafe.Offsetof(nativeMessage{}.Text) - 8]byte
113 _ [8 - unsafe.Offsetof(nativeResponse{}.ReturnCode)]byte
114 _ [unsafe.Offsetof(nativeResponse{}.ReturnCode) - 8]byte
115 _ [8 - unsafe.Offsetof(nativeConversation{}.Data)]byte
116 _ [unsafe.Offsetof(nativeConversation{}.Data) - 8]byte
117 _ [8 - unsafe.Alignof(nativeMessage{})]byte
118 _ [unsafe.Alignof(nativeMessage{}) - 8]byte
119 _ [8 - unsafe.Alignof(nativeResponse{})]byte
120 _ [unsafe.Alignof(nativeResponse{}) - 8]byte
121 _ [8 - unsafe.Alignof(nativeConversation{})]byte
122 _ [unsafe.Alignof(nativeConversation{}) - 8]byte
123)