Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/lib/substitute.c

    r414 r745  
    44   Copyright (C) Andrew Tridgell 1992-2000
    55   Copyright (C) Gerald Carter   2006
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2121
    2222#include "includes.h"
     23#include "system/passwd.h"
     24#include "secrets.h"
     25#include "auth.h"
     26
     27static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
     28                             const char *str);
    2329
    2430userdom_struct current_user_info;
     
    4248        static bool already_perm = false;
    4349        char *tmp_local_machine = NULL;
    44         char addr[INET6_ADDRSTRLEN];
    4550        size_t len;
     51
     52        if (already_perm) {
     53                return true;
     54        }
    4655
    4756        tmp_local_machine = SMB_STRDUP(local_name);
     
    5059        }
    5160        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         }
    7061
    7162        SAFE_FREE(local_machine);
     
    202193                smb_user_name[len-1] = '$';
    203194        }
     195}
     196
     197static char sub_peeraddr[INET6_ADDRSTRLEN];
     198static const char *sub_peername = "";
     199static char sub_sockaddr[INET6_ADDRSTRLEN];
     200
     201void 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));
    204222}
    205223
     
    277295        r = p + 3;
    278296        copylen = q - r;
    279        
     297
    280298        /* reserve space for use later add %$() chars */
    281299        if ( (envname = (char *)SMB_MALLOC(copylen + 1 + 4)) == NULL ) {
    282300                return NULL;
    283301        }
    284        
     302
    285303        strncpy(envname,r,copylen);
    286304        envname[copylen] = '\0';
     
    302320        r = realloc_string_sub(str, envname, envval);
    303321        SAFE_FREE(envname);
    304                
     322
    305323        return r;
    306324}
     
    311329static char *longvar_domainsid( void )
    312330{
    313         DOM_SID sid;
     331        struct dom_sid sid;
    314332        fstring tmp;
    315333        char *sid_string;
    316        
     334
    317335        if ( !secrets_fetch_domain_sid( lp_workgroup(), &sid ) ) {
    318336                return NULL;
    319337        }
    320        
     338
    321339        sid_string = SMB_STRDUP( sid_to_fstring( tmp, &sid ) );
    322        
     340
    323341        if ( !sid_string ) {
    324342                DEBUG(0,("longvar_domainsid: failed to dup SID string!\n"));
    325343        }
    326        
     344
    327345        return sid_string;
    328346}
     
    344362{
    345363        int i;
    346        
     364
    347365        DEBUG(7,("get_longvar_val: expanding variable [%s]\n", varname));
    348        
     366
    349367        for ( i=0; longvar_table[i].name; i++ ) {
    350368                if ( strequal( longvar_table[i].name, varname ) ) {
     
    352370                }
    353371        }
    354        
     372
    355373        return NULL;
    356374}
     
    516534{
    517535        char *s;
    518        
     536
    519537        if ( (s = alloc_sub_basic( smb_name, domain_name, str )) != NULL ) {
    520538                strncpy( str, s, len );
    521539        }
    522        
     540
    523541        SAFE_FREE( s );
    524        
    525542}
    526543
     
    534551{
    535552        char *a, *t;
    536        
     553
    537554        if ( (a = alloc_sub_basic(smb_name, domain_name, str)) == NULL ) {
    538555                return NULL;
     
    546563****************************************************************************/
    547564
    548 char *alloc_sub_basic(const char *smb_name, const char *domain_name,
    549                       const char *str)
     565static char *alloc_sub_basic(const char *smb_name, const char *domain_name,
     566                             const char *str)
    550567{
    551568        char *b, *p, *s, *r, *a_string;
    552569        fstring pidstr, vnnstr;
    553         char addr[INET6_ADDRSTRLEN];
    554570        const char *local_machine_name = get_local_machine_name();
    555571        TALLOC_CTX *tmp_ctx = NULL;
    556572
    557573        /* workaround to prevent a crash while looking at bug #687 */
    558        
     574
    559575        if (!str) {
    560576                DEBUG(0,("alloc_sub_basic: NULL source string!  This should not happen\n"));
    561577                return NULL;
    562578        }
    563        
     579
    564580        a_string = SMB_STRDUP(str);
    565581        if (a_string == NULL) {
     
    606622                        break;
    607623                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");
    615627                        break;
    616628                }
    617629                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");
    620633                        break;
    621634                case 'L' :
     
    633646                        break;
    634647                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);
    636650                        break;
    637651                case 'R' :
     
    723737                goto done;
    724738        }
    725        
     739
    726740        for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
    727                
     741
    728742                b = a_string;
    729                
     743
    730744                switch (*(p+1)) {
    731745                case 'U' :
     
    803817                return NULL;
    804818        }
    805        
     819
    806820        for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
    807                
     821
    808822                b = a_string;
    809                
     823
    810824                switch (*(p+1)) {
    811825                case 'N' :
     
    831845                        a_string = realloc_string_sub(a_string, "%u", user);
    832846                        break;
    833                        
     847
    834848                        /* Patch from jkf@soton.ac.uk Left the %N (NIS
    835849                         * server name) in standard_sub_basic as it is
     
    843857                                                      automount_path(servicename));
    844858                        break;
    845                        
     859
    846860                default:
    847861                        break;
     
    906920        return talloc_sub_advanced(ctx,
    907921                                lp_servicename(SNUM(conn)),
    908                                 conn->server_info->unix_name,
     922                                conn->session_info->unix_name,
    909923                                conn->connectpath,
    910                                 conn->server_info->utok.gid,
     924                                conn->session_info->utok.gid,
    911925                                get_smb_user_name(),
    912926                                "",
Note: See TracChangeset for help on using the changeset viewer.