|
Line 0
Link Here
|
|
|
1 |
/* Copyright (C) 2017 SUSE Linux GmbH |
| 2 |
Author: Josef Möllers <jmoellers@suse.de> |
| 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 |
|
| 22 |
#include <stdio.h> |
| 23 |
#include <string.h> |
| 24 |
#include <ctype.h> |
| 25 |
|
| 26 |
#include "pam-config.h" |
| 27 |
#include "pam-module.h" |
| 28 |
|
| 29 |
static void write_entry(FILE *fp, option_set_t *opt_set); |
| 30 |
|
| 31 |
static int |
| 32 |
write_config_keyinit (pam_module_t *this, |
| 33 |
enum write_type op __attribute__ ((unused)), |
| 34 |
FILE *unused __attribute__((unused))) |
| 35 |
{ |
| 36 |
option_set_t *opt_set = this->get_opt_set (this, SESSION); |
| 37 |
FILE *fp; |
| 38 |
config_content_t *cfg_content; |
| 39 |
int writeit = opt_set->is_enabled (opt_set, "is_enabled"); |
| 40 |
int is_written = 0; |
| 41 |
|
| 42 |
if (debug) |
| 43 |
debug_write_call (this, SESSION); |
| 44 |
|
| 45 |
load_single_config (gl_service, &cfg_content); |
| 46 |
|
| 47 |
fp = create_service_file (gl_service); |
| 48 |
if (!fp) return 0; |
| 49 |
|
| 50 |
fprintf(stderr, "writeit=%d, is_written=%d\n", writeit, is_written); |
| 51 |
while (cfg_content != NULL) |
| 52 |
{ |
| 53 |
fprintf(stderr, "cfg_content->line = >>%s", cfg_content->line); |
| 54 |
if (writeit) |
| 55 |
{ |
| 56 |
fprintf(stderr, "writeit=%d\n", writeit); |
| 57 |
if (!is_written) |
| 58 |
{ |
| 59 |
fprintf(stderr, "is_written=%d\n", is_written); |
| 60 |
/* write this entry as the first in the session part */ |
| 61 |
if (strstr(cfg_content->line, "session") != NULL) |
| 62 |
{ |
| 63 |
fprintf(stderr, "strstr(cfg_content->line, \"session\") != NULL\n"); |
| 64 |
write_entry(fp, opt_set); |
| 65 |
is_written = 1; |
| 66 |
} |
| 67 |
} |
| 68 |
/* skip old entries */ |
| 69 |
if (strcasestr (cfg_content->line, "pam_keyinit.so") == NULL ) |
| 70 |
fprintf (fp, "%s", cfg_content->line); |
| 71 |
} |
| 72 |
else |
| 73 |
{ |
| 74 |
/* skip old entries */ |
| 75 |
if (strcasestr (cfg_content->line, "pam_keyinit.so") == NULL) |
| 76 |
fprintf (fp, "%s", cfg_content->line); |
| 77 |
else |
| 78 |
is_written = 1; |
| 79 |
} |
| 80 |
cfg_content = cfg_content->next; |
| 81 |
} |
| 82 |
|
| 83 |
/* |
| 84 |
* If it has not been written yet, write it now |
| 85 |
* This is highly unlikely as most config files include common-session |
| 86 |
* but then ... |
| 87 |
*/ |
| 88 |
if (!is_written) |
| 89 |
{ |
| 90 |
write_entry(fp, opt_set); |
| 91 |
is_written = 1; |
| 92 |
} |
| 93 |
|
| 94 |
return close_service_file (fp,gl_service); |
| 95 |
} |
| 96 |
|
| 97 |
static void |
| 98 |
write_entry(FILE *fp, option_set_t *opt_set) |
| 99 |
{ |
| 100 |
fprintf(stderr, "write_entry(fp, opt_set)\n"); |
| 101 |
fprintf (fp, "session optional\tpam_keyinit.so revoke "); |
| 102 |
if (opt_set->is_enabled (opt_set, "force")) |
| 103 |
fprintf (fp, "force "); |
| 104 |
if (opt_set->is_enabled (opt_set, "debug")) |
| 105 |
fprintf (fp, "debug "); |
| 106 |
|
| 107 |
fprintf (fp, "\n"); |
| 108 |
|
| 109 |
return; |
| 110 |
} |
| 111 |
|
| 112 |
GETOPT_START_ALL |
| 113 |
else if (strcmp ("force", opt) == 0) |
| 114 |
{ |
| 115 |
opt_set = this->get_opt_set (this, SESSION); |
| 116 |
opt_set->enable (opt_set, "force", g_opt->opt_val); |
| 117 |
} |
| 118 |
GETOPT_END_ALL |
| 119 |
|
| 120 |
PRINT_ARGS("keyinit") |
| 121 |
PRINT_XMLHELP("keyinit") |
| 122 |
|
| 123 |
/* ---- contruct module object ---- */ |
| 124 |
DECLARE_BOOL_OPTS_3 (is_enabled, debug, force); |
| 125 |
DECLARE_STRING_OPTS_0; |
| 126 |
DECLARE_OPT_SETS; |
| 127 |
|
| 128 |
static module_helptext_t helptext[] = {{NULL, NULL, NULL}}; |
| 129 |
|
| 130 |
/* at last construct the complete module object */ |
| 131 |
pam_module_t mod_pam_keyinit = { "pam_keyinit.so", opt_sets, helptext, |
| 132 |
&def_parse_config, |
| 133 |
&def_print_module, |
| 134 |
&write_config_keyinit, |
| 135 |
&get_opt_set, |
| 136 |
&getopt, |
| 137 |
&print_args, |
| 138 |
&print_xmlhelp}; |