diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/libsmb/cliconnect.c | 13 | ||||
-rw-r--r-- | source3/libsmb/nterr.c | 4 | ||||
-rw-r--r-- | source3/utils/net_usershare.c | 21 | ||||
-rw-r--r-- | source3/utils/netlookup.c | 35 |
4 files changed, 53 insertions, 20 deletions
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index 6f32fb1b5d..4c6b890db0 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -1394,7 +1394,11 @@ again: DEBUG(1,("cli_start_connection: failed to connect to %s (%s)\n", nmb_namestr(&called), inet_ntoa(ip))); cli_shutdown(cli); - return NT_STATUS_UNSUCCESSFUL; + if (is_zero_ip(ip)) { + return NT_STATUS_BAD_NETWORK_NAME; + } else { + return NT_STATUS_CONNECTION_REFUSED; + } } if (retry) @@ -1412,7 +1416,7 @@ again: make_nmb_name(&called , "*SMBSERVER", 0x20); goto again; } - return NT_STATUS_UNSUCCESSFUL; + return NT_STATUS_BAD_NETWORK_NAME; } cli_setup_signing_state(cli, signing_state); @@ -1424,7 +1428,10 @@ again: if (!cli_negprot(cli)) { DEBUG(1,("failed negprot\n")); - nt_status = NT_STATUS_UNSUCCESSFUL; + nt_status = cli_nt_error(cli); + if (NT_STATUS_IS_OK(nt_status)) { + nt_status = NT_STATUS_UNSUCCESSFUL; + } cli_shutdown(cli); return nt_status; } diff --git a/source3/libsmb/nterr.c b/source3/libsmb/nterr.c index 677c5d84c7..4f97379ee0 100644 --- a/source3/libsmb/nterr.c +++ b/source3/libsmb/nterr.c @@ -541,6 +541,8 @@ static nt_err_code_struct nt_errs[] = { NULL, NT_STATUS(0) } }; +/* These need sorting..... */ + nt_err_code_struct nt_err_desc[] = { { "Success", NT_STATUS_OK }, @@ -595,6 +597,8 @@ nt_err_code_struct nt_err_desc[] = { "Duplicate name on network", NT_STATUS_DUPLICATE_NAME }, { "Print queue is full", NT_STATUS_PRINT_QUEUE_FULL }, { "No print spool space available", NT_STATUS_NO_SPOOL_SPACE }, + { "The network name cannot be found", NT_STATUS_BAD_NETWORK_NAME }, + { "The connection was refused", NT_STATUS_CONNECTION_REFUSED }, { "Too many names", NT_STATUS_TOO_MANY_NAMES }, { "Too many sessions", NT_STATUS_TOO_MANY_SESSIONS }, { "Invalid server state", NT_STATUS_INVALID_SERVER_STATE }, diff --git a/source3/utils/net_usershare.c b/source3/utils/net_usershare.c index 40f1c22688..586d1646a9 100644 --- a/source3/utils/net_usershare.c +++ b/source3/utils/net_usershare.c @@ -362,10 +362,13 @@ static int info_fn(struct file_list *fl, void *priv) char access_str[2]; const char *domain; const char *name; + NTSTATUS ntstatus; access_str[1] = '\0'; - if (net_lookup_name_from_sid(ctx, &psd->dacl->ace[num_aces].trustee, &domain, &name)) { + ntstatus = net_lookup_name_from_sid(ctx, &psd->dacl->ace[num_aces].trustee, &domain, &name); + + if (!NT_STATUS_IS_OK(ntstatus)) { if (*domain) { pstrcat(acl_str, domain); pstrcat(acl_str, sep_str); @@ -548,7 +551,9 @@ static int net_usershare_add(int argc, const char **argv) if ((myeuid != 0) && lp_usershare_owner_only() && (myeuid != sbuf.st_uid)) { d_fprintf(stderr, "net usershare add: cannot share path %s as " - "we are restricted to only sharing directories we own.\n", + "we are restricted to only sharing directories we own.\n" + "\tAsk the administrator to add the line \"usershare owner only = False\" \n" + "\tto the [global] section of the smb.conf to allow this.\n", us_path ); SAFE_FREE(sharename); return -1; @@ -610,9 +615,15 @@ static int net_usershare_add(int argc, const char **argv) name = talloc_strndup(ctx, pacl, pcolon - pacl); if (!string_to_sid(&sid, name)) { /* Convert to a SID */ - if (!net_lookup_sid_from_name(ctx, name, &sid)) { - d_fprintf(stderr, "net usershare add: cannot convert name %s to a SID.\n", - name ); + NTSTATUS ntstatus = net_lookup_sid_from_name(ctx, name, &sid); + if (!NT_STATUS_IS_OK(ntstatus)) { + d_fprintf(stderr, "net usershare add: cannot convert name \"%s\" to a SID. %s.", + name, get_friendly_nt_error_msg(ntstatus) ); + if (NT_STATUS_EQUAL(ntstatus, NT_STATUS_CONNECTION_REFUSED)) { + d_fprintf(stderr, " Maybe smbd is not running.\n"); + } else { + d_fprintf(stderr, "\n"); + } talloc_destroy(ctx); SAFE_FREE(sharename); return -1; diff --git a/source3/utils/netlookup.c b/source3/utils/netlookup.c index edb2f7d5ba..df0fe0c843 100644 --- a/source3/utils/netlookup.c +++ b/source3/utils/netlookup.c @@ -29,6 +29,7 @@ struct con_struct { BOOL failed_connect; + NTSTATUS err; struct cli_state *cli; struct rpc_pipe_client *lsapipe; POLICY_HND pol; @@ -53,13 +54,16 @@ static int cs_destructor(void *p) Create the connection to localhost. ********************************************************/ -static struct con_struct *create_cs(TALLOC_CTX *ctx) +static struct con_struct *create_cs(TALLOC_CTX *ctx, NTSTATUS *perr) { NTSTATUS nt_status; struct in_addr loopback_ip = *interpret_addr2("127.0.0.1");; + *perr = NT_STATUS_OK; + if (cs) { if (cs->failed_connect) { + *perr = cs->err; return NULL; } return cs; @@ -67,6 +71,7 @@ static struct con_struct *create_cs(TALLOC_CTX *ctx) cs = TALLOC_P(ctx, struct con_struct); if (!cs) { + *perr = NT_STATUS_NO_MEMORY; return NULL; } @@ -103,6 +108,8 @@ static struct con_struct *create_cs(TALLOC_CTX *ctx) if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(2,("create_cs: Connect failed. Error was %s\n", nt_errstr(nt_status))); cs->failed_connect = True; + cs->err = nt_status; + *perr = nt_status; return NULL; } @@ -113,6 +120,8 @@ static struct con_struct *create_cs(TALLOC_CTX *ctx) if (cs->lsapipe == NULL) { DEBUG(2,("create_cs: open LSA pipe failed. Error was %s\n", nt_errstr(nt_status))); cs->failed_connect = True; + cs->err = nt_status; + *perr = nt_status; return NULL; } @@ -123,9 +132,11 @@ static struct con_struct *create_cs(TALLOC_CTX *ctx) if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(2,("create_cs: rpccli_lsa_open_policy failed. Error was %s\n", nt_errstr(nt_status))); cs->failed_connect = True; + cs->err = nt_status; + *perr = nt_status; return NULL; } - + return cs; } @@ -137,7 +148,7 @@ static struct con_struct *create_cs(TALLOC_CTX *ctx) The local smbd will also ask winbindd for us, so we don't have to. ********************************************************/ -BOOL net_lookup_name_from_sid(TALLOC_CTX *ctx, +NTSTATUS net_lookup_name_from_sid(TALLOC_CTX *ctx, DOM_SID *psid, const char **ppdomain, const char **ppname) @@ -151,9 +162,9 @@ BOOL net_lookup_name_from_sid(TALLOC_CTX *ctx, *ppdomain = NULL; *ppname = NULL; - csp = create_cs(ctx); + csp = create_cs(ctx, &nt_status); if (csp == NULL) { - return False; + return nt_status; } nt_status = rpccli_lsa_lookup_sids(csp->lsapipe, ctx, @@ -164,7 +175,7 @@ BOOL net_lookup_name_from_sid(TALLOC_CTX *ctx, &types); if (!NT_STATUS_IS_OK(nt_status)) { - return False; + return nt_status; } *ppdomain = domains[0]; @@ -172,23 +183,23 @@ BOOL net_lookup_name_from_sid(TALLOC_CTX *ctx, /* Don't care about type here. */ /* Converted OK */ - return True; + return NT_STATUS_OK; } /******************************************************** Do a lookup_names call to localhost. ********************************************************/ -BOOL net_lookup_sid_from_name(TALLOC_CTX *ctx, const char *full_name, DOM_SID *pret_sid) +NTSTATUS net_lookup_sid_from_name(TALLOC_CTX *ctx, const char *full_name, DOM_SID *pret_sid) { NTSTATUS nt_status; struct con_struct *csp = NULL; DOM_SID *sids = NULL; uint32 *types = NULL; - csp = create_cs(ctx); + csp = create_cs(ctx, &nt_status); if (csp == NULL) { - return False; + return nt_status; } nt_status = rpccli_lsa_lookup_names(csp->lsapipe, ctx, @@ -199,11 +210,11 @@ BOOL net_lookup_sid_from_name(TALLOC_CTX *ctx, const char *full_name, DOM_SID *p &types); if (!NT_STATUS_IS_OK(nt_status)) { - return False; + return nt_status; } *pret_sid = sids[0]; /* Converted OK */ - return True; + return NT_STATUS_OK; } |