OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

285 lines
8.1 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../heimdal/hdb-ldap-get_values.patch
  5. # Copyright (C) 2008 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. Index: heimdal/lib/hdb/hdb-ldap.c
  17. ===================================================================
  18. --- heimdal/lib/hdb/hdb-ldap.c (revision 22586)
  19. +++ heimdal/lib/hdb/hdb-ldap.c (revision 22587)
  20. @@ -1,7 +1,7 @@
  21. /*
  22. * Copyright (c) 1999-2001, 2003, PADL Software Pty Ltd.
  23. * Copyright (c) 2004, Andrew Bartlett.
  24. - * Copyright (c) 2003 - 2007, Kungliga Tekniska H�gskolan.
  25. + * Copyright (c) 2003 - 2008, Kungliga Tekniska H�gskolan.
  26. * All rights reserved.
  27. *
  28. * Redistribution and use in source and binary forms, with or without
  29. @@ -307,38 +307,40 @@
  30. LDAP_get_string_value(HDB * db, LDAPMessage * entry,
  31. const char *attribute, char **ptr)
  32. {
  33. - char **vals;
  34. - int ret;
  35. + struct berval **vals;
  36. - vals = ldap_get_values(HDB2LDAP(db), entry, (char *) attribute);
  37. - if (vals == NULL) {
  38. + vals = ldap_get_values_len(HDB2LDAP(db), entry, attribute);
  39. + if (vals == NULL || vals[0] == NULL) {
  40. *ptr = NULL;
  41. return HDB_ERR_NOENTRY;
  42. }
  43. - *ptr = strdup(vals[0]);
  44. - if (*ptr == NULL)
  45. - ret = ENOMEM;
  46. - else
  47. - ret = 0;
  48. + *ptr = malloc(vals[0]->bv_len + 1);
  49. + if (*ptr == NULL) {
  50. + ldap_value_free_len(vals);
  51. + return ENOMEM;
  52. + }
  53. - ldap_value_free(vals);
  54. + memcpy(*ptr, vals[0]->bv_val, vals[0]->bv_len);
  55. + (*ptr)[vals[0]->bv_len] = 0;
  56. - return ret;
  57. + ldap_value_free_len(vals);
  58. +
  59. + return 0;
  60. }
  61. static krb5_error_code
  62. LDAP_get_integer_value(HDB * db, LDAPMessage * entry,
  63. const char *attribute, int *ptr)
  64. {
  65. - char **vals;
  66. + krb5_error_code ret;
  67. + char *val;
  68. - vals = ldap_get_values(HDB2LDAP(db), entry, (char *) attribute);
  69. - if (vals == NULL)
  70. - return HDB_ERR_NOENTRY;
  71. -
  72. - *ptr = atoi(vals[0]);
  73. - ldap_value_free(vals);
  74. + ret = LDAP_get_string_value(db, entry, attribute, &val);
  75. + if (ret)
  76. + return ret;
  77. + *ptr = atoi(val);
  78. + free(val);
  79. return 0;
  80. }
  81. @@ -369,6 +371,14 @@
  82. return 0;
  83. }
  84. +static int
  85. +bervalstrcmp(struct berval *v, const char *str)
  86. +{
  87. + size_t len = strlen(str);
  88. + return (v->bv_len == len) && strncasecmp(str, (char *)v->bv_val, len) == 0;
  89. +}
  90. +
  91. +
  92. static krb5_error_code
  93. LDAP_entry2mods(krb5_context context, HDB * db, hdb_entry_ex * ent,
  94. LDAPMessage * msg, LDAPMod *** pmods)
  95. @@ -386,7 +396,7 @@
  96. krb5_boolean is_heimdal_entry = FALSE;
  97. krb5_boolean is_heimdal_principal = FALSE;
  98. - char **values;
  99. + struct berval **vals;
  100. *pmods = NULL;
  101. @@ -398,21 +408,20 @@
  102. is_new_entry = FALSE;
  103. - values = ldap_get_values(HDB2LDAP(db), msg, "objectClass");
  104. - if (values) {
  105. - int num_objectclasses = ldap_count_values(values);
  106. + vals = ldap_get_values_len(HDB2LDAP(db), msg, "objectClass");
  107. + if (vals) {
  108. + int num_objectclasses = ldap_count_values_len(vals);
  109. for (i=0; i < num_objectclasses; i++) {
  110. - if (strcasecmp(values[i], "sambaSamAccount") == 0) {
  111. + if (bervalstrcmp(vals[i], "sambaSamAccount"))
  112. is_samba_account = TRUE;
  113. - } else if (strcasecmp(values[i], structural_object) == 0) {
  114. + else if (bervalstrcmp(vals[i], structural_object))
  115. is_account = TRUE;
  116. - } else if (strcasecmp(values[i], "krb5Principal") == 0) {
  117. + else if (bervalstrcmp(vals[i], "krb5Principal"))
  118. is_heimdal_principal = TRUE;
  119. - } else if (strcasecmp(values[i], "krb5KDCEntry") == 0) {
  120. + else if (bervalstrcmp(vals[i], "krb5KDCEntry"))
  121. is_heimdal_entry = TRUE;
  122. - }
  123. }
  124. - ldap_value_free(values);
  125. + ldap_value_free_len(vals);
  126. }
  127. /*
  128. @@ -602,9 +611,9 @@
  129. /* Remove keys if they exists, and then replace keys. */
  130. if (!is_new_entry && orig.entry.keys.len > 0) {
  131. - values = ldap_get_values(HDB2LDAP(db), msg, "krb5Key");
  132. - if (values) {
  133. - ldap_value_free(values);
  134. + vals = ldap_get_values_len(HDB2LDAP(db), msg, "krb5Key");
  135. + if (vals) {
  136. + ldap_value_free_len(vals);
  137. ret = LDAP_addmod(&mods, LDAP_MOD_DELETE, "krb5Key", NULL);
  138. if (ret)
  139. @@ -641,9 +650,9 @@
  140. goto out;
  141. /* have to kill the LM passwod if it exists */
  142. - values = ldap_get_values(HDB2LDAP(db), msg, "sambaLMPassword");
  143. - if (values) {
  144. - ldap_value_free(values);
  145. + vals = ldap_get_values_len(HDB2LDAP(db), msg, "sambaLMPassword");
  146. + if (vals) {
  147. + ldap_value_free_len(vals);
  148. ret = LDAP_addmod(&mods, LDAP_MOD_DELETE,
  149. "sambaLMPassword", NULL);
  150. if (ret)
  151. @@ -676,9 +685,9 @@
  152. */
  153. if (!is_new_entry) {
  154. - values = ldap_get_values(HDB2LDAP(db), msg, "krb5EncryptionType");
  155. - if (values) {
  156. - ldap_value_free(values);
  157. + vals = ldap_get_values_len(HDB2LDAP(db), msg, "krb5EncryptionType");
  158. + if (vals) {
  159. + ldap_value_free_len(vals);
  160. ret = LDAP_addmod(&mods, LDAP_MOD_DELETE, "krb5EncryptionType",
  161. NULL);
  162. if (ret)
  163. @@ -730,8 +739,8 @@
  164. krb5_error_code ret;
  165. int rc;
  166. const char *filter = "(objectClass=krb5Principal)";
  167. - char **values;
  168. LDAPMessage *res = NULL, *e;
  169. + char *p;
  170. ret = LDAP_no_size_limit(context, HDB2LDAP(db));
  171. if (ret)
  172. @@ -753,14 +762,14 @@
  173. goto out;
  174. }
  175. - values = ldap_get_values(HDB2LDAP(db), e, "krb5PrincipalName");
  176. - if (values == NULL) {
  177. + ret = LDAP_get_string_value(db, e, "krb5PrincipalName", &p);
  178. + if (ret) {
  179. ret = HDB_ERR_NOENTRY;
  180. goto out;
  181. }
  182. - ret = krb5_parse_name(context, values[0], principal);
  183. - ldap_value_free(values);
  184. + ret = krb5_parse_name(context, p, principal);
  185. + free(p);
  186. out:
  187. if (res)
  188. @@ -893,10 +902,9 @@
  189. {
  190. char *unparsed_name = NULL, *dn = NULL, *ntPasswordIN = NULL;
  191. char *samba_acct_flags = NULL;
  192. - unsigned long tmp;
  193. struct berval **keys;
  194. - char **values;
  195. - int tmp_time, i, ret, have_arcfour = 0;
  196. + struct berval **vals;
  197. + int tmp, tmp_time, i, ret, have_arcfour = 0;
  198. memset(ent, 0, sizeof(*ent));
  199. ent->entry.flags = int2HDBFlags(0);
  200. @@ -962,8 +970,8 @@
  201. #endif
  202. }
  203. - values = ldap_get_values(HDB2LDAP(db), msg, "krb5EncryptionType");
  204. - if (values != NULL) {
  205. + vals = ldap_get_values_len(HDB2LDAP(db), msg, "krb5EncryptionType");
  206. + if (vals != NULL) {
  207. int i;
  208. ent->entry.etypes = malloc(sizeof(*(ent->entry.etypes)));
  209. @@ -972,17 +980,26 @@
  210. ret = ENOMEM;
  211. goto out;
  212. }
  213. - ent->entry.etypes->len = ldap_count_values(values);
  214. + ent->entry.etypes->len = ldap_count_values_len(vals);
  215. ent->entry.etypes->val = calloc(ent->entry.etypes->len, sizeof(int));
  216. if (ent->entry.etypes->val == NULL) {
  217. krb5_set_error_string(context, "malloc: out of memory");
  218. + ent->entry.etypes->len = 0;
  219. ret = ENOMEM;
  220. goto out;
  221. }
  222. for (i = 0; i < ent->entry.etypes->len; i++) {
  223. - ent->entry.etypes->val[i] = atoi(values[i]);
  224. + char buf[100];
  225. + if (vals[i]->bv_len > sizeof(buf) - 1) {
  226. + krb5_set_error_string(context, "malloc: out of memory");
  227. + ret = ENOMEM;
  228. + goto out;
  229. + }
  230. + memcpy(buf, vals[i]->bv_val, vals[i]->bv_len);
  231. + buf[vals[i]->bv_len] = '\0';
  232. + ent->entry.etypes->val[i] = atoi(buf);
  233. }
  234. - ldap_value_free(values);
  235. + ldap_value_free_len(vals);
  236. }
  237. for (i = 0; i < ent->entry.keys.len; i++) {
  238. @@ -1193,18 +1210,9 @@
  239. *ent->entry.max_renew = max_renew;
  240. }
  241. - values = ldap_get_values(HDB2LDAP(db), msg, "krb5KDCFlags");
  242. - if (values != NULL) {
  243. - errno = 0;
  244. - tmp = strtoul(values[0], (char **) NULL, 10);
  245. - if (tmp == ULONG_MAX && errno == ERANGE) {
  246. - krb5_set_error_string(context, "strtoul: could not convert flag");
  247. - ret = ERANGE;
  248. - goto out;
  249. - }
  250. - } else {
  251. + ret = LDAP_get_integer_value(db, msg, "krb5KDCFlags", &tmp);
  252. + if (ret)
  253. tmp = 0;
  254. - }
  255. ent->entry.flags = int2HDBFlags(tmp);