/* Note that caller frees the returned buffer if necessary */ static char * parse_server(char ** punc_name) { char * unc_name = *punc_name; int length = strnlen(unc_name,1024); char * share; char * ipaddress_string = NULL; struct hostent * host_entry = NULL; struct in_addr server_ipaddr; if(length > 1023) { printf("mount error: UNC name too long"); return NULL; } if (strncasecmp("cifs://",unc_name,7) == 0) return parse_cifs_url(unc_name+7); if (strncasecmp("smb://",unc_name,6) == 0) { return parse_cifs_url(unc_name+6); } if(length < 3) { /* BB add code to find DFS root here */ printf("\nMounting the DFS root for domain not implemented yet\n"); return NULL; } else { if(strncmp(unc_name,"//",2) && strncmp(unc_name,"\\\\",2)) { /* check for nfs syntax ie server:share */ share = strchr(unc_name,':'); if(share) { free_share_name = 1; *punc_name = malloc(length+3); if(*punc_name == NULL) { /* put the original string back if no memory left */ *punc_name = unc_name; return NULL; } *share = '/'; strncpy((*punc_name)+2,unc_name,length); unc_name = *punc_name; unc_name[length+2] = 0; goto continue_unc_parsing; } else { printf("mount error: improperly formatted UNC name."); printf(" %s does not begin with \\\\ or //\n",unc_name); return NULL; } } else { continue_unc_parsing: unc_name[0] = '/'; unc_name[1] = '/'; unc_name += 2; if ((share = strchr(unc_name, '/')) || (share = strchr(unc_name,'\\'))) { *share = 0; /* temporarily terminate the string */ share += 1; if(got_ip == 0) { host_entry = gethostbyname(unc_name); } *(share - 1) = '/'; /* put the slash back */ if(got_ip) { if(verboseflag) printf("ip address specified explicitly\n"); return NULL; } if(host_entry == NULL) { printf("mount error: could not find target server. TCP name %s not found\n", unc_name); return NULL; } else { /* BB should we pass an alternate version of the share name as Unicode */ /* BB what about ipv6? BB */ /* BB add retries with alternate servers in list */ memcpy(&server_ipaddr.s_addr, host_entry->h_addr, 4); ipaddress_string = inet_ntoa(server_ipaddr); if(ipaddress_string == NULL) { printf("mount error: could not get valid ip address for target server\n"); return NULL; } return ipaddress_string; } } else { /* BB add code to find DFS root (send null path on get DFS Referral to specified server here */ printf("Mounting the DFS root for a particular server not implemented yet\n"); return NULL; } } } }
/* Note that caller frees the returned buffer if necessary */ char * parse_server(char * unc_name) { int length = strnlen(unc_name,1024); char * share; char * ipaddress_string = NULL; struct hostent * host_entry; struct in_addr server_ipaddr; int rc; if(length > 1023) { printf("mount error: UNC name too long"); return 0; } if (strncasecmp("cifs://",unc_name,7) == 0) return parse_cifs_url(unc_name+7); if (strncasecmp("smb://",unc_name,6) == 0) { return parse_cifs_url(unc_name+6); } if(length < 3) { /* BB add code to find DFS root here */ printf("\nMounting the DFS root for domain not implemented yet"); return 0; } else { if(strncmp(unc_name,"//",2) && strncmp(unc_name,"\\\\",2)) { printf("mount error: improperly formatted UNC name."); printf(" %s does not begin with \\\\ or //\n",unc_name); return 0; } else { unc_name[0] = '\\'; unc_name[0] = '/'; unc_name[1] = '/'; unc_name += 2; if ((share = strchr(unc_name, '/')) || (share = strchr(unc_name,'\\'))) { *share = 0; /* temporarily terminate the string */ share += 1; host_entry = gethostbyname(unc_name); *(share - 1) = '/'; /* put the slash back */ /* rc = getipnodebyname(unc_name, AF_INET, AT_ADDRCONFIG ,&rc);*/ if(host_entry == NULL) { printf("mount error: could not find target server. TCP name %s not found ", unc_name); printf(" rc = %d\n",rc); return 0; } else { /* BB should we pass an alternate version of the share name as Unicode */ /* BB what about ipv6? BB */ /* BB add retries with alternate servers in list */ memcpy(&server_ipaddr.s_addr, host_entry->h_addr, 4); ipaddress_string = inet_ntoa(server_ipaddr); if(ipaddress_string == NULL) { printf("mount error: could not get valid ip address for target server\n"); return 0; } return ipaddress_string; } } else { /* BB add code to find DFS root (send null path on get DFS Referral to specified server here */ printf("Mounting the DFS root for a particular server not implemented yet\n"); return 0; } } } }