s3-samr: remove all init_samr_dom* functions.
[ira/wip.git] / source3 / rpc_client / init_samr.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Guenther Deschner                  2008.
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 #include "includes.h"
21
22 /*******************************************************************
23  inits a samr_GroupInfoAll structure.
24 ********************************************************************/
25
26 void init_samr_group_info1(struct samr_GroupInfoAll *r,
27                            const char *name,
28                            uint32_t attributes,
29                            uint32_t num_members,
30                            const char *description)
31 {
32         DEBUG(5, ("init_samr_group_info1\n"));
33
34         init_lsa_String(&r->name, name);
35         r->attributes = attributes;
36         r->num_members = num_members;
37         init_lsa_String(&r->description, description);
38 }
39
40 /*******************************************************************
41  inits a lsa_String structure
42 ********************************************************************/
43
44 void init_samr_group_info2(struct lsa_String *r, const char *group_name)
45 {
46         DEBUG(5, ("init_samr_group_info2\n"));
47
48         init_lsa_String(r, group_name);
49 }
50
51 /*******************************************************************
52  inits a samr_GroupInfoAttributes structure.
53 ********************************************************************/
54
55 void init_samr_group_info3(struct samr_GroupInfoAttributes *r,
56                            uint32_t attributes)
57 {
58         DEBUG(5, ("init_samr_group_info3\n"));
59
60         r->attributes = attributes;
61 }
62
63 /*******************************************************************
64  inits a lsa_String structure
65 ********************************************************************/
66
67 void init_samr_group_info4(struct lsa_String *r, const char *description)
68 {
69         DEBUG(5, ("init_samr_group_info4\n"));
70
71         init_lsa_String(r, description);
72 }
73
74 /*******************************************************************
75  inits a samr_GroupInfoAll structure.
76 ********************************************************************/
77
78 void init_samr_group_info5(struct samr_GroupInfoAll *r,
79                            const char *name,
80                            uint32_t attributes,
81                            uint32_t num_members,
82                            const char *description)
83 {
84         DEBUG(5, ("init_samr_group_info5\n"));
85
86         init_lsa_String(&r->name, name);
87         r->attributes = attributes;
88         r->num_members = num_members;
89         init_lsa_String(&r->description, description);
90 }
91
92 /*******************************************************************
93  inits a samr_AliasInfoAll structure.
94 ********************************************************************/
95
96 void init_samr_alias_info1(struct samr_AliasInfoAll *r,
97                            const char *name,
98                            uint32_t num_members,
99                            const char *description)
100 {
101         DEBUG(5, ("init_samr_alias_info1\n"));
102
103         init_lsa_String(&r->name, name);
104         r->num_members = num_members;
105         init_lsa_String(&r->description, description);
106 }
107
108 /*******************************************************************
109 inits a lsa_String structure.
110 ********************************************************************/
111
112 void init_samr_alias_info3(struct lsa_String *r,
113                            const char *description)
114 {
115         DEBUG(5, ("init_samr_alias_info3\n"));
116
117         init_lsa_String(r, description);
118 }
119
120 /*************************************************************************
121  inits a samr_CryptPasswordEx structure
122  *************************************************************************/
123
124 void init_samr_CryptPasswordEx(const char *pwd,
125                                DATA_BLOB *session_key,
126                                struct samr_CryptPasswordEx *pwd_buf)
127 {
128         /* samr_CryptPasswordEx */
129
130         uchar pwbuf[532];
131         struct MD5Context md5_ctx;
132         uint8_t confounder[16];
133         DATA_BLOB confounded_session_key = data_blob(NULL, 16);
134
135         encode_pw_buffer(pwbuf, pwd, STR_UNICODE);
136
137         generate_random_buffer((uint8_t *)confounder, 16);
138
139         MD5Init(&md5_ctx);
140         MD5Update(&md5_ctx, confounder, 16);
141         MD5Update(&md5_ctx, session_key->data,
142                             session_key->length);
143         MD5Final(confounded_session_key.data, &md5_ctx);
144
145         SamOEMhashBlob(pwbuf, 516, &confounded_session_key);
146         memcpy(&pwbuf[516], confounder, 16);
147
148         memcpy(pwd_buf->data, pwbuf, sizeof(pwbuf));
149         data_blob_free(&confounded_session_key);
150 }
151
152 /*************************************************************************
153  inits a samr_CryptPassword structure
154  *************************************************************************/
155
156 void init_samr_CryptPassword(const char *pwd,
157                              DATA_BLOB *session_key,
158                              struct samr_CryptPassword *pwd_buf)
159 {
160         /* samr_CryptPassword */
161
162         encode_pw_buffer(pwd_buf->data, pwd, STR_UNICODE);
163         SamOEMhashBlob(pwd_buf->data, 516, session_key);
164 }