diff options
author | Sergei Golubchik <serg@mariadb.org> | 2018-03-25 13:02:52 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2018-03-25 13:02:52 +0200 |
commit | c764bc0a78e9359fa208e074bd327f7a852c7cb7 (patch) | |
tree | eeb5d56d225d1fdf97a016c3eae7b93c4e1f6927 /plugin | |
parent | d702e463902bca7d94ff8a1a49468a5b7bdb4ba0 (diff) | |
parent | 15795b9f9a850d9587f17ef18e1ac7b5af31ec1e (diff) | |
download | mariadb-git-c764bc0a78e9359fa208e074bd327f7a852c7cb7.tar.gz |
Merge branch '10.1' into 10.2
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/auth_pam/mapper/pam_user_map.c | 84 | ||||
-rw-r--r-- | plugin/disks/CMakeLists.txt (renamed from plugin/information_schema_disks/CMakeLists.txt) | 2 | ||||
-rw-r--r-- | plugin/disks/README.txt (renamed from plugin/information_schema_disks/README.txt) | 25 | ||||
-rw-r--r-- | plugin/disks/information_schema_disks.cc (renamed from plugin/information_schema_disks/information_schema_disks.cc) | 13 | ||||
-rw-r--r-- | plugin/disks/mysql-test/disks/disks.result | 12 | ||||
-rw-r--r-- | plugin/disks/mysql-test/disks/disks.test | 2 | ||||
-rw-r--r-- | plugin/disks/mysql-test/disks/suite.opt | 1 | ||||
-rw-r--r-- | plugin/disks/mysql-test/disks/suite.pm | 10 |
8 files changed, 119 insertions, 30 deletions
diff --git a/plugin/auth_pam/mapper/pam_user_map.c b/plugin/auth_pam/mapper/pam_user_map.c index e62be946c4a..c03ea12be74 100644 --- a/plugin/auth_pam/mapper/pam_user_map.c +++ b/plugin/auth_pam/mapper/pam_user_map.c @@ -22,14 +22,24 @@ top: accounting @group_ro: readonly ========================================================= +If something doesn't work as expected you can get verbose +comments with the 'debug' option like this +========================================================= +auth required pam_user_map.so debug +========================================================= +These comments are written to the syslog as 'authpriv.debug' +and usually end up in /var/log/secure file. */ #include <stdlib.h> #include <stdio.h> +#include <ctype.h> +#include <string.h> #include <syslog.h> #include <grp.h> #include <pwd.h> +#include <security/pam_ext.h> #include <security/pam_modules.h> #define FILENAME "/etc/security/user_map.conf" @@ -90,9 +100,42 @@ static int user_in_group(const gid_t *user_groups, int ng,const char *group) } +static void print_groups(pam_handle_t *pamh, const gid_t *user_groups, int ng) +{ + char buf[256]; + char *c_buf= buf, *buf_end= buf+sizeof(buf)-2; + struct group *gr; + int cg; + + for (cg=0; cg < ng; cg++) + { + char *c; + if (c_buf == buf_end) + break; + *(c_buf++)= ','; + if (!(gr= getgrgid(user_groups[cg])) || + !(c= gr->gr_name)) + continue; + while (*c) + { + if (c_buf == buf_end) + break; + *(c_buf++)= *(c++); + } + } + c_buf[0]= c_buf[1]= 0; + pam_syslog(pamh, LOG_DEBUG, "User belongs to %d %s [%s].\n", + ng, (ng == 1) ? "group" : "groups", buf+1); +} + + +static const char debug_keyword[]= "debug"; +#define SYSLOG_DEBUG if (mode_debug) pam_syslog + int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char *argv[]) { + int mode_debug= 0; int pam_err, line= 0; const char *username; char buf[256]; @@ -101,6 +144,14 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, gid_t *groups= group_buffer; int n_groups= -1; + for (; argc > 0; argc--) + { + if (strcasecmp(argv[argc-1], debug_keyword) == 0) + mode_debug= 1; + } + + SYSLOG_DEBUG(pamh, LOG_DEBUG, "Opening file '%s'.\n", FILENAME); + f= fopen(FILENAME, "r"); if (f == NULL) { @@ -110,12 +161,18 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, pam_err = pam_get_item(pamh, PAM_USER, (const void**)&username); if (pam_err != PAM_SUCCESS) + { + pam_syslog(pamh, LOG_ERR, "Cannot get username.\n"); goto ret; + } + + SYSLOG_DEBUG(pamh, LOG_DEBUG, "Incoming username '%s'.\n", username); while (fgets(buf, sizeof(buf), f) != NULL) { char *s= buf, *from, *to, *end_from, *end_to; int check_group; + int cmp_result; line++; @@ -124,7 +181,11 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, if ((check_group= *s == '@')) { if (n_groups < 0) + { n_groups= populate_user_groups(username, &groups); + if (mode_debug) + print_groups(pamh, groups, n_groups); + } s++; } from= s; @@ -139,14 +200,30 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, if (end_to == to) goto syntax_error; *end_from= *end_to= 0; - if (check_group ? - user_in_group(groups, n_groups, from) : - (strcmp(username, from) == 0)) + + if (check_group) + { + cmp_result= user_in_group(groups, n_groups, from); + SYSLOG_DEBUG(pamh, LOG_DEBUG, "Check if user is in group '%s': %s\n", + from, cmp_result ? "YES":"NO"); + } + else + { + cmp_result= (strcmp(username, from) == 0); + SYSLOG_DEBUG(pamh, LOG_DEBUG, "Check if username '%s': %s\n", + from, cmp_result ? "YES":"NO"); + } + if (cmp_result) { pam_err= pam_set_item(pamh, PAM_USER, to); + SYSLOG_DEBUG(pamh, LOG_DEBUG, + (pam_err == PAM_SUCCESS) ? "User mapped as '%s'\n" : + "Couldn't map as '%s'\n", to); goto ret; } } + + SYSLOG_DEBUG(pamh, LOG_DEBUG, "User not found in the list.\n"); pam_err= PAM_AUTH_ERR; goto ret; @@ -162,6 +239,7 @@ ret: return pam_err; } + int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char *argv[]) { diff --git a/plugin/information_schema_disks/CMakeLists.txt b/plugin/disks/CMakeLists.txt index a0ed929c62c..446c64d0fdd 100644 --- a/plugin/information_schema_disks/CMakeLists.txt +++ b/plugin/disks/CMakeLists.txt @@ -1,4 +1,4 @@ -IF(NOT WIN32) +IF("${CMAKE_SYSTEM}" MATCHES "Linux") INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql) MYSQL_ADD_PLUGIN(DISKS information_schema_disks.cc MODULE_ONLY RECOMPILE_FOR_EMBEDDED) ENDIF() diff --git a/plugin/information_schema_disks/README.txt b/plugin/disks/README.txt index 1c9b8fb6283..b49db3c03b5 100644 --- a/plugin/information_schema_disks/README.txt +++ b/plugin/disks/README.txt @@ -57,31 +57,16 @@ tables; disks and mounts. ... -Building --------- -- Ensure that the directory information_schema_disks is in the top-level - directory of the server. -- Add - - ADD_SUBDIRECTORY(information_schema_disks) - - to the top-level CMakeLists.txt - -> Invoke make - - $ make - Installation ------------ -- Copy information_schema_disks/libinformation_schema_disks.so to the plugin - directory of the server: - $ cd information_schema_disks - $ sudo cp libinformation_schema_disks.so plugin-directory-of-server +- Use "install plugin" or "install soname" command: + + MariaDB [(none)]> install plugin disks soname 'disks.so'; -- Using mysql, install the plugin: + or - MariaDB [(none)]> install plugin disks soname 'libinformation_schema_disks.so'; + MariaDB [(none)]> install soname 'disks.so'; Usage ----- diff --git a/plugin/information_schema_disks/information_schema_disks.cc b/plugin/disks/information_schema_disks.cc index b5e3a6dc728..122b3d3f17f 100644 --- a/plugin/information_schema_disks/information_schema_disks.cc +++ b/plugin/disks/information_schema_disks.cc @@ -19,7 +19,8 @@ #include <mntent.h> #include <sql_class.h> #include <table.h> -#include <innodb_priv.h> + +bool schema_table_store_record(THD *thd, TABLE *table); namespace { @@ -133,21 +134,21 @@ int disks_table_init(void *ptr) extern "C" { -mysql_declare_plugin(disks_library) +maria_declare_plugin(disks) { MYSQL_INFORMATION_SCHEMA_PLUGIN, &disks_table_info, /* type-specific descriptor */ "DISKS", /* table name */ - "MariaDB", /* author */ + "Johan Wikman", /* author */ "Disk space information", /* description */ PLUGIN_LICENSE_GPL, /* license type */ disks_table_init, /* init function */ - NULL, + NULL, /* deinit function */ 0x0100, /* version = 1.0 */ NULL, /* no status variables */ NULL, /* no system variables */ - NULL, /* no reserved information */ - 0 /* no flags */ + "1.0", /* String version representation */ + MariaDB_PLUGIN_MATURITY_BETA /* Maturity (see include/mysql/plugin.h)*/ } mysql_declare_plugin_end; diff --git a/plugin/disks/mysql-test/disks/disks.result b/plugin/disks/mysql-test/disks/disks.result new file mode 100644 index 00000000000..65b1127d479 --- /dev/null +++ b/plugin/disks/mysql-test/disks/disks.result @@ -0,0 +1,12 @@ +show create table information_schema.disks; +Table Create Table +DISKS CREATE TEMPORARY TABLE `DISKS` ( + `Disk` varchar(4096) NOT NULL DEFAULT '', + `Path` varchar(4096) NOT NULL DEFAULT '', + `Total` int(32) NOT NULL DEFAULT 0, + `Used` int(32) NOT NULL DEFAULT 0, + `Available` int(32) NOT NULL DEFAULT 0 +) ENGINE=MEMORY DEFAULT CHARSET=utf8 +select sum(Total) > sum(Available), sum(Total)>sum(Used) from information_schema.disks; +sum(Total) > sum(Available) sum(Total)>sum(Used) +1 1 diff --git a/plugin/disks/mysql-test/disks/disks.test b/plugin/disks/mysql-test/disks/disks.test new file mode 100644 index 00000000000..13a0762ae01 --- /dev/null +++ b/plugin/disks/mysql-test/disks/disks.test @@ -0,0 +1,2 @@ +show create table information_schema.disks; +select sum(Total) > sum(Available), sum(Total)>sum(Used) from information_schema.disks; diff --git a/plugin/disks/mysql-test/disks/suite.opt b/plugin/disks/mysql-test/disks/suite.opt new file mode 100644 index 00000000000..afbbe2b0163 --- /dev/null +++ b/plugin/disks/mysql-test/disks/suite.opt @@ -0,0 +1 @@ +--plugin-load-add=$DISKS_SO diff --git a/plugin/disks/mysql-test/disks/suite.pm b/plugin/disks/mysql-test/disks/suite.pm new file mode 100644 index 00000000000..c64ef3b3133 --- /dev/null +++ b/plugin/disks/mysql-test/disks/suite.pm @@ -0,0 +1,10 @@ +package My::Suite::Disks; + +@ISA = qw(My::Suite); + +return "No Disks plugin" unless $ENV{DISKS_SO}; + +sub is_default { 1 } + +bless { }; + |