|
Line 0
Link Here
|
|
|
1 |
/* Copyright (C) 2011 Frederic Crozat |
| 2 |
Author: Frederic Crozat <fcrozat@suse.com> |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License version 2 as |
| 6 |
published by the Free Software Foundation. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, |
| 9 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License |
| 14 |
along with this program; if not, write to the Free Software Foundation, |
| 15 |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 16 |
|
| 17 |
#ifdef HAVE_CONFIG_H |
| 18 |
#include <config.h> |
| 19 |
#endif |
| 20 |
|
| 21 |
#include <stdio.h> |
| 22 |
#include <string.h> |
| 23 |
#include <ctype.h> |
| 24 |
#include <stdlib.h> |
| 25 |
|
| 26 |
#include "pam-config.h" |
| 27 |
#include "pam-module.h" |
| 28 |
|
| 29 |
static int |
| 30 |
write_config_systemd (pam_module_t *this, enum write_type op, FILE *fp) |
| 31 |
{ |
| 32 |
option_set_t *opt_set = this->get_opt_set (this, op); |
| 33 |
char *opt; |
| 34 |
|
| 35 |
if (debug) |
| 36 |
debug_write_call (this, op); |
| 37 |
|
| 38 |
if (op != SESSION || !opt_set->is_enabled (opt_set, "is_enabled")) |
| 39 |
return 0; |
| 40 |
|
| 41 |
fprintf (fp, "session\toptional\tpam_systemd.so"); |
| 42 |
|
| 43 |
if (opt_set->is_enabled (opt_set, "debug")) |
| 44 |
fprintf(fp, " debug"); |
| 45 |
if ((opt = opt_set->get_opt (opt_set, "create_session"))) |
| 46 |
fprintf(fp, " create-session=%s",opt); |
| 47 |
if ((opt = opt_set->get_opt (opt_set, "kill_session"))) |
| 48 |
fprintf(fp, " kill-session=%s",opt); |
| 49 |
if ((opt = opt_set->get_opt (opt_set, "kill_user"))) |
| 50 |
fprintf(fp, " kill-user=%s",opt); |
| 51 |
if ((opt = opt_set->get_opt (opt_set, "kill_only_users"))) |
| 52 |
fprintf(fp, " kill-only-users=%s",opt); |
| 53 |
if ((opt = opt_set->get_opt (opt_set, "kill_exclude_users"))) |
| 54 |
fprintf(fp, " kill-exclude-users=%s",opt); |
| 55 |
if ((opt = opt_set->get_opt (opt_set, "controllers"))) |
| 56 |
fprintf(fp, " controllers=%s",opt); |
| 57 |
if ((opt = opt_set->get_opt (opt_set, "reset_controllers"))) |
| 58 |
fprintf(fp, " reset-controllers=%s",opt); |
| 59 |
|
| 60 |
fprintf(fp, "\n"); |
| 61 |
return 0; |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
static int |
| 66 |
parse_config_systemd (pam_module_t *this, char *args, write_type_t type) |
| 67 |
{ |
| 68 |
option_set_t *opt_set = this->get_opt_set (this, type); |
| 69 |
|
| 70 |
if (debug) |
| 71 |
printf ("**** parse_config_%s (%s): '%s'\n", this->name, |
| 72 |
type2string (type), args ? args : ""); |
| 73 |
|
| 74 |
opt_set->enable (opt_set, "is_enabled", TRUE); |
| 75 |
|
| 76 |
while (args && strlen (args) > 0) |
| 77 |
{ |
| 78 |
char *cp = strsep (&args, " \t"); |
| 79 |
|
| 80 |
if (args) |
| 81 |
while (isspace ((int) *args)) |
| 82 |
++args; |
| 83 |
|
| 84 |
if (strcmp (cp, "debug") == 0) |
| 85 |
opt_set->enable (opt_set, "debug", TRUE); |
| 86 |
else if (strncmp (cp, "create-session=", 15) == 0) |
| 87 |
opt_set->set_opt (opt_set, "create_session", strdup(&cp[15])); |
| 88 |
else if (strncmp (cp, "kill-session=", 13) == 0) |
| 89 |
opt_set->set_opt (opt_set, "kill_session", strdup(&cp[13])); |
| 90 |
else if (strncmp (cp, "kill-user=", 10) == 0) |
| 91 |
opt_set->set_opt (opt_set, "kill_user", strdup(&cp[10])); |
| 92 |
else if (strncmp (cp, "kill-only-users=", 16) == 0) |
| 93 |
opt_set->set_opt (opt_set, "kill_only_users", strdup (&cp[16])); |
| 94 |
else if (strncmp (cp, "kill-exclude-users=", 19) == 0) |
| 95 |
opt_set->set_opt (opt_set, "kill_exclude_users", strdup (&cp[19])); |
| 96 |
else if (strncmp (cp, "controllers=", 12) == 0) |
| 97 |
opt_set->set_opt (opt_set, "controllers", strdup (&cp[12])); |
| 98 |
else if (strncmp (cp, "reset-controllers=", 18) == 0) |
| 99 |
opt_set->set_opt (opt_set, "reset_controllers", strdup (&cp[18])); |
| 100 |
else |
| 101 |
print_unknown_option_error ("pam_systemd.so", cp); |
| 102 |
} |
| 103 |
return 1; |
| 104 |
} |
| 105 |
|
| 106 |
GETOPT_START_1(SESSION) |
| 107 |
GETOPT_END_1(SESSION) |
| 108 |
|
| 109 |
PRINT_ARGS("systemd") |
| 110 |
PRINT_XMLHELP("systemd") |
| 111 |
|
| 112 |
/* ---- contruct module object ---- */ |
| 113 |
DECLARE_BOOL_OPTS_2 (is_enabled, debug); |
| 114 |
DECLARE_STRING_OPTS_7 (create_session, kill_session, kill_user, kill_only_users, kill_exclude_users, controllers, reset_controllers); |
| 115 |
DECLARE_OPT_SETS; |
| 116 |
|
| 117 |
static module_helptext_t helptext[] = {{NULL, NULL, NULL}}; |
| 118 |
|
| 119 |
|
| 120 |
/* at last construct the complete module object */ |
| 121 |
pam_module_t mod_pam_systemd = { "pam_systemd.so", opt_sets, helptext, |
| 122 |
&parse_config_systemd, |
| 123 |
&def_print_module, |
| 124 |
&write_config_systemd, |
| 125 |
&get_opt_set, |
| 126 |
&getopt, |
| 127 |
&print_args, |
| 128 |
&print_xmlhelp}; |