/* * Get the current system node name. The returned name is guaranteed * to be null-terminated (gethostname may not null terminate the name). * If the hostname has been fully-qualified for some reason, the domain * part will be removed. The returned hostname is converted to the * specified case (lower, upper, or preserved). * * If gethostname fails, the returned buffer will contain an empty * string. */ int smb_gethostname(char *buf, size_t buflen, smb_caseconv_t which) { char *p; if (buf == NULL || buflen == 0) return (-1); if (gethostname(buf, buflen) != 0) { *buf = '\0'; return (-1); } buf[buflen - 1] = '\0'; if ((p = strchr(buf, '.')) != NULL) *p = '\0'; switch (which) { case SMB_CASE_LOWER: (void) smb_strlwr(buf); break; case SMB_CASE_UPPER: (void) smb_strupr(buf); break; case SMB_CASE_PRESERVE: default: break; } return (0); }
/* * samr_set_user_password * * Set the initial password for the user. * * Returns 0 if everything goes well, -1 if there is trouble generating a * key. */ static int samr_set_user_password(unsigned char *nt_key, BYTE *oem_password) { char hostname[NETBIOS_NAME_SZ]; randomize((char *)oem_password, SAMR_SET_USER_DATA_SZ); /* * The new password is going to be the NetBIOS name of the system * in lower case. */ if (smb_getnetbiosname(hostname, sizeof (hostname)) != 0) return (-1); (void) smb_strlwr(hostname); /* * Generate the OEM password from the hostname and the user session * key(nt_key). */ /*LINTED E_BAD_PTR_CAST_ALIGN*/ (void) sam_oem_password((oem_password_t *)oem_password, (unsigned char *)hostname, nt_key); return (0); }
/* * Extract the share name and share type and connect as appropriate. * Share names are case insensitive so we map the share name to * lower-case as a convenience for internal processing. */ smb_tree_t * smb_tree_connect(smb_request_t *sr) { char *unc_path = sr->arg.tcon.path; char *service = sr->arg.tcon.service; smb_tree_t *tree = NULL; const char *name; int32_t stype; (void) smb_strlwr(unc_path); if ((name = smb_tree_get_sharename(unc_path)) == NULL) { smbsr_error(sr, 0, ERRSRV, ERRinvnetname); return (NULL); } if (smb_tree_get_stype(name, service, &stype) != 0) { smbsr_error(sr, NT_STATUS_BAD_DEVICE_TYPE, ERRDOS, ERROR_BAD_DEV_TYPE); return (NULL); } switch (stype & STYPE_MASK) { case STYPE_DISKTREE: tree = smb_tree_connect_disk(sr, name); break; case STYPE_IPC: tree = smb_tree_connect_ipc(sr, name); break; default: smbsr_error(sr, NT_STATUS_BAD_DEVICE_TYPE, ERRDOS, ERROR_BAD_DEV_TYPE); break; } return (tree); }
/* * smb_pathname_preprocess_adminshare * * Convert any path with share name "C$" or "c$" (Admin share) in to lower case. */ static void smb_pathname_preprocess_adminshare(smb_request_t *sr, smb_pathname_t *pn) { if (strcasecmp(sr->tid_tree->t_sharename, "c$") == 0) (void) smb_strlwr(pn->pn_path); }