pam_ptconfig.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2005 Red Hat, Inc.
  35. * All rights reserved.
  36. * END COPYRIGHT BLOCK **/
  37. #ifdef HAVE_CONFIG_H
  38. # include <config.h>
  39. #endif
  40. /*
  41. * ptconfig.c - configuration-related code for Pass Through Authentication
  42. *
  43. */
  44. #include <plstr.h>
  45. #include "pam_passthru.h"
  46. #define PAM_PT_CONFIG_FILTER "(objectclass=*)"
  47. /*
  48. * The configuration attributes are contained in the plugin entry e.g.
  49. * cn=PAM Pass Through,cn=plugins,cn=config
  50. *
  51. * Configuration is a two step process. The first pass is a validation step which
  52. * occurs pre-op - check inputs and error out if bad. The second pass actually
  53. * applies the changes to the run time config.
  54. */
  55. /*
  56. * function prototypes
  57. */
  58. static int pam_passthru_validate_config (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  59. int *returncode, char *returntext, void *arg);
  60. static int pam_passthru_apply_config (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  61. int *returncode, char *returntext, void *arg);
  62. static int pam_passthru_search (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  63. int *returncode, char *returntext, void *arg)
  64. {
  65. return SLAPI_DSE_CALLBACK_OK;
  66. }
  67. /*
  68. * static variables
  69. */
  70. /* for now, there is only one configuration and it is global to the plugin */
  71. static Pam_PassthruConfig theConfig;
  72. static int inited = 0;
  73. static int dont_allow_that(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  74. int *returncode, char *returntext, void *arg)
  75. {
  76. *returncode = LDAP_UNWILLING_TO_PERFORM;
  77. return SLAPI_DSE_CALLBACK_ERROR;
  78. }
  79. /*
  80. * Read configuration and create a configuration data structure.
  81. * This is called after the server has configured itself so we can check
  82. * for things like collisions between our suffixes and backend's suffixes.
  83. * Returns an LDAP error code (LDAP_SUCCESS if all goes well).
  84. */
  85. int
  86. pam_passthru_config(Slapi_Entry *config_e)
  87. {
  88. int returncode = LDAP_SUCCESS;
  89. char returntext[SLAPI_DSE_RETURNTEXT_SIZE];
  90. if ( inited ) {
  91. slapi_log_error( SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
  92. "only one PAM pass through plugin instance can be used\n" );
  93. return( LDAP_PARAM_ERROR );
  94. }
  95. /* initialize fields */
  96. if ((theConfig.lock = slapi_new_mutex()) == NULL) {
  97. return( LDAP_LOCAL_ERROR );
  98. }
  99. /* do not fallback to regular bind */
  100. theConfig.pamptconfig_fallback = PR_FALSE;
  101. /* require TLS/SSL security */
  102. theConfig.pamptconfig_secure = PR_TRUE;
  103. /* use the RDN method to derive the PAM identity */
  104. theConfig.pamptconfig_map_method1 = PAMPT_MAP_METHOD_RDN;
  105. theConfig.pamptconfig_map_method2 = PAMPT_MAP_METHOD_NONE;
  106. theConfig.pamptconfig_map_method3 = PAMPT_MAP_METHOD_NONE;
  107. if (SLAPI_DSE_CALLBACK_OK == pam_passthru_validate_config(NULL, NULL, config_e,
  108. &returncode, returntext, NULL)) {
  109. pam_passthru_apply_config(NULL, NULL, config_e,
  110. &returncode, returntext, NULL);
  111. }
  112. /* config DSE must be initialized before we get here */
  113. if (returncode == LDAP_SUCCESS) {
  114. const char *config_dn = slapi_entry_get_dn_const(config_e);
  115. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
  116. PAM_PT_CONFIG_FILTER, pam_passthru_validate_config,NULL);
  117. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, config_dn, LDAP_SCOPE_BASE,
  118. PAM_PT_CONFIG_FILTER, pam_passthru_apply_config,NULL);
  119. slapi_config_register_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
  120. PAM_PT_CONFIG_FILTER, dont_allow_that, NULL);
  121. slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
  122. PAM_PT_CONFIG_FILTER, dont_allow_that, NULL);
  123. slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
  124. PAM_PT_CONFIG_FILTER, pam_passthru_search,NULL);
  125. }
  126. inited = 1;
  127. if (returncode != LDAP_SUCCESS) {
  128. slapi_log_error(SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
  129. "Error %d: %s\n", returncode, returntext);
  130. }
  131. return returncode;
  132. }
  133. static int
  134. missing_suffix_to_int(char *missing_suffix)
  135. {
  136. int retval = -1; /* -1 is error */
  137. if (!PL_strcasecmp(missing_suffix, PAMPT_MISSING_SUFFIX_ERROR_STRING)) {
  138. retval = PAMPT_MISSING_SUFFIX_ERROR;
  139. } else if (!PL_strcasecmp(missing_suffix, PAMPT_MISSING_SUFFIX_ALLOW_STRING)) {
  140. retval = PAMPT_MISSING_SUFFIX_ALLOW;
  141. } else if (!PL_strcasecmp(missing_suffix, PAMPT_MISSING_SUFFIX_IGNORE_STRING)) {
  142. retval = PAMPT_MISSING_SUFFIX_IGNORE;
  143. }
  144. return retval;
  145. }
  146. static PRBool
  147. check_missing_suffix_flag(int val) {
  148. if (val == PAMPT_MISSING_SUFFIX_ERROR ||
  149. val == PAMPT_MISSING_SUFFIX_ALLOW ||
  150. val == PAMPT_MISSING_SUFFIX_IGNORE) {
  151. return PR_TRUE;
  152. }
  153. return PR_FALSE;
  154. }
  155. #define MAKE_STR(x) #x
  156. static char *get_missing_suffix_values()
  157. {
  158. return MAKE_STR(PAMPT_MISSING_SUFFIX_ERROR) ", " MAKE_STR(PAMPT_MISSING_SUFFIX_ALLOW) ", "
  159. MAKE_STR(PAMPT_MISSING_SUFFIX_IGNORE);
  160. }
  161. static char *get_map_method_values()
  162. {
  163. return PAMPT_MAP_METHOD_DN_STRING " or " PAMPT_MAP_METHOD_RDN_STRING " or " PAMPT_MAP_METHOD_ENTRY_STRING;
  164. }
  165. static int
  166. meth_to_int(char **map_method, int *err)
  167. {
  168. char *end;
  169. int len;
  170. int ret = PAMPT_MAP_METHOD_NONE;
  171. *err = 0;
  172. if (!map_method || !*map_method) {
  173. return ret;
  174. }
  175. end = strchr(*map_method, ' ');
  176. if (!end) {
  177. len = strlen(*map_method);
  178. } else {
  179. len = end - *map_method;
  180. }
  181. if (!PL_strncasecmp(*map_method, PAMPT_MAP_METHOD_DN_STRING, len)) {
  182. ret = PAMPT_MAP_METHOD_DN;
  183. } else if (!PL_strncasecmp(*map_method, PAMPT_MAP_METHOD_RDN_STRING, len)) {
  184. ret = PAMPT_MAP_METHOD_RDN;
  185. } else if (!PL_strncasecmp(*map_method, PAMPT_MAP_METHOD_ENTRY_STRING, len)) {
  186. ret = PAMPT_MAP_METHOD_ENTRY;
  187. } else {
  188. *err = 1;
  189. }
  190. if (!*err) {
  191. if (end && *end) {
  192. *map_method = end + 1;
  193. } else {
  194. *map_method = NULL;
  195. }
  196. }
  197. return ret;
  198. }
  199. static int
  200. parse_map_method(char *map_method, int *one, int *two, int *three, char *returntext)
  201. {
  202. int err = LDAP_SUCCESS;
  203. int extra;
  204. char **ptr = &map_method;
  205. *one = *two = *three = PAMPT_MAP_METHOD_NONE;
  206. *one = meth_to_int(ptr, &err);
  207. if (err) {
  208. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  209. "The map method in the string [%s] is invalid: must be "
  210. "one of %s", map_method, get_map_method_values());
  211. return LDAP_UNWILLING_TO_PERFORM;
  212. }
  213. *two = meth_to_int(ptr, &err);
  214. if (err) {
  215. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  216. "The map method in the string [%s] is invalid: must be "
  217. "one of %s", map_method, get_map_method_values());
  218. return LDAP_UNWILLING_TO_PERFORM;
  219. }
  220. *three = meth_to_int(ptr, &err);
  221. if (err) {
  222. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  223. "The map method in the string [%s] is invalid: must be "
  224. "one of %s", map_method, get_map_method_values());
  225. return LDAP_UNWILLING_TO_PERFORM;
  226. }
  227. if (((extra = meth_to_int(ptr, &err)) != PAMPT_MAP_METHOD_NONE) ||
  228. err) {
  229. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  230. "Invalid extra text [%s] after last map method",
  231. ((ptr && *ptr) ? *ptr : "(null)"));
  232. return LDAP_UNWILLING_TO_PERFORM;
  233. }
  234. return err;
  235. }
  236. static void
  237. print_suffixes()
  238. {
  239. void *cookie = NULL;
  240. Slapi_DN *sdn = NULL;
  241. slapi_log_error(SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
  242. "The following is the list of valid suffixes to use with "
  243. PAMPT_EXCLUDES_ATTR " and " PAMPT_INCLUDES_ATTR ":\n");
  244. for (sdn = slapi_get_first_suffix(&cookie, 1);
  245. sdn && cookie;
  246. sdn = slapi_get_next_suffix(&cookie, 1)) {
  247. slapi_log_error(SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
  248. "\t%s\n", slapi_sdn_get_dn(sdn));
  249. }
  250. }
  251. /*
  252. Validate the pending changes in the e entry.
  253. */
  254. static int
  255. pam_passthru_validate_config (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  256. int *returncode, char *returntext, void *arg)
  257. {
  258. char *missing_suffix_str = NULL;
  259. int missing_suffix;
  260. int ii;
  261. char **excludes = NULL;
  262. char **includes = NULL;
  263. char *pam_ident_attr = NULL;
  264. char *map_method = NULL;
  265. *returncode = LDAP_UNWILLING_TO_PERFORM; /* be pessimistic */
  266. /* first, get the missing_suffix flag and validate it */
  267. missing_suffix_str = slapi_entry_attr_get_charptr(e, PAMPT_MISSING_SUFFIX_ATTR);
  268. if ((missing_suffix = missing_suffix_to_int(missing_suffix_str)) < 0 ||
  269. !check_missing_suffix_flag(missing_suffix)) {
  270. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  271. "Error: valid values for %s are %s",
  272. PAMPT_MISSING_SUFFIX_ATTR, get_missing_suffix_values());
  273. goto done;
  274. }
  275. if (missing_suffix != PAMPT_MISSING_SUFFIX_IGNORE) {
  276. char **missing_list = NULL;
  277. /* get the list of excluded suffixes */
  278. excludes = slapi_entry_attr_get_charray(e, PAMPT_EXCLUDES_ATTR);
  279. for (ii = 0; excludes && excludes[ii]; ++ii) {
  280. Slapi_DN *comp_dn = slapi_sdn_new_dn_byref(excludes[ii]);
  281. if (!slapi_be_exist(comp_dn)) {
  282. charray_add(&missing_list, slapi_ch_strdup(excludes[ii]));
  283. }
  284. slapi_sdn_free(&comp_dn);
  285. }
  286. /* get the list of included suffixes */
  287. includes = slapi_entry_attr_get_charray(e, PAMPT_INCLUDES_ATTR);
  288. for (ii = 0; includes && includes[ii]; ++ii) {
  289. Slapi_DN *comp_dn = slapi_sdn_new_dn_byref(includes[ii]);
  290. if (!slapi_be_exist(comp_dn)) {
  291. charray_add(&missing_list, slapi_ch_strdup(includes[ii]));
  292. }
  293. slapi_sdn_free(&comp_dn);
  294. }
  295. if (missing_list) {
  296. PRUint32 size =
  297. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  298. "The following suffixes listed in %s or %s are not present in this "
  299. "server: ", PAMPT_EXCLUDES_ATTR, PAMPT_INCLUDES_ATTR);
  300. for (ii = 0; missing_list[ii]; ++ii) {
  301. if (size < SLAPI_DSE_RETURNTEXT_SIZE) {
  302. size += PR_snprintf(returntext+size, SLAPI_DSE_RETURNTEXT_SIZE-size,
  303. "%s%s", (ii > 0) ? "; " : "",
  304. missing_list[ii]);
  305. }
  306. }
  307. slapi_ch_array_free(missing_list);
  308. missing_list = NULL;
  309. print_suffixes();
  310. if (missing_suffix != PAMPT_MISSING_SUFFIX_ERROR) {
  311. slapi_log_error(SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
  312. "Warning: %s\n", returntext);
  313. *returntext = 0; /* log error, don't report back to user */
  314. } else {
  315. goto done;
  316. }
  317. }
  318. }
  319. pam_ident_attr = slapi_entry_attr_get_charptr(e, PAMPT_PAM_IDENT_ATTR);
  320. map_method = slapi_entry_attr_get_charptr(e, PAMPT_MAP_METHOD_ATTR);
  321. if (map_method) {
  322. int one, two, three;
  323. if (LDAP_SUCCESS !=
  324. (*returncode = parse_map_method(map_method, &one, &two, &three, returntext))) {
  325. goto done; /* returntext set already */
  326. }
  327. if (!pam_ident_attr &&
  328. ((one == PAMPT_MAP_METHOD_ENTRY) || (two == PAMPT_MAP_METHOD_ENTRY) ||
  329. (three == PAMPT_MAP_METHOD_ENTRY))) {
  330. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Error: the %s method"
  331. " was specified, but no %s was given",
  332. PAMPT_MAP_METHOD_ENTRY_STRING, PAMPT_PAM_IDENT_ATTR);
  333. *returncode = LDAP_UNWILLING_TO_PERFORM;
  334. goto done;
  335. }
  336. if ((one == PAMPT_MAP_METHOD_NONE) && (two == PAMPT_MAP_METHOD_NONE) &&
  337. (three == PAMPT_MAP_METHOD_NONE)) {
  338. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Error: no method(s)"
  339. " specified for %s, should be one or more of %s",
  340. PAMPT_MAP_METHOD_ATTR, get_map_method_values());
  341. *returncode = LDAP_UNWILLING_TO_PERFORM;
  342. goto done;
  343. }
  344. }
  345. /* success */
  346. *returncode = LDAP_SUCCESS;
  347. done:
  348. slapi_ch_free_string(&map_method);
  349. slapi_ch_free_string(&pam_ident_attr);
  350. slapi_ch_array_free(excludes);
  351. excludes = NULL;
  352. slapi_ch_array_free(includes);
  353. includes = NULL;
  354. slapi_ch_free_string(&missing_suffix_str);
  355. if (*returncode != LDAP_SUCCESS)
  356. {
  357. return SLAPI_DSE_CALLBACK_ERROR;
  358. }
  359. else
  360. {
  361. return SLAPI_DSE_CALLBACK_OK;
  362. }
  363. }
  364. static Pam_PassthruSuffix *
  365. New_Pam_PassthruSuffix(char *suffix)
  366. {
  367. Pam_PassthruSuffix *newone = NULL;
  368. if (suffix) {
  369. newone = (Pam_PassthruSuffix *)slapi_ch_malloc(sizeof(Pam_PassthruSuffix));
  370. newone->pamptsuffix_dn = slapi_sdn_new_dn_byval(suffix);
  371. newone->pamptsuffix_next = NULL;
  372. }
  373. return newone;
  374. }
  375. static Pam_PassthruSuffix *
  376. pam_ptconfig_add_suffixes(char **str_list)
  377. {
  378. Pam_PassthruSuffix *head = NULL;
  379. Pam_PassthruSuffix *suffixent = NULL;
  380. if (str_list && *str_list) {
  381. int ii;
  382. for (ii = 0; str_list[ii]; ++ii) {
  383. Pam_PassthruSuffix *tmp = New_Pam_PassthruSuffix(str_list[ii]);
  384. if (!suffixent) {
  385. head = suffixent = tmp;
  386. } else {
  387. suffixent->pamptsuffix_next = tmp;
  388. suffixent = suffixent->pamptsuffix_next;
  389. }
  390. }
  391. }
  392. return head;
  393. }
  394. static void
  395. Delete_Pam_PassthruSuffix(Pam_PassthruSuffix *one)
  396. {
  397. if (one) {
  398. slapi_sdn_free(&one->pamptsuffix_dn);
  399. slapi_ch_free((void **)&one);
  400. }
  401. }
  402. static void
  403. pam_ptconfig_free_suffixes(Pam_PassthruSuffix *list)
  404. {
  405. while (list) {
  406. Pam_PassthruSuffix *next = list->pamptsuffix_next;
  407. Delete_Pam_PassthruSuffix(list);
  408. list = next;
  409. }
  410. }
  411. /*
  412. Apply the pending changes in the e entry to our config struct.
  413. validate must have already been called
  414. */
  415. static int
  416. pam_passthru_apply_config (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  417. int *returncode, char *returntext, void *arg)
  418. {
  419. char **excludes = NULL;
  420. char **includes = NULL;
  421. char *new_service = NULL;
  422. char *pam_ident_attr = NULL;
  423. char *map_method = NULL;
  424. PRBool fallback;
  425. PRBool secure;
  426. *returncode = LDAP_SUCCESS;
  427. pam_ident_attr = slapi_entry_attr_get_charptr(e, PAMPT_PAM_IDENT_ATTR);
  428. map_method = slapi_entry_attr_get_charptr(e, PAMPT_MAP_METHOD_ATTR);
  429. new_service = slapi_entry_attr_get_charptr(e, PAMPT_SERVICE_ATTR);
  430. excludes = slapi_entry_attr_get_charray(e, PAMPT_EXCLUDES_ATTR);
  431. includes = slapi_entry_attr_get_charray(e, PAMPT_INCLUDES_ATTR);
  432. fallback = slapi_entry_attr_get_bool(e, PAMPT_FALLBACK_ATTR);
  433. secure = slapi_entry_attr_get_bool(e, PAMPT_SECURE_ATTR);
  434. /* lock config here */
  435. slapi_lock_mutex(theConfig.lock);
  436. theConfig.pamptconfig_fallback = fallback;
  437. theConfig.pamptconfig_secure = secure;
  438. if (!theConfig.pamptconfig_service ||
  439. (new_service && PL_strcmp(theConfig.pamptconfig_service, new_service))) {
  440. slapi_ch_free_string(&theConfig.pamptconfig_service);
  441. theConfig.pamptconfig_service = new_service;
  442. new_service = NULL; /* config now owns memory */
  443. }
  444. /* get the list of excluded suffixes */
  445. pam_ptconfig_free_suffixes(theConfig.pamptconfig_excludes);
  446. theConfig.pamptconfig_excludes = pam_ptconfig_add_suffixes(excludes);
  447. /* get the list of included suffixes */
  448. pam_ptconfig_free_suffixes(theConfig.pamptconfig_includes);
  449. theConfig.pamptconfig_includes = pam_ptconfig_add_suffixes(includes);
  450. if (!theConfig.pamptconfig_pam_ident_attr ||
  451. (pam_ident_attr && PL_strcmp(theConfig.pamptconfig_pam_ident_attr, pam_ident_attr))) {
  452. slapi_ch_free_string(&theConfig.pamptconfig_pam_ident_attr);
  453. theConfig.pamptconfig_pam_ident_attr = pam_ident_attr;
  454. pam_ident_attr = NULL; /* config now owns memory */
  455. }
  456. if (map_method) {
  457. parse_map_method(map_method,
  458. &theConfig.pamptconfig_map_method1,
  459. &theConfig.pamptconfig_map_method2,
  460. &theConfig.pamptconfig_map_method3,
  461. NULL);
  462. }
  463. /* unlock config here */
  464. slapi_unlock_mutex(theConfig.lock);
  465. slapi_ch_free_string(&new_service);
  466. slapi_ch_free_string(&map_method);
  467. slapi_ch_free_string(&pam_ident_attr);
  468. slapi_ch_array_free(excludes);
  469. slapi_ch_array_free(includes);
  470. if (*returncode != LDAP_SUCCESS)
  471. {
  472. return SLAPI_DSE_CALLBACK_ERROR;
  473. }
  474. else
  475. {
  476. return SLAPI_DSE_CALLBACK_OK;
  477. }
  478. }
  479. int
  480. pam_passthru_check_suffix(Pam_PassthruConfig *cfg, char *binddn)
  481. {
  482. Slapi_DN *comp_dn;
  483. Pam_PassthruSuffix *try;
  484. int ret = LDAP_SUCCESS;
  485. comp_dn = slapi_sdn_new_dn_byref(binddn);
  486. slapi_lock_mutex(cfg->lock);
  487. if (!cfg->pamptconfig_includes && !cfg->pamptconfig_excludes) {
  488. goto done; /* NULL means allow */
  489. }
  490. /* exclude trumps include - if suffix is on exclude list, then
  491. deny */
  492. for (try = cfg->pamptconfig_excludes; try; try = try->pamptsuffix_next) {
  493. if (slapi_sdn_issuffix(comp_dn, try->pamptsuffix_dn)) {
  494. ret = LDAP_UNWILLING_TO_PERFORM; /* suffix is excluded */
  495. goto done;
  496. }
  497. }
  498. /* ok, now flip it - deny access unless dn is on include list */
  499. if (cfg->pamptconfig_includes) {
  500. ret = LDAP_UNWILLING_TO_PERFORM; /* suffix is excluded */
  501. for (try = cfg->pamptconfig_includes; try; try = try->pamptsuffix_next) {
  502. if (slapi_sdn_issuffix(comp_dn, try->pamptsuffix_dn)) {
  503. ret = LDAP_SUCCESS; /* suffix is included */
  504. goto done;
  505. }
  506. }
  507. }
  508. done:
  509. slapi_unlock_mutex(cfg->lock);
  510. slapi_sdn_free(&comp_dn);
  511. return ret;
  512. }
  513. /*
  514. * Get the pass though configuration data. For now, there is only one
  515. * configuration and it is global to the plugin.
  516. */
  517. Pam_PassthruConfig *
  518. pam_passthru_get_config( void )
  519. {
  520. return( &theConfig );
  521. }