Some checks failed
Build Module / Build Module (push) Failing after 2m6s
feat: use gnu-gcc for cross compile arm Reviewed-on: #28 Co-authored-by: GregoryDosh <authentik@gregorydosh.com> Co-committed-by: GregoryDosh <authentik@gregorydosh.com>
87 lines
2.3 KiB
Go
87 lines
2.3 KiB
Go
//go:build darwin || linux
|
|
// +build darwin linux
|
|
|
|
/*
|
|
Copyright (c) 2017 Uber Technologies, Inc.
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
|
|
SPDX-License-Identifier: LicenseRef-Uber
|
|
*/
|
|
|
|
package main
|
|
|
|
// code in here can't be tested because it relies on cgo. :(
|
|
|
|
import (
|
|
"os"
|
|
"unsafe"
|
|
)
|
|
|
|
/*
|
|
#cgo LDFLAGS:-fPIC
|
|
#include <security/pam_appl.h>
|
|
#include <stdlib.h>
|
|
|
|
char *string_from_argv(int, char**);
|
|
char *get_user(pam_handle_t *pamh);
|
|
int get_uid(char *user);
|
|
*/
|
|
import "C"
|
|
|
|
func init() {
|
|
if !disablePtrace() {
|
|
pamLog("unable to disable ptrace")
|
|
}
|
|
}
|
|
|
|
func sliceFromArgv(argc C.int, argv **C.char) []string {
|
|
r := make([]string, 0, argc)
|
|
for i := 0; i < int(argc); i++ {
|
|
s := C.string_from_argv(C.int(i), argv)
|
|
defer C.free(unsafe.Pointer(s))
|
|
r = append(r, C.GoString(s))
|
|
}
|
|
return r
|
|
}
|
|
|
|
//export pam_sm_authenticate
|
|
func pam_sm_authenticate(pamh *C.pam_handle_t, flags, argc C.int, argv **C.char) C.int {
|
|
cUsername := C.get_user(pamh)
|
|
if cUsername == nil {
|
|
return C.PAM_USER_UNKNOWN
|
|
}
|
|
defer C.free(unsafe.Pointer(cUsername))
|
|
|
|
uid := int(C.get_uid(cUsername))
|
|
if uid < 0 {
|
|
return C.PAM_USER_UNKNOWN
|
|
}
|
|
|
|
r := pamAuthenticate(os.Stderr, uid, C.GoString(cUsername), sliceFromArgv(argc, argv))
|
|
if r == AuthError {
|
|
return C.PAM_AUTH_ERR
|
|
}
|
|
return C.PAM_SUCCESS
|
|
}
|
|
|
|
//export pam_sm_setcred
|
|
func pam_sm_setcred(pamh *C.pam_handle_t, flags, argc C.int, argv **C.char) C.int {
|
|
return C.PAM_IGNORE
|
|
}
|