r12592: Remove some useless dependencies
[ira/wip.git] / source / auth / credentials / credentials_gensec.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    User credentials handling
5
6    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "auth/gensec/gensec.h"
25
26 const struct gensec_security_ops **cli_credentials_gensec_list(struct cli_credentials *creds) 
27 {
28         if (!creds || !creds->gensec_list) {
29                 return gensec_security_all();
30         }
31         return creds->gensec_list;
32 }
33
34 static NTSTATUS cli_credentials_gensec_remove_mech(struct cli_credentials *creds,
35                                                    const struct gensec_security_ops *remove_mech) 
36 {
37         const struct gensec_security_ops **gensec_list;
38         const struct gensec_security_ops **new_gensec_list;
39         int i, j;
40
41         gensec_list = cli_credentials_gensec_list(creds);
42
43         for (i=0; gensec_list && gensec_list[i]; i++) {
44                 /* noop */
45         }
46
47         new_gensec_list = talloc_array(creds, const struct gensec_security_ops *, i + 1);
48         if (!new_gensec_list) {
49                 return NT_STATUS_NO_MEMORY;
50         }
51
52         j = 0;
53         for (i=0; gensec_list && gensec_list[i]; i++) {
54                 if (gensec_list[i] != remove_mech) {
55                         new_gensec_list[j] = gensec_list[i];
56                         j++;
57                 }
58         }
59         new_gensec_list[j] = NULL; 
60         
61         creds->gensec_list = new_gensec_list;
62
63         return NT_STATUS_OK;
64 }
65
66 NTSTATUS cli_credentials_gensec_remove_oid(struct cli_credentials *creds,
67                                            const char *oid) 
68 {
69         const struct gensec_security_ops *gensec_by_oid;
70
71         gensec_by_oid = gensec_security_by_oid(NULL, oid);
72         if (!gensec_by_oid) {
73                 return NT_STATUS_OK;
74         }
75
76         return cli_credentials_gensec_remove_mech(creds, gensec_by_oid);
77 }