Exemplo n.º 1
0
/*
 * cifs_strndup_from_ucs - copy a string from wire format to the local codepage
 * @src - source string
 * @maxlen - don't walk past this many bytes in the source string
 * @is_unicode - is this a unicode string?
 * @codepage - destination codepage
 *
 * Take a string given by the server, convert it to the local codepage and
 * put it in a new buffer. Returns a pointer to the new string or NULL on
 * error.
 */
char *
cifs_strndup_from_ucs(const char *src, const int maxlen, const bool is_unicode,
	     const struct nls_table *codepage)
{
	int len;
	char *dst;

	if (is_unicode) {
		len = cifs_ucs2_bytes((__le16 *) src, maxlen, codepage);
		len += nls_nullsize(codepage);
		dst = kmalloc(len, GFP_KERNEL);
		if (!dst)
			return NULL;
		cifs_from_ucs2(dst, (__le16 *) src, len, maxlen, codepage,
			       false);
	} else {
		len = strnlen(src, maxlen);
		len++;
		dst = kmalloc(len, GFP_KERNEL);
		if (!dst)
			return NULL;
		strlcpy(dst, src, len);
	}

	return dst;
}
Exemplo n.º 2
0
/* Server has provided av pairs/target info in the type 2 challenge
 * packet and we have plucked it and stored within smb session.
 * We parse that blob here to find netbios domain name to be used
 * as part of ntlmv2 authentication (in Target String), if not already
 * specified on the command line.
 * If this function returns without any error but without fetching
 * domain name, authentication may fail against some server but
 * may not fail against other (those who are not very particular
 * about target string i.e. for some, just user name might suffice.
 */
static int
find_domain_name(struct cifsSesInfo *ses, const struct nls_table *nls_cp)
{
	unsigned int attrsize;
	unsigned int type;
	unsigned int onesize = sizeof(struct ntlmssp2_name);
	unsigned char *blobptr;
	unsigned char *blobend;
	struct ntlmssp2_name *attrptr;

	if (!ses->auth_key.len || !ses->auth_key.response)
		return 0;

	blobptr = ses->auth_key.response;
	blobend = blobptr + ses->auth_key.len;

	while (blobptr + onesize < blobend) {
		attrptr = (struct ntlmssp2_name *) blobptr;
		type = le16_to_cpu(attrptr->type);
		if (type == NTLMSSP_AV_EOL)
			break;
		blobptr += 2; /* advance attr type */
		attrsize = le16_to_cpu(attrptr->length);
		blobptr += 2; /* advance attr size */
		if (blobptr + attrsize > blobend)
			break;
		if (type == NTLMSSP_AV_NB_DOMAIN_NAME) {
			if (!attrsize)
				break;
			if (!ses->domainName) {
				ses->domainName =
					kmalloc(attrsize + 1, GFP_KERNEL);
				if (!ses->domainName)
						return -ENOMEM;
				cifs_from_ucs2(ses->domainName,
					(__le16 *)blobptr, attrsize, attrsize,
					nls_cp, false);
				break;
			}
		}
		blobptr += attrsize; /* advance attr  value */
	}

	return 0;
}
Exemplo n.º 3
0
/* inode num, inode type and filename returned */
static int cifs_get_name_from_search_buf(struct qstr *pqst,
        char *current_entry, __u16 level, unsigned int unicode,
        struct cifs_sb_info *cifs_sb, unsigned int max_len, __u64 *pinum)
{
    int rc = 0;
    unsigned int len = 0;
    char *filename;
    struct nls_table *nlt = cifs_sb->local_nls;

    *pinum = 0;

    if (level == SMB_FIND_FILE_UNIX) {
        FILE_UNIX_INFO *pFindData = (FILE_UNIX_INFO *)current_entry;

        filename = &pFindData->FileName[0];
        if (unicode) {
            len = cifs_unicode_bytelen(filename);
        } else {
            /* BB should we make this strnlen of PATH_MAX? */
            len = strnlen(filename, PATH_MAX);
        }

        *pinum = le64_to_cpu(pFindData->basic.UniqueId);
    } else if (level == SMB_FIND_FILE_DIRECTORY_INFO) {
        FILE_DIRECTORY_INFO *pFindData =
            (FILE_DIRECTORY_INFO *)current_entry;
        filename = &pFindData->FileName[0];
        len = le32_to_cpu(pFindData->FileNameLength);
    } else if (level == SMB_FIND_FILE_FULL_DIRECTORY_INFO) {
        FILE_FULL_DIRECTORY_INFO *pFindData =
            (FILE_FULL_DIRECTORY_INFO *)current_entry;
        filename = &pFindData->FileName[0];
        len = le32_to_cpu(pFindData->FileNameLength);
    } else if (level == SMB_FIND_FILE_ID_FULL_DIR_INFO) {
        SEARCH_ID_FULL_DIR_INFO *pFindData =
            (SEARCH_ID_FULL_DIR_INFO *)current_entry;
        filename = &pFindData->FileName[0];
        len = le32_to_cpu(pFindData->FileNameLength);
        *pinum = le64_to_cpu(pFindData->UniqueId);
    } else if (level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
        FILE_BOTH_DIRECTORY_INFO *pFindData =
            (FILE_BOTH_DIRECTORY_INFO *)current_entry;
        filename = &pFindData->FileName[0];
        len = le32_to_cpu(pFindData->FileNameLength);
    } else if (level == SMB_FIND_FILE_INFO_STANDARD) {
        FIND_FILE_STANDARD_INFO *pFindData =
            (FIND_FILE_STANDARD_INFO *)current_entry;
        filename = &pFindData->FileName[0];
        /* one byte length, no name conversion */
        len = (unsigned int)pFindData->FileNameLength;
    } else {
        cFYI(1, "Unknown findfirst level %d", level);
        return -EINVAL;
    }

    if (len > max_len) {
        cERROR(1, "bad search response length %d past smb end", len);
        return -EINVAL;
    }

    if (unicode) {
        pqst->len = cifs_from_ucs2((char *) pqst->name,
                                   (__le16 *) filename,
                                   UNICODE_NAME_MAX,
                                   min(len, max_len), nlt,
                                   cifs_sb->mnt_cifs_flags &
                                   CIFS_MOUNT_MAP_SPECIAL_CHR);
        pqst->len -= nls_nullsize(nlt);
    } else {
        pqst->name = filename;
        pqst->len = len;
    }
    return rc;
}
Exemplo n.º 4
0
static int cifs_filldir(char *find_entry, struct file *file, filldir_t filldir,
		void *dirent, char *scratch_buf, unsigned int max_len)
{
	struct cifsFileInfo *file_info = file->private_data;
	struct super_block *sb = file->f_path.dentry->d_sb;
	struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
	struct cifs_dirent de = { NULL, };
	struct cifs_fattr fattr;
	struct dentry *dentry;
	struct qstr name;
	int rc = 0;
	ino_t ino;

	rc = cifs_fill_dirent(&de, find_entry, file_info->srch_inf.info_level,
			      file_info->srch_inf.unicode);
	if (rc)
		return rc;

	if (de.namelen > max_len) {
		cERROR(1, "bad search response length %zd past smb end",
			  de.namelen);
		return -EINVAL;
	}

	/* skip . and .. since we added them first */
	if (cifs_entry_is_dot(&de, file_info->srch_inf.unicode))
		return 0;

	if (file_info->srch_inf.unicode) {
		struct nls_table *nlt = cifs_sb->local_nls;

		name.name = scratch_buf;
		name.len =
			cifs_from_ucs2((char *)name.name, (__le16 *)de.name,
				       UNICODE_NAME_MAX,
				       min(de.namelen, (size_t)max_len), nlt,
				       cifs_sb->mnt_cifs_flags &
						CIFS_MOUNT_MAP_SPECIAL_CHR);
		name.len -= nls_nullsize(nlt);
	} else {
		name.name = de.name;
		name.len = de.namelen;
	}

	switch (file_info->srch_inf.info_level) {
	case SMB_FIND_FILE_UNIX:
		cifs_unix_basic_to_fattr(&fattr,
					 &((FILE_UNIX_INFO *)find_entry)->basic,
					 cifs_sb);
		break;
	case SMB_FIND_FILE_INFO_STANDARD:
		cifs_std_info_to_fattr(&fattr,
				       (FIND_FILE_STANDARD_INFO *)find_entry,
				       cifs_sb);
		break;
	default:
		cifs_dir_info_to_fattr(&fattr,
				       (FILE_DIRECTORY_INFO *)find_entry,
				       cifs_sb);
		break;
	}

	if (de.ino && (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)) {
		fattr.cf_uniqueid = de.ino;
	} else {
		fattr.cf_uniqueid = iunique(sb, ROOT_I);
		cifs_autodisable_serverino(cifs_sb);
	}

	if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) &&
	    CIFSCouldBeMFSymlink(&fattr))
		/*
		 * trying to get the type and mode can be slow,
		 * so just call those regular files for now, and mark
		 * for reval
		 */
		fattr.cf_flags |= CIFS_FATTR_NEED_REVAL;

	ino = cifs_uniqueid_to_ino_t(fattr.cf_uniqueid);
	dentry = cifs_readdir_lookup(file->f_dentry, &name, &fattr);

	rc = filldir(dirent, name.name, name.len, file->f_pos, ino,
		     fattr.cf_dtype);

	dput(dentry);
	return rc;
}