#include <stdio.h>#include <stdlib.h>#include <getopt.h>#include <string.h>#include <ctype.h>#include <signal.h>#include <sys/types.h>#include <pwd.h>#include <errno.h>#include <unistd.h>#include <syslog.h>#include <stdarg.h>#include <dirent.h>#include <sys/stat.h>#include <sys/socket.h>#include <sys/un.h>#include <sys/queue.h>#include <sys/wait.h>#include <sys/time.h>#include <libgen.h>#include <assert.h>#include <grp.h>#include <limits.h>#include <libconfig.h>
Go to the source code of this file.
Data Structures | |
| struct | plugin |
Defines | |
| #define | _GNU_SOURCE |
| #define | BASE_DIR "/var/run/lsm" |
| #define | SOCKET_DIR BASE_DIR"/ipc" |
| #define | PLUGIN_DIR "/usr/bin" |
| #define | LSM_USER "libstoragemgmt" |
| #define | LSM_CONF_DIR "/etc/lsm/" |
| #define | LSM_PLUGIN_CONF_DIR_NAME "pluginconf.d" |
| #define | LSMD_CONF_FILE "lsmd.conf" |
| #define | LSM_CONF_ALLOW_ROOT_OPT_NAME "allow-plugin-root-privilege" |
| #define | LSM_CONF_REQUIRE_ROOT_OPT_NAME "require-root-privilege" |
| #define | min(a, b) |
| #define | max(a, b) |
| #define | log_and_exit(fmt,...) logger(LOG_ERR, fmt, ##__VA_ARGS__) |
| #define | warn(fmt,...) logger(LOG_WARNING, fmt, ##__VA_ARGS__) |
| #define | info(fmt,...) logger(LOG_INFO, fmt, ##__VA_ARGS__) |
Typedefs | |
| typedef int(* | file_op )(void *p, char *full_file_path) |
Enumerations | |
| enum | serve_type { RUNNING, RESTART, EXIT } |
Functions | |
| LIST_HEAD (plugin_list, plugin) | |
| void | signal_handler (int s) |
| void | install_sh (void) |
| void | drop_privileges (void) |
| void | flight_check (void) |
| void | usage (void) |
| char * | path_form (const char *path, const char *name) |
| void | process_directory (char *dir, void *p, file_op call_back) |
| int | delete_socket (void *p, char *full_name) |
| void | clean_sockets () |
| int | setup_socket (char *full_name) |
| void | empty_plugin_list (struct plugin_list *list) |
| void | parse_conf_bool (char *conf_path, char *key_name, int *value) |
| int | chk_pconf_root_pri (char *plugin_path) |
| int | process_plugin (void *p, char *full_name) |
| void | child_cleanup (void) |
| void | clean_up (void) |
| int | process_plugins (void) |
| struct plugin * | plugin_lookup (int fd) |
| void | exec_plugin (char *plugin, int client_fd, int require_root) |
| void | _serving (void) |
| void | serve (void) |
| int | main (int argc, char *argv[]) |
Variables | |
| int | verbose_flag = 0 |
| int | systemd = 0 |
| char * | socket_dir = SOCKET_DIR |
| char * | plugin_dir = PLUGIN_DIR |
| char * | conf_dir = LSM_CONF_DIR |
| char | plugin_extension [] = "_lsmplugin" |
| char | plugin_conf_extension [] = ".conf" |
| serve_type | serve_state = RUNNING |
| int | plugin_mem_debug = 0 |
| int | allow_root_plugin = 0 |
| int | has_root_plugin = 0 |
| #define _GNU_SOURCE |
Definition at line 19 of file lsm_daemon.c.
| #define BASE_DIR "/var/run/lsm" |
Definition at line 47 of file lsm_daemon.c.
| #define info | ( | fmt, | |||
| ... | ) | logger(LOG_INFO, fmt, ##__VA_ARGS__) |
Definition at line 136 of file lsm_daemon.c.
| #define log_and_exit | ( | fmt, | |||
| ... | ) | logger(LOG_ERR, fmt, ##__VA_ARGS__) |
Definition at line 134 of file lsm_daemon.c.
| #define LSM_CONF_ALLOW_ROOT_OPT_NAME "allow-plugin-root-privilege" |
Definition at line 54 of file lsm_daemon.c.
| #define LSM_CONF_DIR "/etc/lsm/" |
Definition at line 51 of file lsm_daemon.c.
| #define LSM_CONF_REQUIRE_ROOT_OPT_NAME "require-root-privilege" |
Definition at line 55 of file lsm_daemon.c.
| #define LSM_PLUGIN_CONF_DIR_NAME "pluginconf.d" |
Definition at line 52 of file lsm_daemon.c.
| #define LSM_USER "libstoragemgmt" |
Definition at line 50 of file lsm_daemon.c.
| #define LSMD_CONF_FILE "lsmd.conf" |
Definition at line 53 of file lsm_daemon.c.
| #define max | ( | a, | |||
| b | ) |
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
Definition at line 62 of file lsm_daemon.c.
| #define min | ( | a, | |||
| b | ) |
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
Definition at line 57 of file lsm_daemon.c.
| #define PLUGIN_DIR "/usr/bin" |
Definition at line 49 of file lsm_daemon.c.
| #define SOCKET_DIR BASE_DIR"/ipc" |
Definition at line 48 of file lsm_daemon.c.
| #define warn | ( | fmt, | |||
| ... | ) | logger(LOG_WARNING, fmt, ##__VA_ARGS__) |
Definition at line 135 of file lsm_daemon.c.
Definition at line 254 of file lsm_daemon.c.
| enum serve_type |
Definition at line 78 of file lsm_daemon.c.
| void _serving | ( | void | ) |
Main event loop
Definition at line 739 of file lsm_daemon.c.


| void child_cleanup | ( | void | ) |
Cleans up any children that have exited.
Definition at line 559 of file lsm_daemon.c.

| int chk_pconf_root_pri | ( | char * | plugin_path | ) |
Load plugin config for root privilege setting. If config not found, return 0 for no root privilege required.
| plugin_path | Full path of plugin |
Definition at line 474 of file lsm_daemon.c.


| void clean_sockets | ( | ) |
Walk the IPC socket directory and remove the socket files.
Definition at line 339 of file lsm_daemon.c.


| void clean_up | ( | void | ) |
Closes and frees memory and removes Unix domain sockets.
Definition at line 592 of file lsm_daemon.c.


| int delete_socket | ( | void * | p, | |
| char * | full_name | |||
| ) |
Callback to remove a unix domain socket by deleting it.
| p | Call back data | |
| full_name | Full path an and file name |
Definition at line 317 of file lsm_daemon.c.

| void drop_privileges | ( | void | ) |
If we are running as root, we will try to drop our privs. to our default user.
Definition at line 169 of file lsm_daemon.c.

| void empty_plugin_list | ( | struct plugin_list * | list | ) |
Closes all the listening sockets and re-claims memory in linked list.
| list |
Definition at line 409 of file lsm_daemon.c.

| void exec_plugin | ( | char * | plugin, | |
| int | client_fd, | |||
| int | require_root | |||
| ) |
Does the actual fork and exec of the plug-in
| plugin | Full filename and path of plug-in to exec. | |
| client_fd | Client connected file descriptor | |
| require_root | int, indicate whether this plugin require root privilege or not |
Definition at line 638 of file lsm_daemon.c.


| void flight_check | ( | void | ) |
Check to make sure we have access to the directories of interest
Definition at line 203 of file lsm_daemon.c.

| void install_sh | ( | void | ) |
Installs our signal handler
Definition at line 154 of file lsm_daemon.c.


| LIST_HEAD | ( | plugin_list | , | |
| plugin | ||||
| ) |
Linked list of plug-ins
Definition at line 99 of file lsm_daemon.c.
| int main | ( | int | argc, | |
| char * | argv[] | |||
| ) |
| void parse_conf_bool | ( | char * | conf_path, | |
| char * | key_name, | |||
| int * | value | |||
| ) |
Parse config and seeking provided key name bool 1. Keep value untouched if file not exist 2. If file is not readable, abort via log_and_exit() 3. Keep value untouched if provided key not found 4. Abort via log_and_exit() if no enough memory.
| conf_path | config file path | |
| key_name | string, searching key | |
| value | int, output, value of this config key |
Definition at line 442 of file lsm_daemon.c.

| char* path_form | ( | const char * | path, | |
| const char * | name | |||
| ) |
Concatenates a path and a file name.
| path | Fully qualified path | |
| name | File name |
Definition at line 241 of file lsm_daemon.c.

| struct plugin* plugin_lookup | ( | int | fd | ) | [read] |
Given a socket descriptor looks it up and returns the plug-in
| fd | Socket descriptor to lookup |
Definition at line 620 of file lsm_daemon.c.

| void process_directory | ( | char * | dir, | |
| void * | p, | |||
| file_op | call_back | |||
| ) |
For a given directory iterate through each directory item and exec the callback, recursively process nested directories too.
| dir | Directory to transverse | |
| p | Pointer to user data (Optional) | |
| call_back | Function to call against file |
Definition at line 264 of file lsm_daemon.c.


| int process_plugin | ( | void * | p, | |
| char * | full_name | |||
| ) |
Call back for plug-in processing.
| p | Private data | |
| full_name | Full path and file name |
Definition at line 519 of file lsm_daemon.c.


| int process_plugins | ( | void | ) |
Walks the plugin directory creating IPC sockets for each one.
Definition at line 602 of file lsm_daemon.c.


| void serve | ( | void | ) |
Main entry for daemon to work
Definition at line 798 of file lsm_daemon.c.


| int setup_socket | ( | char * | full_name | ) |
Given a fully qualified path and name to a plug-in, create the IPC socket.
| full_name | Full name and path for plug-in |
Definition at line 350 of file lsm_daemon.c.


| void signal_handler | ( | int | s | ) |
Our signal handler.
| s | Received signal |
Definition at line 142 of file lsm_daemon.c.

| void usage | ( | void | ) |
Print help.
Definition at line 222 of file lsm_daemon.c.

| int allow_root_plugin = 0 |
Definition at line 83 of file lsm_daemon.c.
| char* conf_dir = LSM_CONF_DIR |
Definition at line 72 of file lsm_daemon.c.
| int has_root_plugin = 0 |
Definition at line 84 of file lsm_daemon.c.
| char plugin_conf_extension[] = ".conf" |
Definition at line 76 of file lsm_daemon.c.
| char* plugin_dir = PLUGIN_DIR |
Definition at line 71 of file lsm_daemon.c.
| char plugin_extension[] = "_lsmplugin" |
Definition at line 74 of file lsm_daemon.c.
| int plugin_mem_debug = 0 |
Definition at line 81 of file lsm_daemon.c.
| serve_type serve_state = RUNNING |
Definition at line 79 of file lsm_daemon.c.
| char* socket_dir = SOCKET_DIR |
Definition at line 70 of file lsm_daemon.c.
| int systemd = 0 |
Definition at line 68 of file lsm_daemon.c.
| int verbose_flag = 0 |
Definition at line 67 of file lsm_daemon.c.
1.6.1