From 393832889d46223cbdc8b4b2802826f3339eae7a Mon Sep 17 00:00:00 2001 From: Matthew Ray Date: Fri, 22 May 2020 21:56:56 -0400 Subject: [PATCH] go bindings for username lookup by UID --- Makefile | 8 +++++++- src/functions/getUserByUid.ts | 7 +++++++ src/functions/index.ts | 1 + src/go/getUserByUid/getUserByUid.go | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/functions/getUserByUid.ts create mode 100644 src/go/getUserByUid/getUserByUid.go diff --git a/Makefile b/Makefile index 5553d82..1179bf6 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,9 @@ check_certificate_files := $(wildcard src/go/checkCertificate/*.go) check_certificate_signatures_files := $(wildcard src/go/checkCertSignatures/*.go) storage_files := $(wildcard src/go/storage/*.go) +get_user_by_uid_files := $(wildcard src/go/getUserByUid/*.go) -all: check_certificate check_cert_signatures storage typescript +all: check_certificate check_cert_signatures storage getUserByUid typescript check_certificate: HOME=/root go build -ldflags="-s -w" -o dist/bin/checkCertificate ${check_certificate_files} @@ -21,5 +22,10 @@ storage: @chmod 740 dist/bin/storage file dist/bin/storage +getUserByUid: + HOME=/root go build -ldflags="-s -w" dist/bin/getUserByUid ${storage_files} + @chmod 740 dist/bin/getUserByUid + file dist/bin/getUserByUid + typescript: tsc -p ./tsconfig.json diff --git a/src/functions/getUserByUid.ts b/src/functions/getUserByUid.ts new file mode 100644 index 0000000..b56c148 --- /dev/null +++ b/src/functions/getUserByUid.ts @@ -0,0 +1,7 @@ +import { Client } from '..'; + +export default async function getUserByUid(client: Client, uid: number): Promise { + const res = await client.util.exec(`${__dirname}/../bin/getUserByUid ${uid}`); + if (res === '-1') return null; + return res.trim(); +} diff --git a/src/functions/index.ts b/src/functions/index.ts index b933c35..6abf234 100644 --- a/src/functions/index.ts +++ b/src/functions/index.ts @@ -1,5 +1,6 @@ export { default as checkLock, clear as clearLock } from '../intervals/checkLock'; export { default as dataConversion } from './dataConversion'; export { default as existingLimitsSetup } from './existingLimitsSetup'; +export { default as getUserByUid } from './getUserByUid'; // export { default as checkSS, clear as clearSS } from './checkSS'; export { default as parseCertificate, Certificate } from './parseCertificate'; diff --git a/src/go/getUserByUid/getUserByUid.go b/src/go/getUserByUid/getUserByUid.go new file mode 100644 index 0000000..1a64881 --- /dev/null +++ b/src/go/getUserByUid/getUserByUid.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "os" + "os/user" +) + +func main() { + if len(os.Args) > 1 { + fmt.Println("-1") + os.Exit(0) + } + userInfo, err := user.LookupId(os.Args[1]) + if err != nil { + fmt.Println("-1") + os.Exit(0) + } + fmt.Printf("%s", userInfo.Username) + os.Exit(0) +}