s3: Remove unused winbindd_dual_lookupsid
[samba.git] / source3 / winbindd / winbindd_async.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Async helpers for blocking functions
5
6    Copyright (C) Volker Lendecke 2005
7    Copyright (C) Gerald Carter 2006
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "includes.h"
24 #include "winbindd.h"
25
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_WINBIND
28
29 enum winbindd_result winbindd_dual_lookupname(struct winbindd_domain *domain,
30                                               struct winbindd_cli_state *state)
31 {
32         enum lsa_SidType type;
33         char *name_domain, *name_user;
34         DOM_SID sid;
35         char *p;
36
37         /* Ensure null termination */
38         state->request->data.name.dom_name[sizeof(state->request->data.name.dom_name)-1]='\0';
39
40         /* Ensure null termination */
41         state->request->data.name.name[sizeof(state->request->data.name.name)-1]='\0';
42
43         /* cope with the name being a fully qualified name */
44         p = strstr(state->request->data.name.name, lp_winbind_separator());
45         if (p) {
46                 *p = 0;
47                 name_domain = state->request->data.name.name;
48                 name_user = p+1;
49         } else {
50                 name_domain = state->request->data.name.dom_name;
51                 name_user = state->request->data.name.name;
52         }
53
54         DEBUG(3, ("[%5lu]: lookupname %s%s%s\n", (unsigned long)state->pid,
55                   name_domain, lp_winbind_separator(), name_user));
56
57         /* Lookup name from DC using lsa_lookup_names() */
58         if (!winbindd_lookup_sid_by_name(state->mem_ctx, state->request->original_cmd, domain, name_domain,
59                                          name_user, &sid, &type)) {
60                 return WINBINDD_ERROR;
61         }
62
63         sid_to_fstring(state->response->data.sid.sid, &sid);
64         state->response->data.sid.type = type;
65
66         return WINBINDD_OK;
67 }
68
69 bool print_sidlist(TALLOC_CTX *mem_ctx, const DOM_SID *sids,
70                    size_t num_sids, char **result, ssize_t *len)
71 {
72         size_t i;
73         size_t buflen = 0;
74
75         *len = 0;
76         *result = NULL;
77         for (i=0; i<num_sids; i++) {
78                 fstring tmp;
79                 sprintf_append(mem_ctx, result, len, &buflen,
80                                "%s\n", sid_to_fstring(tmp, &sids[i]));
81         }
82
83         if ((num_sids != 0) && (*result == NULL)) {
84                 return False;
85         }
86
87         return True;
88 }
89
90 bool parse_sidlist(TALLOC_CTX *mem_ctx, const char *sidstr,
91                    DOM_SID **sids, size_t *num_sids)
92 {
93         const char *p, *q;
94
95         p = sidstr;
96         if (p == NULL)
97                 return False;
98
99         while (p[0] != '\0') {
100                 fstring tmp;
101                 size_t sidlen;
102                 DOM_SID sid;
103                 q = strchr(p, '\n');
104                 if (q == NULL) {
105                         DEBUG(0, ("Got invalid sidstr: %s\n", p));
106                         return False;
107                 }
108                 sidlen = PTR_DIFF(q, p);
109                 if (sidlen >= sizeof(tmp)-1) {
110                         return false;
111                 }
112                 memcpy(tmp, p, sidlen);
113                 tmp[sidlen] = '\0';
114                 q += 1;
115                 if (!string_to_sid(&sid, tmp)) {
116                         DEBUG(0, ("Could not parse sid %s\n", p));
117                         return False;
118                 }
119                 if (!NT_STATUS_IS_OK(add_sid_to_array(mem_ctx, &sid, sids,
120                                                       num_sids)))
121                 {
122                         return False;
123                 }
124                 p = q;
125         }
126         return True;
127 }
128
129 enum winbindd_result winbindd_dual_ping(struct winbindd_domain *domain,
130                                         struct winbindd_cli_state *state)
131 {
132         return WINBINDD_OK;
133 }