1
0

lasuser.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* lasuser.c
  42. * This file contains the User LAS code.
  43. */
  44. #include <netsite.h>
  45. #include <base/shexp.h>
  46. #include <base/util.h>
  47. #include <libaccess/las.h>
  48. #include <libaccess/dbtlibaccess.h>
  49. #include <libaccess/aclerror.h>
  50. #include "aclutil.h"
  51. #ifdef UTEST
  52. extern char * LASUserGetUser();
  53. #endif
  54. /*
  55. * LASUserEval
  56. * INPUT
  57. * attr_name The string "user" - in lower case.
  58. * comparator CMP_OP_EQ or CMP_OP_NE only
  59. * attr_pattern A comma-separated list of users
  60. * *cachable Always set to ACL_NOT_CACHABLE.
  61. * subject Subject property list
  62. * resource Resource property list
  63. * auth_info Authentication info, if any
  64. * RETURNS
  65. * retcode The usual LAS return codes.
  66. */
  67. int LASUserEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  68. char *attr_pattern, ACLCachable_t *cachable,
  69. void **LAS_cookie, PList_t subject, PList_t resource,
  70. PList_t auth_info, PList_t global_auth)
  71. {
  72. char *uid;
  73. char *users;
  74. char *user;
  75. char *comma;
  76. int retcode;
  77. int matched;
  78. int is_owner;
  79. int rv;
  80. *cachable = ACL_NOT_CACHABLE;
  81. *LAS_cookie = (void *)0;
  82. if (strcmp(attr_name, ACL_ATTR_USER) != 0) {
  83. nserrGenerate(errp, ACLERRINVAL, ACLERR5700, ACL_Program, 2, XP_GetAdminStr(DBT_lasUserEvalReceivedRequestForAtt_), attr_name);
  84. return LAS_EVAL_INVALID;
  85. }
  86. if ((comparator != CMP_OP_EQ) && (comparator != CMP_OP_NE)) {
  87. nserrGenerate(errp, ACLERRINVAL, ACLERR5710, ACL_Program, 2, XP_GetAdminStr(DBT_lasuserevalIllegalComparatorDN_), comparator_string(comparator));
  88. return LAS_EVAL_INVALID;
  89. }
  90. if (!strcmp(attr_pattern, "anyone")) {
  91. *cachable = ACL_INDEF_CACHABLE;
  92. return comparator == CMP_OP_EQ ? LAS_EVAL_TRUE : LAS_EVAL_FALSE;
  93. }
  94. /* get the authenticated user name */
  95. #ifndef UTEST
  96. rv = ACL_GetAttribute(errp, ACL_ATTR_USER, (void **)&uid,
  97. subject, resource, auth_info, global_auth);
  98. if (rv != LAS_EVAL_TRUE) {
  99. return rv;
  100. }
  101. #else
  102. uid = (char *)LASUserGetUser();
  103. #endif
  104. /* We have an authenticated user */
  105. if (!strcmp(attr_pattern, "all")) {
  106. return comparator == CMP_OP_EQ ? LAS_EVAL_TRUE : LAS_EVAL_FALSE;
  107. }
  108. users = STRDUP(attr_pattern);
  109. if (!users) {
  110. nserrGenerate(errp, ACLERRNOMEM, ACLERR5720, ACL_Program, 1,
  111. XP_GetAdminStr(DBT_lasuserevalRanOutOfMemoryN_));
  112. return LAS_EVAL_FAIL;
  113. }
  114. user = users;
  115. matched = 0;
  116. /* check if the uid is one of the users */
  117. while(user != 0 && *user != 0 && !matched) {
  118. if ((comma = strchr(user, ',')) != NULL) {
  119. *comma++ = 0;
  120. }
  121. /* ignore leading whitespace */
  122. while(*user == ' ' || *user == '\t') user++;
  123. if (*user) {
  124. /* ignore trailing whitespace */
  125. int len = strlen(user);
  126. char *ptr = user+len-1;
  127. while(*ptr == ' ' || *ptr == '\t') *ptr-- = 0;
  128. }
  129. if (!strcasecmp(user, ACL_ATTR_OWNER)) {
  130. rv = ACL_GetAttribute(errp, ACL_ATTR_IS_OWNER, (void **)&is_owner,
  131. subject, resource, auth_info, global_auth);
  132. if (rv == LAS_EVAL_TRUE)
  133. matched = 1;
  134. else
  135. /* continue checking for next user */
  136. user = comma;
  137. }
  138. else if (!WILDPAT_CASECMP(uid, user)) {
  139. /* uid is one of the users */
  140. matched = 1;
  141. }
  142. else {
  143. /* continue checking for next user */
  144. user = comma;
  145. }
  146. }
  147. if (comparator == CMP_OP_EQ) {
  148. retcode = (matched ? LAS_EVAL_TRUE : LAS_EVAL_FALSE);
  149. }
  150. else {
  151. retcode = (matched ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  152. }
  153. FREE(users);
  154. return retcode;
  155. }
  156. /* LASUserFlush
  157. * Deallocates any memory previously allocated by the LAS
  158. */
  159. void
  160. LASUserFlush(void **las_cookie)
  161. {
  162. /* do nothing */
  163. return;
  164. }