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/libcli/nbt/lmhosts.c

    r414 r745  
    2727#include "system/filesys.h"
    2828#include "system/network.h"
     29#include "../libcli/nbt/libnbt.h"
    2930
    3031/********************************************************
     
    156157}
    157158
     159/********************************************************
     160 Resolve via "lmhosts" method.
     161*********************************************************/
     162
     163NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file,
     164                                          const char *name, int name_type,
     165                                          TALLOC_CTX *mem_ctx,
     166                                          struct sockaddr_storage **return_iplist,
     167                                          int *return_count)
     168{
     169        /*
     170         * "lmhosts" means parse the local lmhosts file.
     171         */
     172
     173        XFILE *fp;
     174        char *lmhost_name = NULL;
     175        int name_type2;
     176        struct sockaddr_storage return_ss;
     177        NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
     178        TALLOC_CTX *ctx = NULL;
     179
     180        *return_iplist = NULL;
     181        *return_count = 0;
     182
     183        DEBUG(3,("resolve_lmhosts: "
     184                "Attempting lmhosts lookup for name %s<0x%x>\n",
     185                name, name_type));
     186
     187        fp = startlmhosts(lmhosts_file);
     188
     189        if ( fp == NULL )
     190                return NT_STATUS_NO_SUCH_FILE;
     191
     192        ctx = talloc_new(mem_ctx);
     193        if (!ctx) {
     194                endlmhosts(fp);
     195                return NT_STATUS_NO_MEMORY;
     196        }
     197
     198        while (getlmhostsent(ctx, fp, &lmhost_name, &name_type2, &return_ss)) {
     199
     200                if (!strequal(name, lmhost_name)) {
     201                        TALLOC_FREE(lmhost_name);
     202                        continue;
     203                }
     204
     205                if ((name_type2 != -1) && (name_type != name_type2)) {
     206                        TALLOC_FREE(lmhost_name);
     207                        continue;
     208                }
     209               
     210                *return_iplist = talloc_realloc(ctx, (*return_iplist),
     211                                                struct sockaddr_storage,
     212                                                (*return_count)+1);
     213
     214                if ((*return_iplist) == NULL) {
     215                        TALLOC_FREE(ctx);
     216                        endlmhosts(fp);
     217                        DEBUG(3,("resolve_lmhosts: talloc_realloc fail !\n"));
     218                        return NT_STATUS_NO_MEMORY;
     219                }
     220
     221                (*return_iplist)[*return_count] = return_ss;
     222                *return_count += 1;
     223
     224                /* we found something */
     225                status = NT_STATUS_OK;
     226
     227                /* Multiple names only for DC lookup */
     228                if (name_type != 0x1c)
     229                        break;
     230        }
     231
     232        talloc_steal(mem_ctx, *return_iplist);
     233        TALLOC_FREE(ctx);
     234        endlmhosts(fp);
     235        return status;
     236}
     237
Note: See TracChangeset for help on using the changeset viewer.