diff options
-rw-r--r-- | source3/include/includes.h | 2 | ||||
-rw-r--r-- | source3/lib/replace/replace.h | 2 | ||||
-rw-r--r-- | source3/lib/util.c | 19 | ||||
-rw-r--r-- | source3/lib/util_sock.c | 52 | ||||
-rw-r--r-- | source3/libsmb/ntlmssp.c | 44 | ||||
-rw-r--r-- | source3/nmbd/nmbd_processlogon.c | 9 | ||||
-rw-r--r-- | source3/printing/nt_printing.c | 14 | ||||
-rw-r--r-- | source3/registry/reg_dynamic.c | 13 | ||||
-rw-r--r-- | source3/rpc_server/srv_lsa_nt.c | 8 | ||||
-rw-r--r-- | source3/rpc_server/srv_spoolss_nt.c | 12 | ||||
-rw-r--r-- | source3/utils/net_rpc_printer.c | 14 |
11 files changed, 106 insertions, 83 deletions
diff --git a/source3/include/includes.h b/source3/include/includes.h index b9e77010de..2e82070815 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -892,7 +892,7 @@ int setresgid(gid_t rgid, gid_t egid, gid_t sgid); * defined. */ #ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 254 +#define MAXHOSTNAMELEN 255 #endif /* yuck, I'd like a better way of doing this */ diff --git a/source3/lib/replace/replace.h b/source3/lib/replace/replace.h index 55ed2e9570..973c68ee14 100644 --- a/source3/lib/replace/replace.h +++ b/source3/lib/replace/replace.h @@ -357,7 +357,7 @@ ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset) #define _TYPE_MAXIMUM(t) ((t) (~ (t) 0 - _TYPE_MINIMUM (t))) #ifndef HOST_NAME_MAX -#define HOST_NAME_MAX 64 +#define HOST_NAME_MAX 255 #endif /* diff --git a/source3/lib/util.c b/source3/lib/util.c index 0ae80c1f9e..6e92a60238 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1212,23 +1212,24 @@ bool get_myname(char *my_name) Get my own domain name. ****************************************************************************/ -bool get_mydnsdomname(fstring my_domname) +char *get_mydnsdomname(TALLOC_CTX *ctx) { - fstring domname; + const char *domname; + char *my_domname = NULL; char *p; - *my_domname = '\0'; - if (!get_mydnsfullname(domname)) { - return False; - } + domname = get_mydnsfullname(); + if (!domname) { + return NULL; + } + p = strchr_m(domname, '.'); if (p) { p++; - fstrcpy(my_domname, p); - return True; + my_domname = talloc_strdup(ctx, p); } - return False; + return my_domname; } /**************************************************************************** diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index bd6fdbb105..66da297dc7 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1978,34 +1978,34 @@ out_umask: Get my own canonical name, including domain. ****************************************************************************/ -static fstring dnshostname_cache; - -bool get_mydnsfullname(fstring my_dnsname) +const char *get_mydnsfullname(void) { - if (!*dnshostname_cache) { + static char *dnshostname_cache; + + if (dnshostname_cache == NULL || !*dnshostname_cache) { struct addrinfo *res = NULL; + char my_hostname[HOST_NAME_MAX]; bool ret; /* get my host name */ - if (gethostname(dnshostname_cache, sizeof(dnshostname_cache)) == -1) { - *dnshostname_cache = '\0'; + if (gethostname(my_hostname, sizeof(my_hostname)) == -1) { DEBUG(0,("get_mydnsfullname: gethostname failed\n")); - return false; + return NULL; } /* Ensure null termination. */ - dnshostname_cache[sizeof(dnshostname_cache)-1] = '\0'; + my_hostname[sizeof(my_hostname)-1] = '\0'; ret = interpret_string_addr_internal(&res, - dnshostname_cache, + my_hostname, AI_ADDRCONFIG|AI_CANONNAME); if (!ret || res == NULL) { DEBUG(3,("get_mydnsfullname: getaddrinfo failed for " "name %s [%s]\n", - dnshostname_cache, + my_hostname, gai_strerror(ret) )); - return false; + return NULL; } /* @@ -2015,17 +2015,15 @@ bool get_mydnsfullname(fstring my_dnsname) if (res->ai_canonname == NULL) { DEBUG(3,("get_mydnsfullname: failed to get " "canonical name for %s\n", - dnshostname_cache)); + my_hostname)); freeaddrinfo(res); - return false; + return NULL; } - - fstrcpy(dnshostname_cache, res->ai_canonname); + dnshostname_cache = SMB_STRDUP(res->ai_canonname); freeaddrinfo(res); } - fstrcpy(my_dnsname, dnshostname_cache); - return true; + return dnshostname_cache; } /************************************************************ @@ -2034,15 +2032,20 @@ bool get_mydnsfullname(fstring my_dnsname) bool is_myname_or_ipaddr(const char *s) { - fstring name, dnsname; - char *servername; + TALLOC_CTX *ctx = talloc_tos(); + char *name = NULL; + const char *dnsname; + char *servername = NULL; if (!s) { return false; } /* Santize the string from '\\name' */ - fstrcpy(name, s); + name = talloc_strdup(ctx, s); + if (!name) { + return false; + } servername = strrchr_m(name, '\\' ); if (!servername) { @@ -2072,10 +2075,9 @@ bool is_myname_or_ipaddr(const char *s) } /* Maybe it's my dns name */ - if (get_mydnsfullname(dnsname)) { - if (strequal(servername, dnsname)) { - return true; - } + dnsname = get_mydnsfullname(); + if (dnsname && strequal(servername, dnsname)) { + return true; } /* Handle possible CNAME records - convert to an IP addr. */ @@ -2104,7 +2106,7 @@ bool is_myname_or_ipaddr(const char *s) return false; } - nics = TALLOC_ARRAY(talloc_tos(), struct iface_struct, + nics = TALLOC_ARRAY(ctx, struct iface_struct, MAX_INTERFACES); if (!nics) { return false; diff --git a/source3/libsmb/ntlmssp.c b/source3/libsmb/ntlmssp.c index 7205d57a0a..ed08e8102b 100644 --- a/source3/libsmb/ntlmssp.c +++ b/source3/libsmb/ntlmssp.c @@ -501,18 +501,19 @@ DATA_BLOB ntlmssp_weaken_keys(NTLMSSP_STATE *ntlmssp_state, TALLOC_CTX *mem_ctx) /** * Next state function for the Negotiate packet - * + * * @param ntlmssp_state NTLMSSP State * @param request The request, as a DATA_BLOB * @param request The reply, as an allocated DATA_BLOB, caller to free. - * @return Errors or MORE_PROCESSING_REQUIRED if a reply is sent. + * @return Errors or MORE_PROCESSING_REQUIRED if a reply is sent. */ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state, const DATA_BLOB request, DATA_BLOB *reply) { DATA_BLOB struct_blob; - fstring dnsname, dnsdomname; + const char *dnsname; + char *dnsdomname = NULL; uint32 neg_flags = 0; uint32 ntlmssp_command, chal_flags; const uint8 *cryptkey; @@ -535,7 +536,7 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state, } debug_ntlmssp_flags(neg_flags); } - + ntlmssp_handle_neg_flags(ntlmssp_state, neg_flags, lp_lanman_auth()); /* Ask our caller what challenge they would like in the packet */ @@ -548,31 +549,34 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state, /* The flags we send back are not just the negotiated flags, * they are also 'what is in this packet'. Therfore, we - * operate on 'chal_flags' from here on + * operate on 'chal_flags' from here on */ chal_flags = ntlmssp_state->neg_flags; /* get the right name to fill in as 'target' */ - target_name = ntlmssp_target_name(ntlmssp_state, - neg_flags, &chal_flags); - if (target_name == NULL) + target_name = ntlmssp_target_name(ntlmssp_state, + neg_flags, &chal_flags); + if (target_name == NULL) return NT_STATUS_INVALID_PARAMETER; ntlmssp_state->chal = data_blob_talloc(ntlmssp_state->mem_ctx, cryptkey, 8); ntlmssp_state->internal_chal = data_blob_talloc(ntlmssp_state->mem_ctx, cryptkey, 8); - /* This should be a 'netbios domain -> DNS domain' mapping */ - dnsdomname[0] = '\0'; - get_mydnsdomname(dnsdomname); + dnsdomname = get_mydnsdomname(ntlmssp_state->mem_ctx); + if (!dnsdomname) { + return NT_STATUS_BAD_NETWORK_NAME; + } strlower_m(dnsdomname); - - dnsname[0] = '\0'; - get_mydnsfullname(dnsname); - + + dnsname = get_mydnsfullname(); + if (!dnsdomname) { + return NT_STATUS_INVALID_COMPUTER_NAME; + } + /* This creates the 'blob' of names that appears at the end of the packet */ - if (chal_flags & NTLMSSP_CHAL_TARGET_INFO) + if (chal_flags & NTLMSSP_CHAL_TARGET_INFO) { msrpc_gen(&struct_blob, "aaaaa", NTLMSSP_NAME_TYPE_DOMAIN, target_name, @@ -592,9 +596,9 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state, } else { gen_string = "CdAdbddB"; } - + msrpc_gen(reply, gen_string, - "NTLMSSP", + "NTLMSSP", NTLMSSP_CHALLENGE, target_name, chal_flags, @@ -602,7 +606,7 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state, 0, 0, struct_blob.data, struct_blob.length); } - + data_blob_free(&struct_blob); ntlmssp_state->expected_state = NTLMSSP_AUTH; @@ -612,7 +616,7 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state, /** * Next state function for the Authenticate packet - * + * * @param ntlmssp_state NTLMSSP State * @param request The request, as a DATA_BLOB * @param request The reply, as an allocated DATA_BLOB, caller to free. diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index feb7941cc3..50a614a390 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -394,13 +394,18 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", else { struct GUID domain_guid; UUID_FLAT flat_guid; - pstring domain; + char *domain; pstring hostname; char *component, *dc, *q1; char *q_orig = q; int str_offset; - get_mydnsdomname(domain); + domain = get_mydnsdomname(talloc_tos()); + if (!domain) { + DEBUG(2, + ("get_mydnsdomname failed.\n")); + return; + } get_myname(hostname); if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) { diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index 36add6f474..57e7d37c6e 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -2936,7 +2936,7 @@ static bool map_nt_printer_info2_to_dsspooler(NT_PRINTER_INFO_LEVEL_2 *info2) { REGVAL_CTR *ctr = NULL; fstring longname; - fstring dnssuffix; + const char *dnssuffix; char *allocated_string = NULL; const char *ascii_str; int i; @@ -2948,15 +2948,17 @@ static bool map_nt_printer_info2_to_dsspooler(NT_PRINTER_INFO_LEVEL_2 *info2) map_sz_into_ctr(ctr, SPOOL_REG_PRINTERNAME, info2->sharename); map_sz_into_ctr(ctr, SPOOL_REG_SHORTSERVERNAME, global_myname()); - /* we make the assumption that the netbios name is the same - as the DNS name sinc ethe former will be what we used to + /* we make the assumption that the netbios name is the same + as the DNS name sinc ethe former will be what we used to join the domain */ - if ( get_mydnsdomname( dnssuffix ) ) + dnssuffix = get_mydnsdomname(talloc_tos()); + if (!dnssuffix) { fstr_sprintf( longname, "%s.%s", global_myname(), dnssuffix ); - else + } else { fstrcpy( longname, global_myname() ); - + } + map_sz_into_ctr(ctr, SPOOL_REG_SERVERNAME, longname); asprintf(&allocated_string, "\\\\%s\\%s", longname, info2->sharename); diff --git a/source3/registry/reg_dynamic.c b/source3/registry/reg_dynamic.c index 472760eacf..e589dff2c8 100644 --- a/source3/registry/reg_dynamic.c +++ b/source3/registry/reg_dynamic.c @@ -83,17 +83,20 @@ static int tcpip_params( REGVAL_CTR *regvals ) fstring value; int value_length; char *hname; - fstring mydomainname; - + char *mydomainname = NULL; hname = myhostname(); value_length = push_ucs2( value, value, hname, sizeof(value), STR_TERMINATE|STR_NOALIGN); regval_ctr_addvalue( regvals, "Hostname",REG_SZ, value, value_length ); - - get_mydnsdomname( mydomainname ); + + mydomainname = get_mydnsdomname(talloc_tos()); + if (!mydomainname) { + return -1; + } + value_length = push_ucs2( value, value, mydomainname, sizeof(value), STR_TERMINATE|STR_NOALIGN); regval_ctr_addvalue( regvals, "Domain", REG_SZ, value, value_length ); - + return regval_ctr_numvals( regvals ); } diff --git a/source3/rpc_server/srv_lsa_nt.c b/source3/rpc_server/srv_lsa_nt.c index ea2bc0fa7b..5c2e1b6f01 100644 --- a/source3/rpc_server/srv_lsa_nt.c +++ b/source3/rpc_server/srv_lsa_nt.c @@ -1927,10 +1927,12 @@ NTSTATUS _lsa_query_info2(pipes_struct *p, LSA_Q_QUERY_INFO2 *q_u, LSA_R_QUERY_I /* ugly temp hack for these next two */ /* This should be a 'netbios domain -> DNS domain' mapping */ - dnsdomname[0] = '\0'; - get_mydnsdomname(dnsdomname); + dnsdomname = get_mydnsdomname(p->mem_ctx); + if (!dnsdomname) { + return NT_STATUS_CANT_ACCESS_DOMAIN_INFO; + } strlower_m(dnsdomname); - + dns_name = dnsdomname; forest_name = dnsdomname; diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index aba56c2d05..fe7a12940e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -2401,20 +2401,20 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint return WERR_OK; } - if (!StrCaseCmp(value, "DNSMachineName")) { - pstring hostname; - - if (!get_mydnsfullname(hostname)) + if (!StrCaseCmp(value, "DNSMachineName")) { + const char *hostname = get_mydnsfullname(); + + if (!hostname) return WERR_BADFILE; *type = REG_SZ; - *needed = 2*(strlen(hostname)+1); + *needed = 2*(strlen(hostname)+1); if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL) return WERR_NOMEM; memset(*data, 0, (*needed > in_size) ? *needed:in_size); for (i=0; i<strlen(hostname); i++) { (*data)[2*i]=hostname[i]; (*data)[2*i+1]='\0'; - } + } return WERR_OK; } diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index d14caad975..5e85bae7ee 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -2070,7 +2070,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, REGVAL_CTR *reg_ctr; struct cli_state *cli_dst = NULL; char *devicename = NULL, *unc_name = NULL, *url = NULL; - fstring longname; + const char *longname; uint16 *keylist = NULL, *curkey; @@ -2094,12 +2094,16 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, printf ("no printers found on server.\n"); nt_status = NT_STATUS_OK; goto done; - } - + } + /* needed for dns-strings in regkeys */ - get_mydnsfullname(longname); - + longname = get_mydnsfullname(); + if (!longname) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + /* do something for all printers */ for (i = 0; i < num_printers; i++) { |