예제 #1
0
파일: cliconnect.c 프로젝트: jophxy/samba
struct cli_state *get_ipc_connect_master_ip(pstring workgroup,
							struct user_auth_info *user_info, struct in_addr *mb_ip)
{
	fstring name;
	struct cli_state *cli;
	struct in_addr server_ss;

        /*
         * Do a name status query to find out the name of the master browser.
         * We use <01><02>__MSBROWSE__<02>#01 if *#00 fails because a domain
         * master browser will not respond to a wildcard query (or, at least,
         * an NT4 server acting as the domain master browser will not).
         *
         * We might be able to use ONLY the query on MSBROWSE, but that's not
         * yet been tested with all Windows versions, so until it is, leave
         * the original wildcard query as the first choice and fall back to
         * MSBROWSE if the wildcard query fails.
         */

	if (!name_status_find("*", 0, 0x1d, *mb_ip, name) &&
		!name_status_find(MSBROWSE, 1, 0x1d, *mb_ip, name))
		return NULL;

	if (!find_master_ip(name, &server_ss))
		return NULL;

	pstrcpy(workgroup, name);
	DEBUG(4, ("found master browser %s, %s\n", 
				name, inet_ntoa(*mb_ip)));

	cli = get_ipc_connect(inet_ntoa(server_ss), &server_ss, user_info);

	return cli;
}
예제 #2
0
static BOOL get_servers(char *workgroup, struct user_auth_info *user_info)
{
	struct cli_state *cli;
	struct in_addr server_ip;

	/* Open an IPC$ connection to the master browser for the workgroup */

	if (!find_master_ip(workgroup, &server_ip)) {
		DEBUG(4, ("Cannot find master browser for workgroup %s\n",
					workgroup));
		return False;
	}

	if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info)))
		return False;

	if (!cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, add_name, 
				&servers)) {
		if(cli) cli_shutdown(cli);
		return False;
	}

	if(cli)cli_shutdown(cli);
	return True;
}
예제 #3
0
파일: cliconnect.c 프로젝트: jophxy/samba
struct cli_state *get_ipc_connect(char *server, struct in_addr *server_ip,
                                         struct user_auth_info *user_info)
{
        struct cli_state *cli;
        pstring myname;
	NTSTATUS nt_status;

        get_myname(myname);
	
	nt_status = cli_full_connection(&cli, myname, server,
					server_ip, 0, "IPC$", "IPC", 
					user_info->username, lp_workgroup(),
					user_info->password, strlen(user_info->password));

	if (NT_STATUS_IS_OK(nt_status)) {
		return cli;
	} else if (is_ipaddress(server)) {
	    /* windows 9* needs a correct NMB name for connections */
	    fstring remote_name;

	    if (name_status_find("*", 0, 0, *server_ip, remote_name)) {
		cli = get_ipc_connect(remote_name, server_ip, user_info);
		if (cli)
		    return cli;
	    }
	}
	return NULL;
}
예제 #4
0
/****************************************************************************
  display tree of smb workgroups, servers and shares
****************************************************************************/
static bool get_workgroups(struct user_auth_info *user_info)
{
        struct cli_state *cli;
        struct sockaddr_storage server_ss;
	TALLOC_CTX *ctx = talloc_tos();
	char *master_workgroup = NULL;

        /* Try to connect to a #1d name of our current workgroup.  If that
           doesn't work broadcast for a master browser and then jump off
           that workgroup. */

	master_workgroup = talloc_strdup(ctx, lp_workgroup());
	if (!master_workgroup) {
		return false;
	}

	if (!use_bcast && !find_master_ip(lp_workgroup(), &server_ss)) {
		DEBUG(4,("Unable to find master browser for workgroup %s, "
			 "falling back to broadcast\n",
			 master_workgroup));
		use_bcast = true;
	}

	if (!use_bcast) {
		char addr[INET6_ADDRSTRLEN];

		print_sockaddr(addr, sizeof(addr), &server_ss);

		cli = get_ipc_connect(addr, &server_ss, user_info);
		if (cli == NULL) {
			return false;
		}
	} else {
		cli = get_ipc_connect_master_ip_bcast(talloc_tos(),
						      user_info,
						      &master_workgroup);
		if (cli == NULL) {
			DEBUG(4, ("Unable to find master browser by "
				  "broadcast\n"));
			return false;
		}
	}

        if (!cli_NetServerEnum(cli, master_workgroup,
                               SV_TYPE_DOMAIN_ENUM, add_name, &workgroups))
                return False;

        return True;
}
예제 #5
0
static bool get_shares(char *server_name, struct user_auth_info *user_info)
{
        struct cli_state *cli;

        if (!(cli = get_ipc_connect(server_name, NULL, user_info)))
                return False;

	if (get_rpc_shares(cli, add_name, &shares))
		return True;

        if (!cli_RNetShareEnum(cli, add_name, &shares))
                return False;

        return True;
}
예제 #6
0
/****************************************************************************
  display tree of smb workgroups, servers and shares
 ****************************************************************************/
static BOOL get_workgroups(struct user_auth_info *user_info)
{
	struct cli_state *cli, *cli2;
	struct in_addr server_ip;
	pstring master_workgroup;

	/* Try to connect to a #1d name of our current workgroup.  If that
	   doesn't work broadcast for a master browser and then jump off
	   that workgroup. */

	pstrcpy(master_workgroup, lp_workgroup());

	if (!use_bcast && !find_master_ip(lp_workgroup(), &server_ip)) {
		DEBUG(4, ("Unable to find master browser for workgroup %s, falling back to broadcast\n", 
					master_workgroup));
		use_bcast = True;
	} else if(!use_bcast) {
		if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info)))
			return False;
	}

	if (!(cli2 = get_ipc_connect_master_ip_bcast(master_workgroup, user_info))) {
		DEBUG(4, ("Unable to find master browser by "
					"broadcast\n"));
		if(cli) cli_shutdown(cli);
		return False;
	}

	if(cli2) {
		if(cli) cli_shutdown(cli);
		cli = cli2;
	}

	if (!cli_NetServerEnum(cli, master_workgroup, 
				SV_TYPE_DOMAIN_ENUM, add_name, &workgroups)) {
		if(cli) cli_shutdown(cli);
		return False;
	}

	if(cli) cli_shutdown(cli);
	return True;
}
예제 #7
0
static bool get_servers(char *workgroup, struct user_auth_info *user_info)
{
        struct cli_state *cli;
        struct sockaddr_storage server_ss;
	char addr[INET6_ADDRSTRLEN];

        /* Open an IPC$ connection to the master browser for the workgroup */

        if (!find_master_ip(workgroup, &server_ss)) {
                DEBUG(4, ("Cannot find master browser for workgroup %s\n",
                          workgroup));
                return False;
        }

	print_sockaddr(addr, sizeof(addr), &server_ss);
        if (!(cli = get_ipc_connect(addr, &server_ss, user_info)))
                return False;

        if (!cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, add_name,
                               &servers))
                return False;

        return True;
}