source: vendor/current/source3/passdb/pdb_nds.c@ 414

Last change on this file since 414 was 414, checked in by Herwig Bauernfeind, 16 years ago

Samba 3.5.0: Initial import

File size: 22.6 KB
Line 
1/*
2 Unix SMB/CIFS mplementation.
3 NDS LDAP helper functions for SAMBA
4 Copyright (C) Vince Brimhall 2004-2005
5
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 3 of the License, or
9 (at your option) any later version.
10
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.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19*/
20
21#include "includes.h"
22
23#include <lber.h>
24#include <ldap.h>
25#include <wchar.h>
26
27#include "smbldap.h"
28
29#define NMASLDAP_GET_LOGIN_CONFIG_REQUEST "2.16.840.1.113719.1.39.42.100.3"
30#define NMASLDAP_GET_LOGIN_CONFIG_RESPONSE "2.16.840.1.113719.1.39.42.100.4"
31#define NMASLDAP_SET_PASSWORD_REQUEST "2.16.840.1.113719.1.39.42.100.11"
32#define NMASLDAP_SET_PASSWORD_RESPONSE "2.16.840.1.113719.1.39.42.100.12"
33#define NMASLDAP_GET_PASSWORD_REQUEST "2.16.840.1.113719.1.39.42.100.13"
34#define NMASLDAP_GET_PASSWORD_RESPONSE "2.16.840.1.113719.1.39.42.100.14"
35
36#define NMAS_LDAP_EXT_VERSION 1
37
38/**********************************************************************
39 Take the request BER value and input data items and BER encodes the
40 data into the BER value
41**********************************************************************/
42
43static int berEncodePasswordData(
44 struct berval **requestBV,
45 const char *objectDN,
46 const char *password,
47 const char *password2)
48{
49 int err = 0, rc=0;
50 BerElement *requestBer = NULL;
51
52 const char * utf8ObjPtr = NULL;
53 int utf8ObjSize = 0;
54 const char * utf8PwdPtr = NULL;
55 int utf8PwdSize = 0;
56 const char * utf8Pwd2Ptr = NULL;
57 int utf8Pwd2Size = 0;
58
59
60 /* Convert objectDN and tag strings from Unicode to UTF-8 */
61 utf8ObjSize = strlen(objectDN)+1;
62 utf8ObjPtr = objectDN;
63
64 if (password != NULL)
65 {
66 utf8PwdSize = strlen(password)+1;
67 utf8PwdPtr = password;
68 }
69
70 if (password2 != NULL)
71 {
72 utf8Pwd2Size = strlen(password2)+1;
73 utf8Pwd2Ptr = password2;
74 }
75
76 /* Allocate a BerElement for the request parameters. */
77 if((requestBer = ber_alloc()) == NULL)
78 {
79 err = LDAP_ENCODING_ERROR;
80 goto Cleanup;
81 }
82
83 if (password != NULL && password2 != NULL)
84 {
85 /* BER encode the NMAS Version, the objectDN, and the password */
86 rc = ber_printf(requestBer, "{iooo}", NMAS_LDAP_EXT_VERSION, utf8ObjPtr, utf8ObjSize, utf8PwdPtr, utf8PwdSize, utf8Pwd2Ptr, utf8Pwd2Size);
87 }
88 else if (password != NULL)
89 {
90 /* BER encode the NMAS Version, the objectDN, and the password */
91 rc = ber_printf(requestBer, "{ioo}", NMAS_LDAP_EXT_VERSION, utf8ObjPtr, utf8ObjSize, utf8PwdPtr, utf8PwdSize);
92 }
93 else
94 {
95 /* BER encode the NMAS Version and the objectDN */
96 rc = ber_printf(requestBer, "{io}", NMAS_LDAP_EXT_VERSION, utf8ObjPtr, utf8ObjSize);
97 }
98
99 if (rc < 0)
100 {
101 err = LDAP_ENCODING_ERROR;
102 goto Cleanup;
103 }
104 else
105 {
106 err = 0;
107 }
108
109 /* Convert the BER we just built to a berval that we'll send with the extended request. */
110 if(ber_flatten(requestBer, requestBV) == LBER_ERROR)
111 {
112 err = LDAP_ENCODING_ERROR;
113 goto Cleanup;
114 }
115
116Cleanup:
117
118 if(requestBer)
119 {
120 ber_free(requestBer, 1);
121 }
122
123 return err;
124}
125
126/**********************************************************************
127 Take the request BER value and input data items and BER encodes the
128 data into the BER value
129**********************************************************************/
130
131static int berEncodeLoginData(
132 struct berval **requestBV,
133 char *objectDN,
134 unsigned int methodIDLen,
135 unsigned int *methodID,
136 char *tag,
137 size_t putDataLen,
138 void *putData)
139{
140 int err = 0;
141 BerElement *requestBer = NULL;
142
143 unsigned int i;
144 unsigned int elemCnt = methodIDLen / sizeof(unsigned int);
145
146 char *utf8ObjPtr=NULL;
147 int utf8ObjSize = 0;
148
149 char *utf8TagPtr = NULL;
150 int utf8TagSize = 0;
151
152 utf8ObjPtr = objectDN;
153 utf8ObjSize = strlen(utf8ObjPtr)+1;
154
155 utf8TagPtr = tag;
156 utf8TagSize = strlen(utf8TagPtr)+1;
157
158 /* Allocate a BerElement for the request parameters. */
159 if((requestBer = ber_alloc()) == NULL)
160 {
161 err = LDAP_ENCODING_ERROR;
162 goto Cleanup;
163 }
164
165 /* BER encode the NMAS Version and the objectDN */
166 err = (ber_printf(requestBer, "{io", NMAS_LDAP_EXT_VERSION, utf8ObjPtr, utf8ObjSize) < 0) ? LDAP_ENCODING_ERROR : 0;
167
168 /* BER encode the MethodID Length and value */
169 if (!err)
170 {
171 err = (ber_printf(requestBer, "{i{", methodIDLen) < 0) ? LDAP_ENCODING_ERROR : 0;