コード例 #1
0
ファイル: namequery.c プロジェクト: GarothLongint/mc
/********************************************************
resolve via "lmhosts" method
*********************************************************/
static BOOL
resolve_lmhosts (const char *name, struct in_addr *return_ip, int name_type)
{
    /*
     * "lmhosts" means parse the local lmhosts file.
     */

    FILE *fp;
    pstring lmhost_name;
    int name_type2;

    DEBUG (3, ("resolve_name: Attempting lmhosts lookup for name %s<0x%x>\n", name, name_type));

    fp = startlmhosts (LMHOSTSFILE);
    if (fp)
    {
        while (getlmhostsent (fp, lmhost_name, &name_type2, return_ip))
        {
            if (strequal (name, lmhost_name) && ((name_type2 == -1) || (name_type == name_type2)))
            {
                endlmhosts (fp);
                return True;
            }
        }
        endlmhosts (fp);
    }
    return False;
}
コード例 #2
0
ファイル: nmbd_lmhosts.c プロジェクト: Alexander--/samba
void load_lmhosts_file(const char *fname)
{
	char *name = NULL;
	int name_type;
	struct sockaddr_storage ss;
	TALLOC_CTX *ctx = talloc_init("load_lmhosts_file");
	FILE *fp = startlmhosts( fname );

	if (!fp) {
		DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
			fname, strerror(errno)));
		TALLOC_FREE(ctx);
		return;
	}

	while (getlmhostsent(ctx, fp, &name, &name_type, &ss) ) {
		struct in_addr ipaddr;
		struct subnet_record *subrec = NULL;
		enum name_source source = LMHOSTS_NAME;

		if (ss.ss_family != AF_INET) {
			TALLOC_FREE(name);
			continue;
		}

		ipaddr = ((struct sockaddr_in *)&ss)->sin_addr;

		/* We find a relevent subnet to put this entry on, then add it. */
		/* Go through all the broadcast subnets and see if the mask matches. */
		for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
			if(same_net_v4(ipaddr, subrec->bcast_ip, subrec->mask_ip))
				break;
		}

		/* If none match add the name to the remote_broadcast_subnet. */
		if(subrec == NULL)
			subrec = remote_broadcast_subnet;

		if(name_type == -1) {
			/* Add the (0) and (0x20) names directly into the namelist for this subnet. */
			(void)add_name_to_subnet(subrec,name,0x00,(uint16_t)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
			(void)add_name_to_subnet(subrec,name,0x20,(uint16_t)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
		} else {
			/* Add the given name type to the subnet namelist. */
			(void)add_name_to_subnet(subrec,name,name_type,(uint16_t)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
		}
	}

	TALLOC_FREE(ctx);
	endlmhosts(fp);
}
コード例 #3
0
ファイル: nmbd_lmhosts.c プロジェクト: AllardJ/Tomato
/****************************************************************************
Load a lmhosts file.
****************************************************************************/
void load_lmhosts_file(char *fname)
{  
  pstring name;
  int name_type;
  struct in_addr ipaddr;
  FILE *fp = startlmhosts( fname );

  if (!fp) {
    DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n",
             fname, strerror(errno)));
    return;
  }
   
  while (getlmhostsent(fp, name, &name_type, &ipaddr) )
  {
    struct subnet_record *subrec = NULL;
    enum name_source source = LMHOSTS_NAME;

    /* We find a relevent subnet to put this entry on, then add it. */
    /* Go through all the broadcast subnets and see if the mask matches. */
    for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
    {
      if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip))
        break;
    }
  
    /* If none match add the name to the remote_broadcast_subnet. */
    if(subrec == NULL)
      subrec = remote_broadcast_subnet;

    if(name_type == -1)
    {
      /* Add the (0) and (0x20) names directly into the namelist for this subnet. */
      (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
      (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
    }
    else
    {
      /* Add the given name type to the subnet namelist. */
      (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr);
    }
  }
   
  endlmhosts(fp);
}