static void sync_child(char *name, int nm_type, char *workgroup, struct in_addr ip, bool local, bool servers, char *fname) { fstring unix_workgroup; struct cli_state *cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; struct sockaddr_storage ss; NTSTATUS status; /* W2K DMB's return empty browse lists on port 445. Use 139. * Patch from Andy Levine [email protected]. */ in_addr_to_sockaddr_storage(&ss, ip); status = cli_connect_nb(name, &ss, NBT_SMB_PORT, nm_type, get_local_machine_name(), SMB_SIGNING_DEFAULT, 0, &cli); if (!NT_STATUS_IS_OK(status)) { return; } status = cli_negprot(cli, PROTOCOL_NT1); if (!NT_STATUS_IS_OK(status)) { cli_shutdown(cli); return; } if (!NT_STATUS_IS_OK(cli_session_setup(cli, "", "", 1, "", 0, workgroup))) { cli_shutdown(cli); return; } if (!NT_STATUS_IS_OK(cli_tree_connect(cli, "IPC$", "IPC", "", 1))) { cli_shutdown(cli); return; } /* All the cli_XX functions take UNIX character set. */ fstrcpy(unix_workgroup, cli->server_domain ? cli->server_domain : workgroup); /* Fetch a workgroup list. */ cli_NetServerEnum(cli, unix_workgroup, local_type|SV_TYPE_DOMAIN_ENUM, callback, NULL); /* Now fetch a server list. */ if (servers) { fstrcpy(unix_workgroup, workgroup); cli_NetServerEnum(cli, unix_workgroup, local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, callback, NULL); } cli_shutdown(cli); }
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; }
int net_rap_server(int argc, const char **argv) { struct cli_state *cli; int ret; if (argc > 0) { if (strequal(argv[0], "name")) { return net_rap_server_name(argc, argv); } /* smb4k uses 'net [rap|rpc] server domain' to query servers in a domain */ /* Fall through for 'domain', any other forms will cause to show usage message */ if (!strequal(argv[0], "domain")) { return net_rap_server_usage(argc-1, argv+1); } } if (!(cli = net_make_ipc_connection(0))) return -1; d_printf("\nEnumerating servers in this domain or workgroup: \n\n"\ "\tServer name Server description\n"\ "\t------------- ----------------------------\n"); ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL, display_server_func,NULL); cli_shutdown(cli); return ret; }
static int net_rap_server_domain(struct net_context *c, int argc, const char **argv) { struct cli_state *cli; int ret; if (c->display_usage) { d_printf("%s\n%s", _("Usage:"), _("net rap server domain\n" " Enumerate servers in this domain/workgroup\n")); return 0; } if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli))) return -1; d_printf(_("\nEnumerating servers in this domain or workgroup: \n\n" "\tServer name Server description\n" "\t------------- ----------------------------\n")); ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_ALL, display_server_func,NULL); cli_shutdown(cli); return ret; }
/**************************************************************************** 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; }
int net_rap_domain(int argc, const char **argv) { struct cli_state *cli; int ret; if (!(cli = net_make_ipc_connection(0))) return -1; d_printf("\nEnumerating domains:\n\n"\ "\tDomain name Server name of Browse Master\n"\ "\t------------- ----------------------------\n"); ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM, display_server_func,NULL); cli_shutdown(cli); return ret; }
/**************************************************************************** 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; }
int net_rap_domain(struct net_context *c, int argc, const char **argv) { struct cli_state *cli; int ret; if (c->display_usage) return net_rap_domain_usage(c, argc, argv); if (!NT_STATUS_IS_OK(net_make_ipc_connection(c, 0, &cli))) return -1; d_printf(_("\nEnumerating domains:\n\n" "\tDomain name Server name of Browse Master\n" "\t------------- ----------------------------\n")); ret = cli_NetServerEnum(cli, cli->server_domain, SV_TYPE_DOMAIN_ENUM, display_server_func,NULL); cli_shutdown(cli); return ret; }
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; }
static void sync_child(char *name, int nm_type, char *workgroup, struct in_addr ip, bool local, bool servers, char *fname) { fstring unix_workgroup; struct cli_state *cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; struct nmb_name called, calling; struct sockaddr_storage ss; NTSTATUS status; /* W2K DMB's return empty browse lists on port 445. Use 139. * Patch from Andy Levine [email protected]. */ cli = cli_initialise(); if (!cli) { return; } if (!cli_set_port(cli, 139)) { cli_shutdown(cli); return; } in_addr_to_sockaddr_storage(&ss, ip); status = cli_connect(cli, name, &ss); if (!NT_STATUS_IS_OK(status)) { cli_shutdown(cli); return; } make_nmb_name(&calling, get_local_machine_name(), 0x0); make_nmb_name(&called , name, nm_type); if (!cli_session_request(cli, &calling, &called)) { cli_shutdown(cli); return; } if (!cli_negprot(cli)) { cli_shutdown(cli); return; } if (!NT_STATUS_IS_OK(cli_session_setup(cli, "", "", 1, "", 0, workgroup))) { cli_shutdown(cli); return; } if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) { cli_shutdown(cli); return; } /* All the cli_XX functions take UNIX character set. */ fstrcpy(unix_workgroup, cli->server_domain ? cli->server_domain : workgroup); /* Fetch a workgroup list. */ cli_NetServerEnum(cli, unix_workgroup, local_type|SV_TYPE_DOMAIN_ENUM, callback, NULL); /* Now fetch a server list. */ if (servers) { fstrcpy(unix_workgroup, workgroup); cli_NetServerEnum(cli, unix_workgroup, local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, callback, NULL); } cli_shutdown(cli); }