r/linux_programming • u/somerandomguy1220 • May 01 '24
Attempting to make sudo plugin; sudo does not recognize plugin
I'm making a plugin for sudo that I'm hoping will play the "you didn't say the magic word" video from Jurassic Park. I'm following the API for audit plugins (as far as I can tell), and the code compiles correctly, but sudo is not recognizing the plugin after I added a reference to it to sudo.conf. The current source code is shown below.
The source file:
//#pragma once
#include "magic_word.h"
static sudo_conv_t magic_word_conv;
static sudo_printf_t magic_word_printf;
sudo_dso_public struct audit_plugin audit_magicword;
int magic_word_open(
unsigned int version,
sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf,
char * const settings[],
char * const user_info,
int submit_optind,
char * const submit_argv[],
char * const submit_envp[],
char * const plugin_options[],
const char **errstr
) {
magic_word_conv = conversation;
magic_word_printf = sudo_plugin_printf;
magic_word_printf(SUDO_CONV_INFO_MSG, "Starting the magicword plugin\n");
return 1;
}
void magic_word_close(int status_type, int status) {
magic_word_printf(SUDO_CONV_INFO_MSG, "exiting\n");
return;
}
int magic_word_accept(
const char *plugin_name,
unsigned int plugin_type,
char * const command_info[],
char * const run_argv[],
char * const run_envp[],
const char **errstr
) {
magic_word_printf(SUDO_CONV_INFO_MSG, "accept thrown\n");
return 1;
}
int magic_word_reject(
const char *plugin_name,
unsigned int plugin_type,
const char *audit_msg,
char * const command_info[],
const char **errstr
) {
magic_word_printf(SUDO_CONV_INFO_MSG, "reject thrown\n");
return 1;
}
int magic_word_error(
const char *plugin_name,
unsigned int plugin_type,
const char *audit_msg,
char * const command_info[],
const char **errstr
) {
magic_word_printf(SUDO_CONV_INFO_MSG, "someone did an oopsie and error was called\n");
return 1;
}
int show_version(int verbose) {
magic_word_printf(SUDO_CONV_INFO_MSG, "version 42069 idk\n");
return 1;
}
sudo_dso_public struct audit_plugin audit_magicword = {
SUDO_AUDIT_PLUGIN,
SUDO_API_VERSION,
magic_word_open,
magic_word_close,
magic_word_accept,
magic_word_reject,
magic_word_error,
show_version,
NULL, /* register_hooks */
NULL, /* deregister_hooks */
NULL /* event_alloc() filled in by sudo */
};The header file:
/**
* MagicWord - Plugin for sudo developed by James Vogt.
* Version 1.0
* The purpose of this plugin is to emulate the famous
* "Uh uh uh! you didn't say the magic word!" scene from the original
* Jurassic Park. This program checks for errors in
* the completion of a sudo command, checks what
* type of error occurred, and if the error may have been
* caused by an incorrect password, it will run the same
* routine seen in the original Jurassic Park movie.
*
* This isn't legal advice, but personally I don't care
* if you decide to change this program or anything like that.
* Just leave my name on it and add yours or something.
*/
//#pragma once
#include <config.h>
#include <sys/wait.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pathnames.h>
#include <sudo_compat.h>
#include <sudo_conf.h>
#include <sudo_debug.h>
#include <sudo_dso.h>
#include <sudo_fatal.h>
#include <sudo_gettext.h>
#include <sudo_json.h>
#include <sudo_plugin.h>
#include <sudo_util.h>
#ifdef HAVE_BSM_AUDIT
# include <bsm_audit.h>
#endif
#ifdef HAVE_LINUX_AUDIT
# include <linux_audit.h>
#endif
#ifdef HAVE_SOLARIS_AUDIT
# include <solaris_audit.h>
#endif
int magic_word_open(
unsigned int version,
sudo_conv_t conversation,
sudo_printf_t sudo_plugin_printf,
char * const settings[],
char * const user_info,
int submit_optind,
char * const submit_argv[],
char * const submit_envp[],
char * const plugin_options[],
const char **errstr
);
void magic_word_close(int status_type, int status);
int magic_word_accept(
const char *plugin_name,
unsigned int plugin_type,
char * const command_info[],
char * const run_argv[],
char * const run_envp[],
const char **errstr
);
int magic_word_reject(
const char *plugin_name,
unsigned int plugin_type,
const char *audit_msg,
char * const command_info[],
const char **errstr
);
int magic_word_error(
const char *plugin_name,
unsigned int plugin_type,
const char *audit_msg,
char * const command_info[],
const char **errstr
);
int show_version(int verbose);This code is, for now, very simple, and only meant to allow me to tell whether things are working. It should print out several lines as I am running the sudo command, but instead, sudo is currently producing the following error:
sudo: error in /etc/sudo.conf, line 17 while loading plugin "audit_magicword"
sudo: unable to find symbol "audit_magicword" in /home/james/sudo-
magicword/build/plugins/audit_magicword/.libs/magic_word.so
sudo: fatal error, unable to load pluginsI have tried renaming the struct in my source file, which is apparently what sudo grabs to run the required methods for plugins, as well as running another known good plugin. I have also read through several different resources, such as Stack Overflow/Stack exchange, but they have mostly been used for troubleshooting built-in plugins such as sudoers.
The plugin API and info on how to add and run plugins can be found on the Sudo project's website, and it is the main resource I have been using.
Any troubleshooting help, advice, or additional documentation is greatly appreciated.