r15837: starting sync up for 3.0.23rc1 (in sync with SAMBA_3_0 r15822)
[Samba.git] / source / sam / nss_info.c
blob3d0e658a358258257f0a8c48bcc457f71ac0738d
1 /*
2 Unix SMB/CIFS implementation.
3 nss info helpers
4 Copyright (C) Guenther Deschner 2006
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/
20 #include "includes.h"
22 #undef DBGC_CLASS
23 #define DBGC_CLASS DBGC_IDMAP
25 /* winbind nss info = rfc2307 SO36:sfu FHAIN:rfc2307 PANKOW:template
27 * syntax is:
28 * 1st param: default setting
29 * following ":" separated list elements:
30 * DOMAIN:setting
31 * setting can be one of "sfu", "rfc2307", "template", "unixinfo"
34 enum wb_posix_mapping get_nss_info(const char *domain_name)
36 const char **list = lp_winbind_nss_info();
37 enum wb_posix_mapping map_templ = WB_POSIX_MAP_TEMPLATE;
38 int i;
40 DEBUG(11,("get_nss_info for %s\n", domain_name));
42 if (!lp_winbind_nss_info() || !*lp_winbind_nss_info()) {
43 return WB_POSIX_MAP_TEMPLATE;
46 if ((map_templ = wb_posix_map_type(list[0])) == -1) {
47 DEBUG(0,("get_nss_info: invalid setting: %s\n", list[0]));
48 return WB_POSIX_MAP_TEMPLATE;
51 DEBUG(11,("get_nss_info: using \"%s\" by default\n", list[0]));
53 for (i=0; list[i]; i++) {
55 const char *p = list[i];
56 fstring tok;
58 if (!next_token(&p, tok, ":", sizeof(tok))) {
59 DEBUG(0,("get_nss_info: no \":\" delimitier found\n"));
60 continue;
63 if (strequal(tok, domain_name)) {
65 enum wb_posix_mapping type;
67 if ((type = wb_posix_map_type(p)) == -1) {
68 DEBUG(0,("get_nss_info: invalid setting: %s\n", p));
69 /* return WB_POSIX_MAP_TEMPLATE; */
70 continue;
73 DEBUG(11,("get_nss_info: using \"%s\" for domain: %s\n", p, tok));
75 return type;
79 return map_templ;
82 const char *wb_posix_map_str(enum wb_posix_mapping mtype)
84 switch (mtype) {
85 case WB_POSIX_MAP_TEMPLATE:
86 return "template";
87 case WB_POSIX_MAP_SFU:
88 return "sfu";
89 case WB_POSIX_MAP_RFC2307:
90 return "rfc2307";
91 case WB_POSIX_MAP_UNIXINFO:
92 return "unixinfo";
93 default:
94 break;
96 return NULL;
99 enum wb_posix_mapping wb_posix_map_type(const char *map_str)
101 if (strequal(map_str, "template"))
102 return WB_POSIX_MAP_TEMPLATE;
103 else if (strequal(map_str, "sfu"))
104 return WB_POSIX_MAP_SFU;
105 else if (strequal(map_str, "rfc2307"))
106 return WB_POSIX_MAP_RFC2307;
107 else if (strequal(map_str, "unixinfo"))
108 return WB_POSIX_MAP_UNIXINFO;
110 return -1;