mirror of
https://github.com/boltgolt/howdy.git
synced 2024-09-19 09:51:19 +02:00
refactor: inline send_message
This commit is contained in:
parent
27287bc03c
commit
073aea4816
1 changed files with 10 additions and 22 deletions
|
@ -129,25 +129,6 @@ auto howdy_msg(char *username, int status, INIReader &reader,
|
||||||
return PAM_SUCCESS;
|
return PAM_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Format and send a message to PAM
|
|
||||||
* @param conv PAM conversation function
|
|
||||||
* @param type Type of PAM message
|
|
||||||
* @param message String to show the user
|
|
||||||
* @return Returns the conversation function return code
|
|
||||||
*/
|
|
||||||
auto send_message(struct pam_conv *conv, int type, const char *message) -> int {
|
|
||||||
// No need to free this, it's allocated on the stack
|
|
||||||
const struct pam_message msg = {.msg_style = type, .msg = message};
|
|
||||||
const struct pam_message *msgp = &msg;
|
|
||||||
|
|
||||||
struct pam_response res = {};
|
|
||||||
struct pam_response *resp = &res;
|
|
||||||
|
|
||||||
// Call the conversation function with the constructed arguments
|
|
||||||
return conv->conv(1, &msgp, &resp, conv->appdata_ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main function, runs the identification and authentication
|
* The main function, runs the identification and authentication
|
||||||
* @param pamh The handle to interface directly with PAM
|
* @param pamh The handle to interface directly with PAM
|
||||||
|
@ -185,9 +166,16 @@ auto identify(pam_handle_t *pamh, int flags, int argc, const char **argv,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap the PAM conversation function in our own, easier function
|
// Wrap the PAM conversation function in our own, easier function
|
||||||
auto conv_function = [conv](int msg_type, const char *msg) {
|
auto conv_function = [conv](int msg_type, const char *msg_str) {
|
||||||
return send_message(conv, std::forward<decltype(msg_type)>(msg_type),
|
// No need to free this, it's allocated on the stack
|
||||||
std::forward<decltype(msg)>(msg));
|
const struct pam_message msg = {.msg_style = msg_type, .msg = msg_str};
|
||||||
|
const struct pam_message *msgp = &msg;
|
||||||
|
|
||||||
|
struct pam_response res = {};
|
||||||
|
struct pam_response *resp = &res;
|
||||||
|
|
||||||
|
// Call the conversation function with the constructed arguments
|
||||||
|
return conv->conv(1, &msgp, &resp, conv->appdata_ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Error out if we could not ready the config file
|
// Error out if we could not ready the config file
|
||||||
|
|
Loading…
Reference in a new issue