1
0

pam_ptconfig.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. char **ptr = &map_method;
  204. *one = *two = *three = PAMPT_MAP_METHOD_NONE;
  205. *one = meth_to_int(ptr, &err);
  206. if (err) {
  207. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  208. "The map method in the string [%s] is invalid: must be "
  209. "one of %s", map_method, get_map_method_values());
  210. return LDAP_UNWILLING_TO_PERFORM;
  211. }
  212. *two = meth_to_int(ptr, &err);
  213. if (err) {
  214. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  215. "The map method in the string [%s] is invalid: must be "
  216. "one of %s", map_method, get_map_method_values());
  217. return LDAP_UNWILLING_TO_PERFORM;
  218. }
  219. *three = meth_to_int(ptr, &err);
  220. if (err) {
  221. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  222. "The map method in the string [%s] is invalid: must be "
  223. "one of %s", map_method, get_map_method_values());
  224. return LDAP_UNWILLING_TO_PERFORM;
  225. }
  226. if ((meth_to_int(ptr, &err) != PAMPT_MAP_METHOD_NONE) ||
  227. err) {
  228. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  229. "Invalid extra text [%s] after last map method",
  230. ((ptr && *ptr) ? *ptr : "(null)"));
  231. return LDAP_UNWILLING_TO_PERFORM;
  232. }
  233. return err;
  234. }
  235. static void
  236. print_suffixes()
  237. {
  238. void *cookie = NULL;
  239. Slapi_DN *sdn = NULL;
  240. slapi_log_error(SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
  241. "The following is the list of valid suffixes to use with "
  242. PAMPT_EXCLUDES_ATTR " and " PAMPT_INCLUDES_ATTR ":\n");
  243. for (sdn = slapi_get_first_suffix(&cookie, 1);
  244. sdn && cookie;
  245. sdn = slapi_get_next_suffix(&cookie, 1)) {
  246. slapi_log_error(SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
  247. "\t%s\n", slapi_sdn_get_dn(sdn));
  248. }
  249. }
  250. /*
  251. Validate the pending changes in the e entry.
  252. */
  253. static int
  254. pam_passthru_validate_config (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  255. int *returncode, char *returntext, void *arg)
  256. {
  257. char *missing_suffix_str = NULL;
  258. int missing_suffix;
  259. int ii;
  260. char **excludes = NULL;
  261. char **includes = NULL;
  262. char *pam_ident_attr = NULL;
  263. char *map_method = NULL;
  264. *returncode = LDAP_UNWILLING_TO_PERFORM; /* be pessimistic */
  265. /* first, get the missing_suffix flag and validate it */
  266. missing_suffix_str = slapi_entry_attr_get_charptr(e, PAMPT_MISSING_SUFFIX_ATTR);
  267. if ((missing_suffix = missing_suffix_to_int(missing_suffix_str)) < 0 ||
  268. !check_missing_suffix_flag(missing_suffix)) {
  269. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  270. "Error: valid values for %s are %s",
  271. PAMPT_MISSING_SUFFIX_ATTR, get_missing_suffix_values());
  272. goto done;
  273. }
  274. if (missing_suffix != PAMPT_MISSING_SUFFIX_IGNORE) {
  275. char **missing_list = NULL;
  276. /* get the list of excluded suffixes */
  277. excludes = slapi_entry_attr_get_charray(e, PAMPT_EXCLUDES_ATTR);
  278. for (ii = 0; excludes && excludes[ii]; ++ii) {
  279. Slapi_DN *comp_dn = slapi_sdn_new_dn_byref(excludes[ii]);
  280. if (!slapi_be_exist(comp_dn)) {
  281. charray_add(&missing_list, slapi_ch_strdup(excludes[ii]));
  282. }
  283. slapi_sdn_free(&comp_dn);
  284. }
  285. /* get the list of included suffixes */
  286. includes = slapi_entry_attr_get_charray(e, PAMPT_INCLUDES_ATTR);
  287. for (ii = 0; includes && includes[ii]; ++ii) {
  288. Slapi_DN *comp_dn = slapi_sdn_new_dn_byref(includes[ii]);
  289. if (!slapi_be_exist(comp_dn)) {
  290. charray_add(&missing_list, slapi_ch_strdup(includes[ii]));
  291. }
  292. slapi_sdn_free(&comp_dn);
  293. }
  294. if (missing_list) {
  295. PRUint32 size =
  296. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  297. "The following suffixes listed in %s or %s are not present in this "
  298. "server: ", PAMPT_EXCLUDES_ATTR, PAMPT_INCLUDES_ATTR);
  299. for (ii = 0; missing_list[ii]; ++ii) {
  300. if (size < SLAPI_DSE_RETURNTEXT_SIZE) {
  301. size += PR_snprintf(returntext+size, SLAPI_DSE_RETURNTEXT_SIZE-size,
  302. "%s%s", (ii > 0) ? "; " : "",
  303. missing_list[ii]);
  304. }
  305. }
  306. slapi_ch_array_free(missing_list);
  307. missing_list = NULL;
  308. print_suffixes();
  309. if (missing_suffix != PAMPT_MISSING_SUFFIX_ERROR) {
  310. slapi_log_error(SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
  311. "Warning: %s\n", returntext);
  312. *returntext = 0; /* log error, don't report back to user */
  313. } else {
  314. goto done;
  315. }
  316. }
  317. }
  318. pam_ident_attr = slapi_entry_attr_get_charptr(e, PAMPT_PAM_IDENT_ATTR);
  319. map_method = slapi_entry_attr_get_charptr(e, PAMPT_MAP_METHOD_ATTR);
  320. if (map_method) {
  321. int one, two, three;
  322. if (LDAP_SUCCESS !=
  323. (*returncode = parse_map_method(map_method, &one, &two, &three, returntext))) {
  324. goto done; /* returntext set already */
  325. }
  326. if (!pam_ident_attr &&
  327. ((one == PAMPT_MAP_METHOD_ENTRY) || (two == PAMPT_MAP_METHOD_ENTRY) ||
  328. (three == PAMPT_MAP_METHOD_ENTRY))) {
  329. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Error: the %s method"
  330. " was specified, but no %s was given",
  331. PAMPT_MAP_METHOD_ENTRY_STRING, PAMPT_PAM_IDENT_ATTR);
  332. *returncode = LDAP_UNWILLING_TO_PERFORM;
  333. goto done;
  334. }
  335. if ((one == PAMPT_MAP_METHOD_NONE) && (two == PAMPT_MAP_METHOD_NONE) &&
  336. (three == PAMPT_MAP_METHOD_NONE)) {
  337. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Error: no method(s)"
  338. " specified for %s, should be one or more of %s",
  339. PAMPT_MAP_METHOD_ATTR, get_map_method_values());
  340. *returncode = LDAP_UNWILLING_TO_PERFORM;
  341. goto done;
  342. }
  343. }
  344. /* success */
  345. *returncode = LDAP_SUCCESS;
  346. done:
  347. slapi_ch_free_string(&map_method);
  348. slapi_ch_free_string(&pam_ident_attr);
  349. slapi_ch_array_free(excludes);
  350. excludes = NULL;
  351. slapi_ch_array_free(includes);
  352. includes = NULL;
  353. slapi_ch_free_string(&missing_suffix_str);
  354. if (*returncode != LDAP_SUCCESS)
  355. {
  356. return SLAPI_DSE_CALLBACK_ERROR;
  357. }
  358. else
  359. {
  360. return SLAPI_DSE_CALLBACK_OK;
  361. }
  362. }
  363. static Pam_PassthruSuffix *
  364. New_Pam_PassthruSuffix(char *suffix)
  365. {
  366. Pam_PassthruSuffix *newone = NULL;
  367. if (suffix) {
  368. newone = (Pam_PassthruSuffix *)slapi_ch_malloc(sizeof(Pam_PassthruSuffix));
  369. newone->pamptsuffix_dn = slapi_sdn_new_dn_byval(suffix);
  370. newone->pamptsuffix_next = NULL;
  371. }
  372. return newone;
  373. }
  374. static Pam_PassthruSuffix *
  375. pam_ptconfig_add_suffixes(char **str_list)
  376. {
  377. Pam_PassthruSuffix *head = NULL;
  378. Pam_PassthruSuffix *suffixent = NULL;
  379. if (str_list && *str_list) {
  380. int ii;
  381. for (ii = 0; str_list[ii]; ++ii) {
  382. Pam_PassthruSuffix *tmp = New_Pam_PassthruSuffix(str_list[ii]);
  383. if (!suffixent) {
  384. head = suffixent = tmp;
  385. } else {
  386. suffixent->pamptsuffix_next = tmp;
  387. suffixent = suffixent->pamptsuffix_next;
  388. }
  389. }
  390. }
  391. return head;
  392. }
  393. static void
  394. Delete_Pam_PassthruSuffix(Pam_PassthruSuffix *one)
  395. {
  396. if (one) {
  397. slapi_sdn_free(&one->pamptsuffix_dn);
  398. slapi_ch_free((void **)&one);
  399. }
  400. }
  401. static void
  402. pam_ptconfig_free_suffixes(Pam_PassthruSuffix *list)
  403. {
  404. while (list) {
  405. Pam_PassthruSuffix *next = list->pamptsuffix_next;
  406. Delete_Pam_PassthruSuffix(list);
  407. list = next;
  408. }
  409. }
  410. /*
  411. Apply the pending changes in the e entry to our config struct.
  412. validate must have already been called
  413. */
  414. static int
  415. pam_passthru_apply_config (Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  416. int *returncode, char *returntext, void *arg)
  417. {
  418. char **excludes = NULL;
  419. char **includes = NULL;
  420. char *new_service = NULL;
  421. char *pam_ident_attr = NULL;
  422. char *map_method = NULL;
  423. PRBool fallback;
  424. PRBool secure;
  425. *returncode = LDAP_SUCCESS;
  426. pam_ident_attr = slapi_entry_attr_get_charptr(e, PAMPT_PAM_IDENT_ATTR);
  427. map_method = slapi_entry_attr_get_charptr(e, PAMPT_MAP_METHOD_ATTR);
  428. new_service = slapi_entry_attr_get_charptr(e, PAMPT_SERVICE_ATTR);
  429. excludes = slapi_entry_attr_get_charray(e, PAMPT_EXCLUDES_ATTR);
  430. includes = slapi_entry_attr_get_charray(e, PAMPT_INCLUDES_ATTR);
  431. fallback = slapi_entry_attr_get_bool(e, PAMPT_FALLBACK_ATTR);
  432. secure = slapi_entry_attr_get_bool(e, PAMPT_SECURE_ATTR);
  433. /* lock config here */
  434. slapi_lock_mutex(theConfig.lock);
  435. theConfig.pamptconfig_fallback = fallback;
  436. theConfig.pamptconfig_secure = secure;
  437. if (!theConfig.pamptconfig_service ||
  438. (new_service && PL_strcmp(theConfig.pamptconfig_service, new_service))) {
  439. slapi_ch_free_string(&theConfig.pamptconfig_service);
  440. theConfig.pamptconfig_service = new_service;
  441. new_service = NULL; /* config now owns memory */
  442. }
  443. /* get the list of excluded suffixes */
  444. pam_ptconfig_free_suffixes(theConfig.pamptconfig_excludes);
  445. theConfig.pamptconfig_excludes = pam_ptconfig_add_suffixes(excludes);
  446. /* get the list of included suffixes */
  447. pam_ptconfig_free_suffixes(theConfig.pamptconfig_includes);
  448. theConfig.pamptconfig_includes = pam_ptconfig_add_suffixes(includes);
  449. if (!theConfig.pamptconfig_pam_ident_attr ||
  450. (pam_ident_attr && PL_strcmp(theConfig.pamptconfig_pam_ident_attr, pam_ident_attr))) {
  451. slapi_ch_free_string(&theConfig.pamptconfig_pam_ident_attr);
  452. theConfig.pamptconfig_pam_ident_attr = pam_ident_attr;
  453. pam_ident_attr = NULL; /* config now owns memory */
  454. }
  455. if (map_method) {
  456. parse_map_method(map_method,
  457. &theConfig.pamptconfig_map_method1,
  458. &theConfig.pamptconfig_map_method2,
  459. &theConfig.pamptconfig_map_method3,
  460. NULL);
  461. }
  462. /* unlock config here */
  463. slapi_unlock_mutex(theConfig.lock);
  464. slapi_ch_free_string(&new_service);
  465. slapi_ch_free_string(&map_method);
  466. slapi_ch_free_string(&pam_ident_attr);
  467. slapi_ch_array_free(excludes);
  468. slapi_ch_array_free(includes);
  469. if (*returncode != LDAP_SUCCESS)
  470. {
  471. return SLAPI_DSE_CALLBACK_ERROR;
  472. }
  473. else
  474. {
  475. return SLAPI_DSE_CALLBACK_OK;
  476. }
  477. }
  478. int
  479. pam_passthru_check_suffix(Pam_PassthruConfig *cfg, char *binddn)
  480. {
  481. Slapi_DN *comp_dn;
  482. Pam_PassthruSuffix *try;
  483. int ret = LDAP_SUCCESS;
  484. comp_dn = slapi_sdn_new_dn_byref(binddn);
  485. slapi_lock_mutex(cfg->lock);
  486. if (!cfg->pamptconfig_includes && !cfg->pamptconfig_excludes) {
  487. goto done; /* NULL means allow */
  488. }
  489. /* exclude trumps include - if suffix is on exclude list, then
  490. deny */
  491. for (try = cfg->pamptconfig_excludes; try; try = try->pamptsuffix_next) {
  492. if (slapi_sdn_issuffix(comp_dn, try->pamptsuffix_dn)) {
  493. ret = LDAP_UNWILLING_TO_PERFORM; /* suffix is excluded */
  494. goto done;
  495. }
  496. }
  497. /* ok, now flip it - deny access unless dn is on include list */
  498. if (cfg->pamptconfig_includes) {
  499. ret = LDAP_UNWILLING_TO_PERFORM; /* suffix is excluded */
  500. for (try = cfg->pamptconfig_includes; try; try = try->pamptsuffix_next) {
  501. if (slapi_sdn_issuffix(comp_dn, try->pamptsuffix_dn)) {
  502. ret = LDAP_SUCCESS; /* suffix is included */
  503. goto done;
  504. }
  505. }
  506. }
  507. done:
  508. slapi_unlock_mutex(cfg->lock);
  509. slapi_sdn_free(&comp_dn);
  510. return ret;
  511. }
  512. /*
  513. * Get the pass though configuration data. For now, there is only one
  514. * configuration and it is global to the plugin.
  515. */
  516. Pam_PassthruConfig *
  517. pam_passthru_get_config( void )
  518. {
  519. return( &theConfig );
  520. }