#include "includes.h"
#include "utils/net.h"
-int net_lookup_usage(int argc, const char **argv)
+int net_lookup_usage(struct net_context *c, int argc, const char **argv)
{
d_printf(
" net lookup [host] HOSTNAME[#<type>]\n\tgives IP for a hostname\n\n"
}
/* lookup a hostname giving an IP */
-static int net_lookup_host(int argc, const char **argv)
+static int net_lookup_host(struct net_context *c, int argc, const char **argv)
{
struct sockaddr_storage ss;
int name_type = 0x20;
char *p;
if (argc == 0)
- return net_lookup_usage(argc, argv);
+ return net_lookup_usage(c, argc, argv);
p = strchr_m(name,'#');
if (p) {
}
#endif
-static int net_lookup_ldap(int argc, const char **argv)
+static int net_lookup_ldap(struct net_context *c, int argc, const char **argv)
{
#ifdef HAVE_ADS
const char *domain;
if (argc > 0)
domain = argv[0];
else
- domain = opt_target_workgroup;
+ domain = c->opt_target_workgroup;
sitename = sitename_fetch(domain);
return -1;
}
-static int net_lookup_dc(int argc, const char **argv)
+static int net_lookup_dc(struct net_context *c, int argc, const char **argv)
{
struct ip_service *ip_list;
struct sockaddr_storage ss;
if (sec_ads) {
domain = lp_realm();
} else {
- domain = opt_target_workgroup;
+ domain = c->opt_target_workgroup;
}
if (argc > 0)
return -1;
print_sockaddr(addr, sizeof(addr), &ss);
- asprintf(&pdc_str, "%s", addr);
+ if (asprintf(&pdc_str, "%s", addr) == -1) {
+ return -1;
+ }
d_printf("%s\n", pdc_str);
sitename = sitename_fetch(domain);
return 0;
}
-static int net_lookup_pdc(int argc, const char **argv)
+static int net_lookup_pdc(struct net_context *c, int argc, const char **argv)
{
struct sockaddr_storage ss;
char *pdc_str = NULL;
if (lp_security() == SEC_ADS) {
domain = lp_realm();
} else {
- domain = opt_target_workgroup;
+ domain = c->opt_target_workgroup;
}
if (argc > 0)
return -1;
print_sockaddr(addr, sizeof(addr), &ss);
- asprintf(&pdc_str, "%s", addr);
+ if (asprintf(&pdc_str, "%s", addr) == -1) {
+ return -1;
+ }
d_printf("%s\n", pdc_str);
SAFE_FREE(pdc_str);
return 0;
}
-static int net_lookup_master(int argc, const char **argv)
+static int net_lookup_master(struct net_context *c, int argc, const char **argv)
{
struct sockaddr_storage master_ss;
- const char *domain=opt_target_workgroup;
+ const char *domain = c->opt_target_workgroup;
char addr[INET6_ADDRSTRLEN];
if (argc > 0)
return 0;
}
-static int net_lookup_kdc(int argc, const char **argv)
+static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
{
#ifdef HAVE_KRB5
krb5_error_code rc;
initialize_krb5_error_table();
rc = krb5_init_context(&ctx);
if (rc) {
- DEBUG(1,("krb5_init_context failed (%s)\n",
+ DEBUG(1,("krb5_init_context failed (%s)\n",
error_message(rc)));
return -1;
}
return -1;
}
-static int net_lookup_name(int argc, const char **argv)
+static int net_lookup_name(struct net_context *c, int argc, const char **argv)
{
const char *dom, *name;
DOM_SID sid;
return 0;
}
-static int net_lookup_sid(int argc, const char **argv)
+static int net_lookup_sid(struct net_context *c, int argc, const char **argv)
{
const char *dom, *name;
DOM_SID sid;
return 0;
}
-static int net_lookup_dsgetdcname(int argc, const char **argv)
+static int net_lookup_dsgetdcname(struct net_context *c, int argc, const char **argv)
{
NTSTATUS status;
const char *domain_name = NULL;
- char *site_name = NULL;
+ const char *site_name = NULL;
uint32_t flags = 0;
- struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+ struct netr_DsRGetDCNameInfo *info = NULL;
TALLOC_CTX *mem_ctx;
+ char *s = NULL;
if (argc < 1 || argc > 3) {
d_printf("usage: net lookup dsgetdcname "
}
if (argc == 3) {
- site_name = SMB_STRDUP(argv[2]);
- if (!site_name) {
- TALLOC_FREE(mem_ctx);
- return -1;
- }
- }
-
- if (!site_name) {
- site_name = sitename_fetch(domain_name);
+ site_name = argv[2];
}
- status = DsGetDcName(mem_ctx, NULL, domain_name, NULL, site_name,
+ status = dsgetdcname(mem_ctx, NULL, domain_name, NULL, site_name,
flags, &info);
if (!NT_STATUS_IS_OK(status)) {
d_printf("failed with: %s\n", nt_errstr(status));
- SAFE_FREE(site_name);
TALLOC_FREE(mem_ctx);
return -1;
}
- display_ds_domain_controller_info(mem_ctx, info);
+ s = NDR_PRINT_STRUCT_STRING(mem_ctx, netr_DsRGetDCNameInfo, info);
+ printf("%s\n", s);
+ TALLOC_FREE(s);
- SAFE_FREE(site_name);
TALLOC_FREE(mem_ctx);
return 0;
}
/* lookup hosts or IP addresses using internal samba lookup fns */
-int net_lookup(int argc, const char **argv)
+int net_lookup(struct net_context *c, int argc, const char **argv)
{
int i;
if (argc < 1) {
d_printf("\nUsage: \n");
- return net_lookup_usage(argc, argv);
+ return net_lookup_usage(c, argc, argv);
}
for (i=0; table[i].funcname; i++) {
if (StrCaseCmp(argv[0], table[i].funcname) == 0)
- return table[i].fn(argc-1, argv+1);
+ return table[i].fn(c, argc-1, argv+1);
}
- /* Default to lookup a hostname so 'net lookup foo#1b' can be
+ /* Default to lookup a hostname so 'net lookup foo#1b' can be
used instead of 'net lookup host foo#1b'. The host syntax
- is a bit confusing as non #00 names can't really be
+ is a bit confusing as non #00 names can't really be
considered hosts as such. */
- return net_lookup_host(argc, argv);
+ return net_lookup_host(c, argc, argv);
}