PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/slapi-nis-0.42/src/defs-nis.c

#
C | 363 lines | 335 code | 8 blank | 20 comment | 50 complexity | 9d67abc46df7aa6620813518aa4cc687 MD5 | raw file
  1. /*
  2. * Copyright 2008,2009,2011,2012 Red Hat, Inc.
  3. *
  4. * This Program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * This Program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this Program; if not, write to the
  15. *
  16. * Free Software Foundation, Inc.
  17. * 59 Temple Place, Suite 330
  18. * Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include "config.h"
  23. #endif
  24. #include <rpc/xdr.h>
  25. #include <fnmatch.h>
  26. #include <paths.h>
  27. #include <string.h>
  28. #include "defs-nis.h"
  29. #define DEFAULT_ENTRY_FILTER "(&(nisMapName=%m)(objectClass=nisObject))"
  30. #define DEFAULT_KEY_FORMAT NULL
  31. #define DEFAULT_KEYS_FORMAT "%{cn}"
  32. #define DEFAULT_VALUE_FORMAT "%{nisMapEntry}"
  33. #define DEFAULT_VALUES_FORMAT NULL
  34. #define DEFAULT_DISALLOWED_CHARS NULL
  35. #define DEFAULT_MAP_SECURE FALSE
  36. #define DEFAULT_CONFIGURATION_SUFFIX "cn=NIS Server, cn=plugins, cn=config"
  37. static struct configuration {
  38. char *map;
  39. enum { config_exact, config_glob } config_match;
  40. bool_t secure;
  41. char *base;
  42. char *filter;
  43. char *key_format, *keys_format, *value_format, *values_format;
  44. char *disallowed_chars;
  45. } config[] = {
  46. {"passwd.byname", config_exact, FALSE, NULL,
  47. "(objectClass=posixAccount)",
  48. "%{uid}", NULL,
  49. "%{uid}:%regsubi(\"%{userPassword}\",\"^\\\\{CRYPT\\\\}(..*)\",\"%1\",\"*\"):%regmatch(\"%{uidNumber}\",\"[0-9]+\"):%regmatch(\"%{gidNumber}\",\"[0-9]+\"):%{gecos:-%{cn:-}}:%{homeDirectory:-/}:%{loginShell:-" _PATH_BSHELL "}", NULL,
  50. ":\r\n"},
  51. {"passwd.byuid", config_exact, FALSE, NULL,
  52. "(objectClass=posixAccount)",
  53. "%{uidNumber}", NULL,
  54. "%{uid}:%regsubi(\"%{userPassword}\",\"^\\\\{CRYPT\\\\}(..*)\",\"%1\",\"*\"):%regmatch(\"%{uidNumber}\",\"[0-9]+\"):%regmatch(\"%{gidNumber}\",\"[0-9]+\"):%{gecos:-%{cn:-}}:%{homeDirectory:-/}:%{loginShell:-" _PATH_BSHELL "}", NULL,
  55. ":\r\n"},
  56. {"group.byname", config_exact, FALSE, NULL,
  57. "(objectClass=posixGroup)",
  58. "%{cn}", NULL,
  59. "%{cn}:%regsubi(\"%{userPassword}\",\"^\\\\{CRYPT\\\\}(..*)\",\"%1\",\"*\"):%regmatch(\"%{gidNumber}\",\"[0-9]+\"):%merge(\",\",\"%{memberUid}\",\"%deref_r(\\\"member\\\",\\\"uid\\\")\",\"%deref_r(\\\"uniqueMember\\\",\\\"uid\\\")\")", NULL,
  60. ":,\r\n"},
  61. {"group.bygid", config_exact, FALSE, NULL,
  62. "(objectClass=posixGroup)",
  63. "%{gidNumber}", NULL,
  64. "%{cn}:%regsubi(\"%{userPassword}\",\"^\\\\{CRYPT\\\\}(..*)\",\"%1\",\"*\"):%{gidNumber}:%merge(\",\",\"%{memberUid}\",\"%deref_r(\\\"member\\\",\\\"uid\\\")\",\"%deref_r(\\\"uniqueMember\\\",\\\"uid\\\")\")", NULL,
  65. ":,\r\n"},
  66. {"netgroup", config_exact, FALSE, NULL,
  67. "(objectClass=nisNetgroup)",
  68. "%{cn}", NULL,
  69. "%merge(\" \",\"%{nisNetgroupTriple}\",\"%{memberNisNetgroup}\")", NULL,
  70. NULL},
  71. {"auto.*", config_glob, FALSE, NULL,
  72. "(objectClass=automount)",
  73. NULL, "%{automountKey}",
  74. "%{automountInformation}", NULL,
  75. NULL},
  76. {"ethers.byaddr", config_exact, FALSE, NULL,
  77. "(&(macAddress=*)(cn=*)(objectclass=ieee802device))",
  78. NULL,
  79. "%mregsub(\"%{macaddress} %{cn}\",\"(..:..:..:..:..:..) (.*)\",\"%2\")",
  80. NULL,
  81. "%{macaddress} %{cn}",
  82. NULL},
  83. {"ethers.byname", config_exact, FALSE, NULL,
  84. "(&(macAddress=*)(cn=*)(objectclass=ieee802device))",
  85. NULL,
  86. "%mregsub(\"%{macaddress} %{cn}\",\"(..:..:..:..:..:..) (.*)\",\"%1\")",
  87. NULL,
  88. "%{macaddress} %{cn}",
  89. NULL},
  90. {"hosts.byaddr", config_exact, FALSE, NULL,
  91. "(&(ipHostNumber=*)(cn=*))",
  92. "%{ipHostNumber}", NULL,
  93. "%first(\"%{cn}\") %{ipHostNumber} %merge(\" \",\"%{cn}\")", NULL,
  94. NULL},
  95. {"hosts.byname", config_exact, FALSE, NULL,
  96. "(&(ipHostNumber=*)(cn=*))",
  97. NULL, "%{cn}",
  98. "%first(\"%{cn}\") %{ipHostNumber} %merge(\" \",\"%{cn}\")", NULL,
  99. NULL},
  100. {"mail.aliases", config_exact, FALSE, NULL,
  101. "(objectClass=nisMailAlias)",
  102. NULL, "%{cn}",
  103. "%merge(\",\",\"%{rfc822MailMember}\")", NULL,
  104. NULL},
  105. {"mail.byaddr", config_exact, FALSE, NULL,
  106. "(objectClass=nisMailAlias)",
  107. NULL, "%{rfc822MailMember}",
  108. "%merge(\",\",\"%{cn}\")", NULL,
  109. NULL},
  110. {"netgroup.byhost", config_exact, FALSE, NULL, /* XXX */
  111. "(objectClass=nisNetgroup)",
  112. NULL, NULL,
  113. NULL, NULL,
  114. NULL},
  115. {"netgroup.byuser", config_exact, FALSE, NULL, /* XXX */
  116. "(objectClass=nisNetgroup)",
  117. NULL, NULL,
  118. NULL, NULL,
  119. NULL},
  120. {"netid.byname", config_exact, FALSE, NULL,
  121. "(objectClass=posixAccount)",
  122. "unix.%{uidNumber}", NULL,
  123. "%{uidNumber}:%merge(\",\",\"%{gidNumber}\",\"%deref_r(\\\"memberOf\\\",\\\"gidNumber\\\")\",\"%referred_r(\\\"group.byname\\\",\\\"member\\\",\\\"gidNumber\\\")\",\"%referred_r(\\\"group.byname\\\",\\\"uniqueMember\\\",\\\"gidNumber\\\")\")", NULL,
  124. NULL},
  125. {"networks.byaddr", config_exact, FALSE, NULL,
  126. "(objectClass=ipNetwork)",
  127. "%{ipNetworkNumber}", NULL,
  128. "%first(\"%{cn}\") %{ipNetworkNumber} %merge(\" \",\"%{cn}\")", NULL,
  129. NULL},
  130. {"networks.byname", config_exact, FALSE, NULL,
  131. "(objectClass=ipNetwork)",
  132. NULL, "%{cn}",
  133. "%first(\"%{cn}\") %{ipNetworkNumber} %merge(\" \",\"%{cn}\")", NULL,
  134. NULL},
  135. {"protocols.byname", config_exact, FALSE, NULL,
  136. "(objectClass=ipProtocol)",
  137. NULL, "%{cn}",
  138. "%first(\"%{cn}\") %{ipProtocolNumber} %merge(\" \",\"%{cn}\")", NULL,
  139. NULL},
  140. {"protocols.bynumber", config_exact, FALSE, NULL,
  141. "(objectClass=ipProtocol)",
  142. "%{ipProtocolNumber}", NULL,
  143. "%first(\"%{cn}\") %{ipProtocolNumber} %merge(\" \",\"%{cn}\")", NULL,
  144. NULL},
  145. {"rpc.byname", config_exact, FALSE, NULL,
  146. "(objectClass=oncRpc)",
  147. NULL, "%{cn}",
  148. "%first(\"%{cn}\") %{oncRpcNumber} %merge(\" \",\"%{cn}\")", NULL,
  149. NULL},
  150. {"rpc.bynumber", config_exact, FALSE, NULL,
  151. "(objectClass=oncRpc)",
  152. "%{oncRpcNumber}", NULL,
  153. "%first(\"%{cn}\") %{oncRpcNumber} %merge(\" \",\"%{cn}\")", NULL,
  154. NULL},
  155. {"services.byname", config_exact, FALSE, NULL,
  156. "(objectClass=ipService)",
  157. NULL, "%{ipServicePort}/%{ipServiceProtocol}",
  158. NULL, "%first(\"%{cn}\") %{ipServicePort}/%{ipServiceProtocol} %merge(\" \",\"%{cn}\")",
  159. NULL},
  160. {"services.byservicename", config_exact, FALSE, NULL,
  161. "(objectClass=ipService)",
  162. NULL, "%{cn}/%{ipServiceProtocol}",
  163. NULL, "%{cn} %{ipServicePort}/%{ipServiceProtocol} %merge(\" \",\"%{cn}\")",
  164. NULL},
  165. {"ypservers", config_exact, FALSE,
  166. "cn=nis-servers, " DEFAULT_CONFIGURATION_SUFFIX,
  167. "(&(" NIS_MAP_CONFIGURATION_MAP_ATTR "=nis-servers)"
  168. "(" NIS_MAP_CONFIGURATION_DOMAIN_ATTR "=%d)"
  169. "(" NIS_PLUGIN_CONFIGURATION_SERVER_ATTR "=*))",
  170. NULL, "%{" NIS_PLUGIN_CONFIGURATION_SERVER_ATTR "}",
  171. NULL, "%{" NIS_PLUGIN_CONFIGURATION_SERVER_ATTR "}",
  172. NULL},
  173. };
  174. void
  175. defaults_get_map_config(const char *mapname,
  176. bool_t *secure,
  177. const char **filter,
  178. const char **key_format,
  179. const char **keys_format,
  180. const char **value_format,
  181. const char **values_format,
  182. const char **disallowed_chars)
  183. {
  184. unsigned int i;
  185. for (i = 0; i < sizeof(config) / sizeof(config[0]); i++) {
  186. bool_t match;
  187. match = FALSE;
  188. switch (config[i].config_match) {
  189. case config_exact:
  190. if (strcmp(config[i].map, mapname) == 0) {
  191. match = TRUE;
  192. }
  193. break;
  194. case config_glob:
  195. if (fnmatch(config[i].map, mapname,
  196. FNM_NOESCAPE) == 0) {
  197. match = TRUE;
  198. }
  199. break;
  200. }
  201. if (!match) {
  202. continue;
  203. }
  204. if (secure) {
  205. *secure = config[i].secure;
  206. }
  207. if (filter) {
  208. *filter = config[i].filter;
  209. }
  210. if (key_format) {
  211. *key_format = config[i].key_format;
  212. }
  213. if (keys_format) {
  214. *keys_format = config[i].keys_format;
  215. }
  216. if (value_format) {
  217. *value_format = config[i].value_format;
  218. }
  219. if (values_format) {
  220. *values_format = config[i].values_format;
  221. }
  222. if (disallowed_chars) {
  223. *disallowed_chars = config[i].disallowed_chars;
  224. }
  225. break;
  226. }
  227. if (i >= (sizeof(config) / sizeof(config[0]))) {
  228. if (secure) {
  229. *secure = DEFAULT_MAP_SECURE;
  230. }
  231. if (filter) {
  232. *filter = DEFAULT_ENTRY_FILTER;
  233. }
  234. if (key_format) {
  235. *key_format = DEFAULT_KEY_FORMAT;
  236. }
  237. if (keys_format) {
  238. *keys_format = DEFAULT_KEYS_FORMAT;
  239. }
  240. if (value_format) {
  241. *value_format = DEFAULT_VALUE_FORMAT;
  242. }
  243. if (values_format) {
  244. *values_format = DEFAULT_VALUES_FORMAT;
  245. }
  246. if (disallowed_chars) {
  247. *disallowed_chars = DEFAULT_DISALLOWED_CHARS;
  248. }
  249. }
  250. }
  251. #ifdef DEFS_NIS_MAIN
  252. #include <getopt.h>
  253. static void
  254. usage(const char *argv0)
  255. {
  256. fprintf(stderr, "Usage: %s [-d domain] [-s suffix] [-m map]\n",
  257. strchr(argv0, '/') ? strrchr(argv0, '/') + 1 : argv0);
  258. }
  259. int
  260. main(int argc, char **argv)
  261. {
  262. unsigned int i;
  263. int c;
  264. const char *domain, *suffix, *map;
  265. domain = "@domain@";
  266. suffix = "@suffix@";
  267. map = "*";
  268. while ((c = getopt(argc, argv, "d:s:m:")) != -1) {
  269. switch (c) {
  270. case 'd':
  271. domain = optarg;
  272. break;
  273. case 's':
  274. suffix = optarg;
  275. break;
  276. case 'm':
  277. map = optarg;
  278. break;
  279. default:
  280. usage(argv[0]);
  281. return 1;
  282. break;
  283. }
  284. }
  285. if (optind != argc) {
  286. usage(argv[0]);
  287. return 1;
  288. }
  289. for (i = 0; i < sizeof(config) / sizeof(config[0]); i++) {
  290. if (fnmatch(map, config[i].map, 0) != 0) {
  291. continue;
  292. }
  293. if ((config[i].key_format == NULL) &&
  294. (config[i].keys_format == NULL)) {
  295. continue;
  296. }
  297. if ((config[i].value_format == NULL) &&
  298. (config[i].values_format == NULL)) {
  299. continue;
  300. }
  301. printf("dn: "
  302. NIS_MAP_CONFIGURATION_DOMAIN_ATTR "=%s+"
  303. NIS_MAP_CONFIGURATION_MAP_ATTR "=%s, "
  304. DEFAULT_CONFIGURATION_SUFFIX "\n",
  305. domain, config[i].map);
  306. printf("%s: %s\n",
  307. NIS_MAP_CONFIGURATION_DOMAIN_ATTR, domain);
  308. printf("%s: %s%s%s\n",
  309. NIS_MAP_CONFIGURATION_MAP_ATTR,
  310. (config[i].config_match == config_glob) ? "@" : "",
  311. config[i].map,
  312. (config[i].config_match == config_glob) ? "@" : "");
  313. if (config[i].base != NULL) {
  314. printf("%s: %s\n", NIS_MAP_CONFIGURATION_BASE_ATTR,
  315. config[i].base);
  316. } else {
  317. printf("%s: %s\n", NIS_MAP_CONFIGURATION_BASE_ATTR,
  318. suffix);
  319. }
  320. printf("%s: %s\n",
  321. NIS_MAP_CONFIGURATION_FILTER_ATTR,
  322. config[i].filter ? config[i].filter : "");
  323. if (config[i].keys_format != NULL) {
  324. printf("%s: %s\n",
  325. NIS_MAP_CONFIGURATION_KEYS_ATTR,
  326. config[i].keys_format);
  327. } else {
  328. printf("%s: %s\n",
  329. NIS_MAP_CONFIGURATION_KEY_ATTR,
  330. config[i].key_format ?
  331. config[i].key_format : "");
  332. }
  333. if (config[i].values_format != NULL) {
  334. printf("%s: %s\n",
  335. NIS_MAP_CONFIGURATION_VALUES_ATTR,
  336. config[i].values_format);
  337. } else {
  338. printf("%s: %s\n",
  339. NIS_MAP_CONFIGURATION_VALUE_ATTR,
  340. config[i].value_format ?
  341. config[i].value_format : "");
  342. }
  343. if (config[i].disallowed_chars != NULL) {
  344. printf("%s: %s\n",
  345. NIS_MAP_CONFIGURATION_DISALLOWED_CHARS_ATTR,
  346. config[i].disallowed_chars);
  347. }
  348. if (config[i].secure) {
  349. printf("%s: yes\n", NIS_MAP_CONFIGURATION_SECURE_ATTR);
  350. }
  351. printf("\n");
  352. }
  353. return 0;
  354. }
  355. #endif