/lib/libpam/libpam/pam_static.c

https://github.com/rhuitl/uClinux · C · 140 lines · 53 code · 21 blank · 66 comment · 18 complexity · a5f2cac1403094ea798504a73e73ceca MD5 · raw file

  1. /* pam_static.c -- static module loading helper functions */
  2. /* created by Michael K. Johnson, johnsonm@redhat.com
  3. *
  4. * $Id: pam_static.c,v 1.3 2005/09/04 20:32:25 kukuk Exp $
  5. */
  6. /* This whole file is only used for PAM_STATIC */
  7. #ifdef PAM_STATIC
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include "pam_private.h"
  12. /*
  13. * Need to include pointers to static modules; this was built by each
  14. * of the modules that register...
  15. */
  16. #include "../modules/_static_module_list"
  17. /*
  18. * and here is a structure that connects libpam to the above static
  19. * modules
  20. */
  21. static struct pam_module *static_modules[] = {
  22. #include "../modules/_static_module_entry"
  23. NULL
  24. };
  25. /*
  26. * and now for the functions
  27. */
  28. /* Return pointer to data structure used to define a static module */
  29. struct pam_module * _pam_open_static_handler(const char *path)
  30. {
  31. int i;
  32. const char *clpath = path;
  33. char *lpath, *end;
  34. if (strchr(clpath, '/')) {
  35. /* ignore path and leading "/" */
  36. clpath = strrchr(path, '/') + 1;
  37. }
  38. /* create copy to muck with (must free before return) */
  39. lpath = _pam_strdup(clpath);
  40. /* chop .so off copy if it exists (or other extension on other
  41. platform...) */
  42. end = strstr(lpath, ".so");
  43. if (end) {
  44. *end = '\0';
  45. }
  46. /* now go find the module */
  47. for (i = 0; static_modules[i] != NULL; i++) {
  48. D(("%s=?%s\n", lpath, static_modules[i]->name));
  49. if (static_modules[i]->name &&
  50. ! strcmp(static_modules[i]->name, lpath)) {
  51. break;
  52. }
  53. }
  54. if (static_modules[i] == NULL) {
  55. pam_syslog (pamh, LOG_ERR, "no static module named %s", lpath);
  56. }
  57. free(lpath);
  58. return (static_modules[i]);
  59. }
  60. /* Return pointer to function requested from static module
  61. * Can't just return void *, because ANSI C disallows casting a
  62. * pointer to a function to a void *...
  63. * This definition means:
  64. * _pam_get_static_sym is a function taking two arguments and
  65. * returning a pointer to a function which takes no arguments
  66. * and returns void... */
  67. voidfunc *_pam_get_static_sym(struct pam_module *mod, const char *symname) {
  68. if (! strcmp(symname, "pam_sm_authenticate")) {
  69. return ((voidfunc *)mod->pam_sm_authenticate);
  70. } else if (! strcmp(symname, "pam_sm_setcred")) {
  71. return ((voidfunc *)mod->pam_sm_setcred);
  72. } else if (! strcmp(symname, "pam_sm_acct_mgmt")) {
  73. return ((voidfunc *)mod->pam_sm_acct_mgmt);
  74. } else if (! strcmp(symname, "pam_sm_open_session")) {
  75. return ((voidfunc *)mod->pam_sm_open_session);
  76. } else if (! strcmp(symname, "pam_sm_close_session")) {
  77. return ((voidfunc *)mod->pam_sm_close_session);
  78. } else if (! strcmp(symname, "pam_sm_chauthtok")) {
  79. return ((voidfunc *)mod->pam_sm_chauthtok);
  80. }
  81. /* getting to this point is an error */
  82. return ((voidfunc *)NULL);
  83. }
  84. #endif /* PAM_STATIC */
  85. /*
  86. * Copyright (C) 1995 by Red Hat Software, Michael K. Johnson
  87. * All rights reserved
  88. *
  89. * Redistribution and use in source and binary forms, with or without
  90. * modification, are permitted provided that the following conditions
  91. * are met:
  92. * 1. Redistributions of source code must retain the above copyright
  93. * notice, and the entire permission notice in its entirety,
  94. * including the disclaimer of warranties.
  95. * 2. Redistributions in binary form must reproduce the above copyright
  96. * notice, this list of conditions and the following disclaimer in the
  97. * documentation and/or other materials provided with the distribution.
  98. * 3. The name of the author may not be used to endorse or promote
  99. * products derived from this software without specific prior
  100. * written permission.
  101. *
  102. * ALTERNATIVELY, this product may be distributed under the terms of
  103. * the GNU Public License, in which case the provisions of the GPL are
  104. * required INSTEAD OF the above restrictions. (This clause is
  105. * necessary due to a potential bad interaction between the GPL and
  106. * the restrictions contained in a BSD-style copyright.)
  107. *
  108. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  109. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  110. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  111. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  112. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  113. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  114. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  115. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  116. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  117. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  118. * OF THE POSSIBILITY OF SUCH DAMAGE.
  119. */