Changeset 745 for trunk/server/source3/lib/substitute.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/lib/substitute.c
r414 r745 4 4 Copyright (C) Andrew Tridgell 1992-2000 5 5 Copyright (C) Gerald Carter 2006 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 21 21 22 22 #include "includes.h" 23 #include "system/passwd.h" 24 #include "secrets.h" 25 #include "auth.h" 26 27 static char *alloc_sub_basic(const char *smb_name, const char *domain_name, 28 const char *str); 23 29 24 30 userdom_struct current_user_info; … … 42 48 static bool already_perm = false; 43 49 char *tmp_local_machine = NULL; 44 char addr[INET6_ADDRSTRLEN];45 50 size_t len; 51 52 if (already_perm) { 53 return true; 54 } 46 55 47 56 tmp_local_machine = SMB_STRDUP(local_name); … … 50 59 } 51 60 trim_char(tmp_local_machine,' ',' '); 52 53 /*54 * Windows NT/2k uses "*SMBSERVER" and XP uses "*SMBSERV"55 * arrggg!!!56 */57 58 if (strequal(tmp_local_machine, "*SMBSERVER") ||59 strequal(tmp_local_machine, "*SMBSERV") ) {60 SAFE_FREE(local_machine);61 local_machine = SMB_STRDUP(client_socket_addr(get_client_fd(),62 addr, sizeof(addr)) );63 SAFE_FREE(tmp_local_machine);64 return local_machine ? true : false;65 }66 67 if (already_perm) {68 return true;69 }70 61 71 62 SAFE_FREE(local_machine); … … 202 193 smb_user_name[len-1] = '$'; 203 194 } 195 } 196 197 static char sub_peeraddr[INET6_ADDRSTRLEN]; 198 static const char *sub_peername = ""; 199 static char sub_sockaddr[INET6_ADDRSTRLEN]; 200 201 void sub_set_socket_ids(const char *peeraddr, const char *peername, 202 const char *sockaddr) 203 { 204 const char *addr = peeraddr; 205 206 if (strnequal(addr, "::ffff:", 7)) { 207 addr += 7; 208 } 209 strlcpy(sub_peeraddr, addr, sizeof(sub_peeraddr)); 210 211 sub_peername = SMB_STRDUP(peername); 212 if (sub_peername == NULL) { 213 sub_peername = sub_peeraddr; 214 } 215 216 /* 217 * Shouldn't we do the ::ffff: cancellation here as well? The 218 * original code in alloc_sub_basic() did not do it, so I'm 219 * leaving it out here as well for compatibility. 220 */ 221 strlcpy(sub_sockaddr, sockaddr, sizeof(sub_sockaddr)); 204 222 } 205 223 … … 277 295 r = p + 3; 278 296 copylen = q - r; 279 297 280 298 /* reserve space for use later add %$() chars */ 281 299 if ( (envname = (char *)SMB_MALLOC(copylen + 1 + 4)) == NULL ) { 282 300 return NULL; 283 301 } 284 302 285 303 strncpy(envname,r,copylen); 286 304 envname[copylen] = '\0'; … … 302 320 r = realloc_string_sub(str, envname, envval); 303 321 SAFE_FREE(envname); 304 322 305 323 return r; 306 324 } … … 311 329 static char *longvar_domainsid( void ) 312 330 { 313 DOM_SIDsid;331 struct dom_sid sid; 314 332 fstring tmp; 315 333 char *sid_string; 316 334 317 335 if ( !secrets_fetch_domain_sid( lp_workgroup(), &sid ) ) { 318 336 return NULL; 319 337 } 320 338 321 339 sid_string = SMB_STRDUP( sid_to_fstring( tmp, &sid ) ); 322 340 323 341 if ( !sid_string ) { 324 342 DEBUG(0,("longvar_domainsid: failed to dup SID string!\n")); 325 343 } 326 344 327 345 return sid_string; 328 346 } … … 344 362 { 345 363 int i; 346 364 347 365 DEBUG(7,("get_longvar_val: expanding variable [%s]\n", varname)); 348 366 349 367 for ( i=0; longvar_table[i].name; i++ ) { 350 368 if ( strequal( longvar_table[i].name, varname ) ) { … … 352 370 } 353 371 } 354 372 355 373 return NULL; 356 374 } … … 516 534 { 517 535 char *s; 518 536 519 537 if ( (s = alloc_sub_basic( smb_name, domain_name, str )) != NULL ) { 520 538 strncpy( str, s, len ); 521 539 } 522 540 523 541 SAFE_FREE( s ); 524 525 542 } 526 543 … … 534 551 { 535 552 char *a, *t; 536 553 537 554 if ( (a = alloc_sub_basic(smb_name, domain_name, str)) == NULL ) { 538 555 return NULL; … … 546 563 ****************************************************************************/ 547 564 548 char *alloc_sub_basic(const char *smb_name, const char *domain_name,549 565 static char *alloc_sub_basic(const char *smb_name, const char *domain_name, 566 const char *str) 550 567 { 551 568 char *b, *p, *s, *r, *a_string; 552 569 fstring pidstr, vnnstr; 553 char addr[INET6_ADDRSTRLEN];554 570 const char *local_machine_name = get_local_machine_name(); 555 571 TALLOC_CTX *tmp_ctx = NULL; 556 572 557 573 /* workaround to prevent a crash while looking at bug #687 */ 558 574 559 575 if (!str) { 560 576 DEBUG(0,("alloc_sub_basic: NULL source string! This should not happen\n")); 561 577 return NULL; 562 578 } 563 579 564 580 a_string = SMB_STRDUP(str); 565 581 if (a_string == NULL) { … … 606 622 break; 607 623 case 'I' : { 608 int offset = 0; 609 client_addr(get_client_fd(), addr, sizeof(addr)); 610 if (strnequal(addr,"::ffff:",7)) { 611 offset = 7; 612 } 613 a_string = realloc_string_sub(a_string, "%I", 614 addr + offset); 624 a_string = realloc_string_sub( 625 a_string, "%I", 626 sub_peeraddr[0] ? sub_peeraddr : "0.0.0.0"); 615 627 break; 616 628 } 617 629 case 'i': 618 a_string = realloc_string_sub( a_string, "%i", 619 client_socket_addr(get_client_fd(), addr, sizeof(addr)) ); 630 a_string = realloc_string_sub( 631 a_string, "%i", 632 sub_sockaddr[0] ? sub_sockaddr : "0.0.0.0"); 620 633 break; 621 634 case 'L' : … … 633 646 break; 634 647 case 'M' : 635 a_string = realloc_string_sub(a_string, "%M", client_name(get_client_fd())); 648 a_string = realloc_string_sub(a_string, "%M", 649 sub_peername); 636 650 break; 637 651 case 'R' : … … 723 737 goto done; 724 738 } 725 739 726 740 for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) { 727 741 728 742 b = a_string; 729 743 730 744 switch (*(p+1)) { 731 745 case 'U' : … … 803 817 return NULL; 804 818 } 805 819 806 820 for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) { 807 821 808 822 b = a_string; 809 823 810 824 switch (*(p+1)) { 811 825 case 'N' : … … 831 845 a_string = realloc_string_sub(a_string, "%u", user); 832 846 break; 833 847 834 848 /* Patch from jkf@soton.ac.uk Left the %N (NIS 835 849 * server name) in standard_sub_basic as it is … … 843 857 automount_path(servicename)); 844 858 break; 845 859 846 860 default: 847 861 break; … … 906 920 return talloc_sub_advanced(ctx, 907 921 lp_servicename(SNUM(conn)), 908 conn->se rver_info->unix_name,922 conn->session_info->unix_name, 909 923 conn->connectpath, 910 conn->se rver_info->utok.gid,924 conn->session_info->utok.gid, 911 925 get_smb_user_name(), 912 926 "",
Note:
See TracChangeset
for help on using the changeset viewer.