| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | NBT netbios routines and daemon - version 2
|
|---|
| 4 | Copyright (C) Andrew Tridgell 1994-1998
|
|---|
| 5 | Copyright (C) Luke Kenneth Casson Leighton 1994-1998
|
|---|
| 6 | Copyright (C) Jeremy Allison 1994-2003
|
|---|
| 7 | Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
|
|---|
| 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 2 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, write to the Free Software
|
|---|
| 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 22 |
|
|---|
| 23 | Revision History:
|
|---|
| 24 |
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | #include "includes.h"
|
|---|
| 28 |
|
|---|
| 29 | struct sam_database_info {
|
|---|
| 30 | uint32 index;
|
|---|
| 31 | uint32 serial_lo, serial_hi;
|
|---|
| 32 | uint32 date_lo, date_hi;
|
|---|
| 33 | };
|
|---|
| 34 |
|
|---|
| 35 | /****************************************************************************
|
|---|
| 36 | Send a message to smbd to do a sam delta sync
|
|---|
| 37 | **************************************************************************/
|
|---|
| 38 |
|
|---|
| 39 | static void send_repl_message(uint32 low_serial)
|
|---|
| 40 | {
|
|---|
| 41 | TDB_CONTEXT *tdb;
|
|---|
| 42 |
|
|---|
| 43 | tdb = tdb_open_log(lock_path("connections.tdb"), 0,
|
|---|
| 44 | TDB_DEFAULT, O_RDONLY, 0);
|
|---|
| 45 |
|
|---|
| 46 | if (!tdb) {
|
|---|
| 47 | DEBUG(3, ("send_repl_message(): failed to open connections "
|
|---|
| 48 | "database\n"));
|
|---|
| 49 | return;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | DEBUG(3, ("sending replication message, serial = 0x%04x\n",
|
|---|
| 53 | low_serial));
|
|---|
| 54 |
|
|---|
| 55 | message_send_all(tdb, MSG_SMB_SAM_REPL, &low_serial,
|
|---|
| 56 | sizeof(low_serial), False, NULL);
|
|---|
| 57 |
|
|---|
| 58 | tdb_close(tdb);
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | /****************************************************************************
|
|---|
| 62 | Process a domain logon packet
|
|---|
| 63 | **************************************************************************/
|
|---|
| 64 |
|
|---|
| 65 | void process_logon_packet(struct packet_struct *p, char *buf,int len,
|
|---|
| 66 | const char *mailslot)
|
|---|
| 67 | {
|
|---|
| 68 | struct dgram_packet *dgram = &p->packet.dgram;
|
|---|
| 69 | pstring my_name;
|
|---|
| 70 | fstring reply_name;
|
|---|
| 71 | pstring outbuf;
|
|---|
| 72 | int code;
|
|---|
| 73 | uint16 token = 0;
|
|---|
| 74 | uint32 ntversion = 0;
|
|---|
| 75 | uint16 lmnttoken = 0;
|
|---|
| 76 | uint16 lm20token = 0;
|
|---|
| 77 | uint32 domainsidsize;
|
|---|
| 78 | BOOL short_request = False;
|
|---|
| 79 | char *getdc;
|
|---|
| 80 | char *uniuser; /* Unicode user name. */
|
|---|
| 81 | pstring ascuser;
|
|---|
| 82 | char *unicomp; /* Unicode computer name. */
|
|---|
| 83 |
|
|---|
| 84 | memset(outbuf, 0, sizeof(outbuf));
|
|---|
| 85 |
|
|---|
| 86 | if (!lp_domain_logons()) {
|
|---|
| 87 | DEBUG(5,("process_logon_packet: Logon packet received from IP %s and domain \
|
|---|
| 88 | logons are not enabled.\n", inet_ntoa(p->ip) ));
|
|---|
| 89 | return;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | pstrcpy(my_name, global_myname());
|
|---|
| 93 |
|
|---|
| 94 | code = get_safe_SVAL(buf,len,buf,0,-1);
|
|---|
| 95 | DEBUG(4,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code));
|
|---|
| 96 |
|
|---|
| 97 | switch (code) {
|
|---|
| 98 | case 0:
|
|---|
| 99 | {
|
|---|
| 100 | fstring mach_str, user_str, getdc_str;
|
|---|
| 101 | char *q = buf + 2;
|
|---|
| 102 | char *machine = q;
|
|---|
| 103 | char *user = skip_string(buf,len,machine);
|
|---|
| 104 |
|
|---|
| 105 | if (!user || PTR_DIFF(user, buf) >= len) {
|
|---|
| 106 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 107 | return;
|
|---|
| 108 | }
|
|---|
| 109 | getdc = skip_string(buf,len,user);
|
|---|
| 110 |
|
|---|
| 111 | if (!getdc || PTR_DIFF(getdc, buf) >= len) {
|
|---|
| 112 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 113 | return;
|
|---|
| 114 | }
|
|---|
| 115 | q = skip_string(buf,len,getdc);
|
|---|
| 116 |
|
|---|
| 117 | if (!q || PTR_DIFF(q + 5, buf) > len) {
|
|---|
| 118 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 119 | return;
|
|---|
| 120 | }
|
|---|
| 121 | token = SVAL(q,3);
|
|---|
| 122 |
|
|---|
| 123 | fstrcpy(reply_name,my_name);
|
|---|
| 124 |
|
|---|
| 125 | pull_ascii_fstring(mach_str, machine);
|
|---|
| 126 | pull_ascii_fstring(user_str, user);
|
|---|
| 127 | pull_ascii_fstring(getdc_str, getdc);
|
|---|
| 128 |
|
|---|
| 129 | DEBUG(5,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n",
|
|---|
| 130 | mach_str,inet_ntoa(p->ip),user_str,token));
|
|---|
| 131 |
|
|---|
| 132 | q = outbuf;
|
|---|
| 133 | SSVAL(q, 0, 6);
|
|---|
| 134 | q += 2;
|
|---|
| 135 |
|
|---|
| 136 | fstrcpy(reply_name, "\\\\");
|
|---|
| 137 | fstrcat(reply_name, my_name);
|
|---|
| 138 | push_ascii(q,reply_name,
|
|---|
| 139 | sizeof(outbuf)-PTR_DIFF(q, outbuf),
|
|---|
| 140 | STR_TERMINATE);
|
|---|
| 141 | q = skip_string(outbuf,sizeof(outbuf),q); /* PDC name */
|
|---|
| 142 |
|
|---|
| 143 | SSVAL(q, 0, token);
|
|---|
| 144 | q += 2;
|
|---|
| 145 |
|
|---|
| 146 | dump_data(4, outbuf, PTR_DIFF(q, outbuf));
|
|---|
| 147 |
|
|---|
| 148 | send_mailslot(True, getdc_str,
|
|---|
| 149 | outbuf,PTR_DIFF(q,outbuf),
|
|---|
| 150 | global_myname(), 0x0,
|
|---|
| 151 | mach_str,
|
|---|
| 152 | dgram->source_name.name_type,
|
|---|
| 153 | p->ip, *iface_ip(p->ip), p->port);
|
|---|
| 154 | break;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | case QUERYFORPDC:
|
|---|
| 158 | {
|
|---|
| 159 | fstring mach_str, getdc_str;
|
|---|
| 160 | fstring source_name;
|
|---|
| 161 | char *q = buf + 2;
|
|---|
| 162 | char *machine = q;
|
|---|
| 163 |
|
|---|
| 164 | if (!lp_domain_master()) {
|
|---|
| 165 | /* We're not Primary Domain Controller -- ignore this */
|
|---|
| 166 | return;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | getdc = skip_string(buf,len,machine);
|
|---|
| 170 |
|
|---|
| 171 | if (!getdc || PTR_DIFF(getdc, buf) >= len) {
|
|---|
| 172 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 173 | return;
|
|---|
| 174 | }
|
|---|
| 175 | q = skip_string(buf,len,getdc);
|
|---|
| 176 |
|
|---|
| 177 | if (!q || PTR_DIFF(q, buf) >= len) {
|
|---|
| 178 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 179 | return;
|
|---|
| 180 | }
|
|---|
| 181 | q = ALIGN2(q, buf);
|
|---|
| 182 |
|
|---|
| 183 | /* At this point we can work out if this is a W9X or NT style
|
|---|
| 184 | request. Experiments show that the difference is wether the
|
|---|
| 185 | packet ends here. For a W9X request we now end with a pair of
|
|---|
| 186 | bytes (usually 0xFE 0xFF) whereas with NT we have two further
|
|---|
| 187 | strings - the following is a simple way of detecting this */
|
|---|
| 188 |
|
|---|
| 189 | if (len - PTR_DIFF(q, buf) <= 3) {
|
|---|
| 190 | short_request = True;
|
|---|
| 191 | } else {
|
|---|
| 192 | unicomp = q;
|
|---|
| 193 |
|
|---|
| 194 | if (PTR_DIFF(q, buf) >= len) {
|
|---|
| 195 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 196 | return;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | /* A full length (NT style) request */
|
|---|
| 200 | q = skip_unibuf(unicomp, PTR_DIFF(buf + len, unicomp));
|
|---|
| 201 |
|
|---|
| 202 | if (PTR_DIFF(q, buf) >= len) {
|
|---|
| 203 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 204 | return;
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | if (len - PTR_DIFF(q, buf) > 8) {
|
|---|
| 208 | /* with NT5 clients we can sometimes
|
|---|
| 209 | get additional data - a length specificed string
|
|---|
| 210 | containing the domain name, then 16 bytes of
|
|---|
| 211 | data (no idea what it is) */
|
|---|
| 212 | int dom_len = CVAL(q, 0);
|
|---|
| 213 | q++;
|
|---|
| 214 | if (dom_len != 0) {
|
|---|
| 215 | q += dom_len + 1;
|
|---|
| 216 | }
|
|---|
| 217 | q += 16;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | if (PTR_DIFF(q + 8, buf) > len) {
|
|---|
| 221 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 222 | return;
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | ntversion = IVAL(q, 0);
|
|---|
| 226 | lmnttoken = SVAL(q, 4);
|
|---|
| 227 | lm20token = SVAL(q, 6);
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | /* Construct reply. */
|
|---|
| 231 | q = outbuf;
|
|---|
| 232 | SSVAL(q, 0, QUERYFORPDC_R);
|
|---|
| 233 | q += 2;
|
|---|
| 234 |
|
|---|
| 235 | fstrcpy(reply_name,my_name);
|
|---|
| 236 | push_ascii(q, reply_name,
|
|---|
| 237 | sizeof(outbuf)-PTR_DIFF(q, outbuf),
|
|---|
| 238 | STR_TERMINATE);
|
|---|
| 239 | q = skip_string(outbuf,sizeof(outbuf),q); /* PDC name */
|
|---|
| 240 |
|
|---|
| 241 | /* PDC and domain name */
|
|---|
| 242 | if (!short_request) {
|
|---|
| 243 | /* Make a full reply */
|
|---|
| 244 | q = ALIGN2(q, outbuf);
|
|---|
| 245 |
|
|---|
| 246 | q += dos_PutUniCode(q, my_name,
|
|---|
| 247 | sizeof(outbuf) - PTR_DIFF(q, outbuf),
|
|---|
| 248 | True); /* PDC name */
|
|---|
| 249 | q += dos_PutUniCode(q, lp_workgroup(),
|
|---|
| 250 | sizeof(outbuf) - PTR_DIFF(q, outbuf),
|
|---|
| 251 | True); /* Domain name*/
|
|---|
| 252 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) {
|
|---|
| 253 | return;
|
|---|
| 254 | }
|
|---|
| 255 | SIVAL(q, 0, 1); /* our nt version */
|
|---|
| 256 | SSVAL(q, 4, 0xffff); /* our lmnttoken */
|
|---|
| 257 | SSVAL(q, 6, 0xffff); /* our lm20token */
|
|---|
| 258 | q += 8;
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | /* RJS, 21-Feb-2000, we send a short reply if the request was short */
|
|---|
| 262 |
|
|---|
| 263 | pull_ascii_fstring(mach_str, machine);
|
|---|
| 264 |
|
|---|
| 265 | DEBUG(5,("process_logon_packet: GETDC request from %s at IP %s, \
|
|---|
| 266 | reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
|
|---|
| 267 | mach_str,inet_ntoa(p->ip), reply_name, lp_workgroup(),
|
|---|
| 268 | QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken,
|
|---|
| 269 | (uint32)lm20token ));
|
|---|
| 270 |
|
|---|
| 271 | dump_data(4, outbuf, PTR_DIFF(q, outbuf));
|
|---|
| 272 |
|
|---|
| 273 | pull_ascii_fstring(getdc_str, getdc);
|
|---|
| 274 | pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name);
|
|---|
| 275 |
|
|---|
| 276 | send_mailslot(True, getdc_str,
|
|---|
| 277 | outbuf,PTR_DIFF(q,outbuf),
|
|---|
| 278 | global_myname(), 0x0,
|
|---|
| 279 | source_name,
|
|---|
| 280 | dgram->source_name.name_type,
|
|---|
| 281 | p->ip, *iface_ip(p->ip), p->port);
|
|---|
| 282 | return;
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | case SAMLOGON:
|
|---|
| 286 |
|
|---|
| 287 | {
|
|---|
| 288 | fstring getdc_str;
|
|---|
| 289 | fstring source_name;
|
|---|
| 290 | char *q = buf + 2;
|
|---|
| 291 | fstring asccomp;
|
|---|
| 292 |
|
|---|
| 293 | q += 2;
|
|---|
| 294 |
|
|---|
| 295 | if (PTR_DIFF(q, buf) >= len) {
|
|---|
| 296 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 297 | return;
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | unicomp = q;
|
|---|
| 301 | uniuser = skip_unibuf(unicomp, PTR_DIFF(buf+len, unicomp));
|
|---|
| 302 |
|
|---|
| 303 | if (PTR_DIFF(uniuser, buf) >= len) {
|
|---|
| 304 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 305 | return;
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | getdc = skip_unibuf(uniuser,PTR_DIFF(buf+len, uniuser));
|
|---|
| 309 |
|
|---|
| 310 | if (PTR_DIFF(getdc, buf) >= len) {
|
|---|
| 311 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 312 | return;
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | q = skip_string(buf,len,getdc);
|
|---|
| 316 |
|
|---|
| 317 | if (!q || PTR_DIFF(q + 8, buf) >= len) {
|
|---|
| 318 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 319 | return;
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | q += 4; /* Account Control Bits - indicating username type */
|
|---|
| 323 | domainsidsize = IVAL(q, 0);
|
|---|
| 324 | q += 4;
|
|---|
| 325 |
|
|---|
| 326 | DEBUG(5,("process_logon_packet: SAMLOGON sidsize %d, len = %d\n", domainsidsize, len));
|
|---|
| 327 |
|
|---|
| 328 | if (domainsidsize < (len - PTR_DIFF(q, buf)) && (domainsidsize != 0)) {
|
|---|
| 329 | q += domainsidsize;
|
|---|
| 330 | q = ALIGN4(q, buf);
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | DEBUG(5,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %ld\n", len, (unsigned long)PTR_DIFF(q, buf) ));
|
|---|
| 334 |
|
|---|
| 335 | if (len - PTR_DIFF(q, buf) > 8) {
|
|---|
| 336 | /* with NT5 clients we can sometimes
|
|---|
| 337 | get additional data - a length specificed string
|
|---|
| 338 | containing the domain name, then 16 bytes of
|
|---|
| 339 | data (no idea what it is) */
|
|---|
| 340 | int dom_len = CVAL(q, 0);
|
|---|
| 341 | q++;
|
|---|
| 342 | if (dom_len < (len - PTR_DIFF(q, buf)) && (dom_len != 0)) {
|
|---|
| 343 | q += dom_len + 1;
|
|---|
| 344 | }
|
|---|
| 345 | q += 16;
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | if (PTR_DIFF(q + 8, buf) > len) {
|
|---|
| 349 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 350 | return;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | ntversion = IVAL(q, 0);
|
|---|
| 354 | lmnttoken = SVAL(q, 4);
|
|---|
| 355 | lm20token = SVAL(q, 6);
|
|---|
| 356 | q += 8;
|
|---|
| 357 |
|
|---|
| 358 | DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion));
|
|---|
| 359 |
|
|---|
| 360 | /*
|
|---|
| 361 | * we respond regadless of whether the machine is in our password
|
|---|
| 362 | * database. If it isn't then we let smbd send an appropriate error.
|
|---|
| 363 | * Let's ignore the SID.
|
|---|
| 364 | */
|
|---|
| 365 | pull_ucs2_pstring(ascuser, uniuser);
|
|---|
| 366 | pull_ucs2_fstring(asccomp, unicomp);
|
|---|
| 367 | DEBUG(5,("process_logon_packet: SAMLOGON user %s\n", ascuser));
|
|---|
| 368 |
|
|---|
| 369 | fstrcpy(reply_name, "\\\\"); /* Here it wants \\LOGONSERVER. */
|
|---|
| 370 | fstrcat(reply_name, my_name);
|
|---|
| 371 |
|
|---|
| 372 | DEBUG(5,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n",
|
|---|
| 373 | asccomp,inet_ntoa(p->ip), ascuser, reply_name, lp_workgroup(),
|
|---|
| 374 | SAMLOGON_R ,lmnttoken));
|
|---|
| 375 |
|
|---|
| 376 | /* Construct reply. */
|
|---|
| 377 |
|
|---|
| 378 | q = outbuf;
|
|---|
| 379 | /* we want the simple version unless we are an ADS PDC..which means */
|
|---|
| 380 | /* never, at least for now */
|
|---|
| 381 | if ((ntversion < 11) || (SEC_ADS != lp_security()) || (ROLE_DOMAIN_PDC != lp_server_role())) {
|
|---|
| 382 | if (SVAL(uniuser, 0) == 0) {
|
|---|
| 383 | SSVAL(q, 0, SAMLOGON_UNK_R); /* user unknown */
|
|---|
| 384 | } else {
|
|---|
| 385 | SSVAL(q, 0, SAMLOGON_R);
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | q += 2;
|
|---|
| 389 |
|
|---|
| 390 | q += dos_PutUniCode(q, reply_name,
|
|---|
| 391 | sizeof(outbuf) - PTR_DIFF(q, outbuf),
|
|---|
| 392 | True);
|
|---|
| 393 | q += dos_PutUniCode(q, ascuser,
|
|---|
| 394 | sizeof(outbuf) - PTR_DIFF(q, outbuf),
|
|---|
| 395 | True);
|
|---|
| 396 | q += dos_PutUniCode(q, lp_workgroup(),
|
|---|
| 397 | sizeof(outbuf) - PTR_DIFF(q, outbuf),
|
|---|
| 398 | True);
|
|---|
| 399 | }
|
|---|
| 400 | #ifdef HAVE_ADS
|
|---|
| 401 | else {
|
|---|
| 402 | struct GUID domain_guid;
|
|---|
| 403 | UUID_FLAT flat_guid;
|
|---|
| 404 | pstring domain;
|
|---|
| 405 | pstring hostname;
|
|---|
| 406 | char *component, *dc, *q1;
|
|---|
| 407 | uint8 size;
|
|---|
| 408 | char *q_orig = q;
|
|---|
| 409 | int str_offset;
|
|---|
| 410 |
|
|---|
| 411 | get_mydnsdomname(domain);
|
|---|
| 412 | get_myname(hostname);
|
|---|
| 413 |
|
|---|
| 414 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) {
|
|---|
| 415 | return;
|
|---|
| 416 | }
|
|---|
| 417 | if (SVAL(uniuser, 0) == 0) {
|
|---|
| 418 | SIVAL(q, 0, SAMLOGON_AD_UNK_R); /* user unknown */
|
|---|
| 419 | } else {
|
|---|
| 420 | SIVAL(q, 0, SAMLOGON_AD_R);
|
|---|
| 421 | }
|
|---|
| 422 | q += 4;
|
|---|
| 423 |
|
|---|
| 424 | SIVAL(q, 0, ADS_PDC|ADS_GC|ADS_LDAP|ADS_DS|
|
|---|
| 425 | ADS_KDC|ADS_TIMESERV|ADS_CLOSEST|ADS_WRITABLE);
|
|---|
| 426 | q += 4;
|
|---|
| 427 |
|
|---|
| 428 | /* Push Domain GUID */
|
|---|
| 429 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < UUID_FLAT_SIZE) {
|
|---|
| 430 | return;
|
|---|
| 431 | }
|
|---|
| 432 | if (False == secrets_fetch_domain_guid(domain, &domain_guid)) {
|
|---|
| 433 | DEBUG(2, ("Could not fetch DomainGUID for %s\n", domain));
|
|---|
| 434 | return;
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | smb_uuid_pack(domain_guid, &flat_guid);
|
|---|
| 438 | memcpy(q, &flat_guid.info, UUID_FLAT_SIZE);
|
|---|
| 439 | q += UUID_FLAT_SIZE;
|
|---|
| 440 |
|
|---|
| 441 | /* Forest */
|
|---|
| 442 | str_offset = q - q_orig;
|
|---|
| 443 | dc = domain;
|
|---|
| 444 | q1 = q;
|
|---|
| 445 | while ((component = strtok(dc, "."))) {
|
|---|
| 446 | dc = NULL;
|
|---|
| 447 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 1) {
|
|---|
| 448 | return;
|
|---|
| 449 | }
|
|---|
| 450 | size = push_ascii(&q[1], component,
|
|---|
| 451 | sizeof(outbuf) - PTR_DIFF(q+1, outbuf),
|
|---|
| 452 | 0);
|
|---|
| 453 | SCVAL(q, 0, size);
|
|---|
| 454 | q += (size + 1);
|
|---|
| 455 | }
|
|---|
| 456 |
|
|---|
| 457 | /* Unk0 */
|
|---|
| 458 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 4) {
|
|---|
| 459 | return;
|
|---|
| 460 | }
|
|---|
| 461 | SCVAL(q, 0, 0);
|
|---|
| 462 | q++;
|
|---|
| 463 |
|
|---|
| 464 | /* Domain */
|
|---|
| 465 | SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F));
|
|---|
| 466 | SCVAL(q, 1, str_offset & 0xFF);
|
|---|
| 467 | q += 2;
|
|---|
| 468 |
|
|---|
| 469 | /* Hostname */
|
|---|
| 470 | size = push_ascii(&q[1], hostname,
|
|---|
| 471 | sizeof(outbuf) - PTR_DIFF(q+1, outbuf),
|
|---|
| 472 | 0);
|
|---|
| 473 | SCVAL(q, 0, size);
|
|---|
| 474 | q += (size + 1);
|
|---|
| 475 |
|
|---|
| 476 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 3) {
|
|---|
| 477 | return;
|
|---|
| 478 | }
|
|---|
| 479 |
|
|---|
| 480 | SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F));
|
|---|
| 481 | SCVAL(q, 1, str_offset & 0xFF);
|
|---|
| 482 | q += 2;
|
|---|
| 483 |
|
|---|
| 484 | /* NETBIOS of domain */
|
|---|
| 485 | size = push_ascii(&q[1], lp_workgroup(),
|
|---|
| 486 | sizeof(outbuf) - PTR_DIFF(q+1, outbuf),
|
|---|
| 487 | STR_UPPER);
|
|---|
| 488 | SCVAL(q, 0, size);
|
|---|
| 489 | q += (size + 1);
|
|---|
| 490 |
|
|---|
| 491 | /* Unk1 */
|
|---|
| 492 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 2) {
|
|---|
| 493 | return;
|
|---|
| 494 | }
|
|---|
| 495 | SCVAL(q, 0, 0);
|
|---|
| 496 | q++;
|
|---|
| 497 |
|
|---|
| 498 | /* NETBIOS of hostname */
|
|---|
| 499 | size = push_ascii(&q[1], my_name,
|
|---|
| 500 | sizeof(outbuf) - PTR_DIFF(q+1, outbuf),
|
|---|
| 501 | 0);
|
|---|
| 502 | SCVAL(q, 0, size);
|
|---|
| 503 | q += (size + 1);
|
|---|
| 504 |
|
|---|
| 505 | /* Unk2 */
|
|---|
| 506 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 4) {
|
|---|
| 507 | return;
|
|---|
| 508 | }
|
|---|
| 509 | SCVAL(q, 0, 0);
|
|---|
| 510 | q++;
|
|---|
| 511 |
|
|---|
| 512 | /* User name */
|
|---|
| 513 | if (SVAL(uniuser, 0) != 0) {
|
|---|
| 514 | size = push_ascii(&q[1], ascuser,
|
|---|
| 515 | sizeof(outbuf) - PTR_DIFF(q+1, outbuf),
|
|---|
| 516 | 0);
|
|---|
| 517 | SCVAL(q, 0, size);
|
|---|
| 518 | q += (size + 1);
|
|---|
| 519 | }
|
|---|
| 520 |
|
|---|
| 521 | q_orig = q;
|
|---|
| 522 | /* Site name */
|
|---|
| 523 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 1) {
|
|---|
| 524 | return;
|
|---|
| 525 | }
|
|---|
| 526 | size = push_ascii(&q[1], "Default-First-Site-Name",
|
|---|
| 527 | sizeof(outbuf) - PTR_DIFF(q+1, outbuf),
|
|---|
| 528 | 0);
|
|---|
| 529 | SCVAL(q, 0, size);
|
|---|
| 530 | q += (size + 1);
|
|---|
| 531 |
|
|---|
| 532 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 18) {
|
|---|
| 533 | return;
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | /* Site name (2) */
|
|---|
| 537 | str_offset = q - q_orig;
|
|---|
| 538 | SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F));
|
|---|
| 539 | SCVAL(q, 1, str_offset & 0xFF);
|
|---|
| 540 | q += 2;
|
|---|
| 541 |
|
|---|
| 542 | SCVAL(q, 0, PTR_DIFF(q,q1));
|
|---|
| 543 | SCVAL(q, 1, 0x10); /* unknown */
|
|---|
| 544 |
|
|---|
| 545 | SIVAL(q, 0, 0x00000002);
|
|---|
| 546 | q += 4; /* unknown */
|
|---|
| 547 | SIVAL(q, 0, (iface_ip(p->ip))->s_addr);
|
|---|
| 548 | q += 4;
|
|---|
| 549 | SIVAL(q, 0, 0x00000000);
|
|---|
| 550 | q += 4; /* unknown */
|
|---|
| 551 | SIVAL(q, 0, 0x00000000);
|
|---|
| 552 | q += 4; /* unknown */
|
|---|
| 553 | }
|
|---|
| 554 | #endif
|
|---|
| 555 |
|
|---|
| 556 | if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) {
|
|---|
| 557 | return;
|
|---|
| 558 | }
|
|---|
| 559 |
|
|---|
| 560 | /* tell the client what version we are */
|
|---|
| 561 | SIVAL(q, 0, ((ntversion < 11) || (SEC_ADS != lp_security())) ? 1 : 13);
|
|---|
| 562 | /* our ntversion */
|
|---|
| 563 | SSVAL(q, 4, 0xffff); /* our lmnttoken */
|
|---|
| 564 | SSVAL(q, 6, 0xffff); /* our lm20token */
|
|---|
| 565 | q += 8;
|
|---|
| 566 |
|
|---|
| 567 | dump_data(4, outbuf, PTR_DIFF(q, outbuf));
|
|---|
| 568 |
|
|---|
| 569 | pull_ascii_fstring(getdc_str, getdc);
|
|---|
| 570 | pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name);
|
|---|
| 571 |
|
|---|
| 572 | send_mailslot(True, getdc,
|
|---|
| 573 | outbuf,PTR_DIFF(q,outbuf),
|
|---|
| 574 | global_myname(), 0x0,
|
|---|
| 575 | source_name,
|
|---|
| 576 | dgram->source_name.name_type,
|
|---|
| 577 | p->ip, *iface_ip(p->ip), p->port);
|
|---|
| 578 | break;
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | /* Announce change to UAS or SAM. Send by the domain controller when a
|
|---|
| 582 | replication event is required. */
|
|---|
| 583 |
|
|---|
| 584 | case SAM_UAS_CHANGE:
|
|---|
| 585 | {
|
|---|
| 586 | struct sam_database_info *db_info;
|
|---|
| 587 | char *q = buf + 2;
|
|---|
| 588 | int i, db_count;
|
|---|
| 589 | uint32 low_serial;
|
|---|
| 590 |
|
|---|
| 591 | /* Header */
|
|---|
| 592 |
|
|---|
| 593 | if (PTR_DIFF(q + 16, buf) >= len) {
|
|---|
| 594 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 595 | return;
|
|---|
| 596 | }
|
|---|
| 597 |
|
|---|
| 598 | low_serial = IVAL(q, 0); q += 4; /* Low serial number */
|
|---|
| 599 |
|
|---|
| 600 | q += 4; /* Date/time */
|
|---|
| 601 | q += 4; /* Pulse */
|
|---|
| 602 | q += 4; /* Random */
|
|---|
| 603 |
|
|---|
| 604 | /* Domain info */
|
|---|
| 605 |
|
|---|
| 606 | q = skip_string(buf,len,q); /* PDC name */
|
|---|
| 607 |
|
|---|
| 608 | if (!q || PTR_DIFF(q, buf) >= len) {
|
|---|
| 609 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 610 | return;
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | q = skip_string(buf,len,q); /* Domain name */
|
|---|
| 614 |
|
|---|
| 615 | if (!q || PTR_DIFF(q, buf) >= len) {
|
|---|
| 616 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 617 | return;
|
|---|
| 618 | }
|
|---|
| 619 |
|
|---|
| 620 | q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode PDC name */
|
|---|
| 621 |
|
|---|
| 622 | if (PTR_DIFF(q, buf) >= len) {
|
|---|
| 623 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 624 | return;
|
|---|
| 625 | }
|
|---|
| 626 |
|
|---|
| 627 | q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode domain name */
|
|---|
| 628 |
|
|---|
| 629 | /* Database info */
|
|---|
| 630 |
|
|---|
| 631 | if (PTR_DIFF(q + 2, buf) >= len) {
|
|---|
| 632 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 633 | return;
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | db_count = SVAL(q, 0); q += 2;
|
|---|
| 637 |
|
|---|
| 638 | if (PTR_DIFF(q + (db_count*20), buf) >= len) {
|
|---|
| 639 | DEBUG(0,("process_logon_packet: bad packet\n"));
|
|---|
| 640 | return;
|
|---|
| 641 | }
|
|---|
| 642 |
|
|---|
| 643 | db_info = SMB_MALLOC_ARRAY(struct sam_database_info, db_count);
|
|---|
| 644 |
|
|---|
| 645 | if (db_info == NULL) {
|
|---|
| 646 | DEBUG(3, ("out of memory allocating info for %d databases\n", db_count));
|
|---|
| 647 | return;
|
|---|
| 648 | }
|
|---|
| 649 |
|
|---|
| 650 | for (i = 0; i < db_count; i++) {
|
|---|
| 651 | db_info[i].index = IVAL(q, 0);
|
|---|
| 652 | db_info[i].serial_lo = IVAL(q, 4);
|
|---|
| 653 | db_info[i].serial_hi = IVAL(q, 8);
|
|---|
| 654 | db_info[i].date_lo = IVAL(q, 12);
|
|---|
| 655 | db_info[i].date_hi = IVAL(q, 16);
|
|---|
| 656 | q += 20;
|
|---|
| 657 | }
|
|---|
| 658 |
|
|---|
| 659 | /* Domain SID */
|
|---|
| 660 |
|
|---|
| 661 | #if 0
|
|---|
| 662 | /* We must range check this. */
|
|---|
| 663 | q += IVAL(q, 0) + 4; /* 4 byte length plus data */
|
|---|
| 664 |
|
|---|
| 665 | q += 2; /* Alignment? */
|
|---|
| 666 |
|
|---|
| 667 | /* Misc other info */
|
|---|
| 668 |
|
|---|
| 669 | q += 4; /* NT version (0x1) */
|
|---|
| 670 | q += 2; /* LMNT token (0xff) */
|
|---|
| 671 | q += 2; /* LM20 token (0xff) */
|
|---|
| 672 | #endif
|
|---|
| 673 |
|
|---|
| 674 | SAFE_FREE(db_info); /* Not sure whether we need to do anything useful with these */
|
|---|
| 675 |
|
|---|
| 676 | /* Send message to smbd */
|
|---|
| 677 |
|
|---|
| 678 | send_repl_message(low_serial);
|
|---|
| 679 | break;
|
|---|
| 680 | }
|
|---|
| 681 |
|
|---|
| 682 | default:
|
|---|
| 683 | DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code));
|
|---|
| 684 | return;
|
|---|
| 685 | }
|
|---|
| 686 | }
|
|---|