1#define _POSIX_C_SOURCE 200809L2#include <stdio.h>3#include <stdlib.h>4#include <security/pam_appl.h>5#include "pam.h"67/*8I really doubt it is a good idea to bring Go to the binary whose primary task9is to call libpam using CGo anyway.10*/1112int run(void) {13 char *username = NULL, *password = NULL;14 size_t username_buf_len = 0, password_buf_len = 0;1516 ssize_t username_len = getline(&username, &username_buf_len, stdin);17 if (username_len < 0) {18 perror("getline username");19 return 2;20 }2122 ssize_t password_len = getline(&password, &password_buf_len, stdin);23 if (password_len < 0) {24 perror("getline password");25 return 2;26 }2728 // Cut trailing \n.29 if (username_len > 0) {30 username[username_len - 1] = 0;31 }32 if (password_len > 0) {33 password[password_len - 1] = 0;34 }3536 struct error_obj err = run_pam_auth(username, password);37 if (err.status != 0) {38 if (err.status == 2) {39 fprintf(stderr, "%s: %s\n", err.func_name, err.error_msg);40 }41 return err.status;42 }4344 return 0;45}4647#ifndef CGO48int main() {49 return run();50}51#endif