diff options
Diffstat (limited to 'usr/src/lib')
27 files changed, 404 insertions, 1429 deletions
diff --git a/usr/src/lib/libsmbfs/Makefile.com b/usr/src/lib/libsmbfs/Makefile.com index 656ba731b3..f7a6c06790 100644 --- a/usr/src/lib/libsmbfs/Makefile.com +++ b/usr/src/lib/libsmbfs/Makefile.com @@ -33,9 +33,8 @@ VERS= .1 # leaving out: kiconv.o -OBJECTS=\ +OBJ_LIB=\ acl_api.o \ - acl_conv.o \ acl_print.o \ charsets.o \ cfopt.o \ @@ -75,13 +74,19 @@ OBJECTS=\ ui-sun.o \ utf_str.o +OBJ_CMN= smbfs_ntacl.o + +OBJECTS= $(OBJ_LIB) $(OBJ_CMN) + include $(SRC)/lib/Makefile.lib LIBS = $(DYNLIB) $(LINTLIB) SRCDIR= ../smb +CMNDIR= $(SRC)/common/smbclnt -SRCS= $(OBJECTS:%.o=../smb/%.c) +SRCS= $(OBJ_LIB:%.o=$(SRCDIR)/%.c) \ + $(OBJ_CMN:%.o=$(CMNDIR)/%.c) $(LINTLIB) := SRCS = $(SRCDIR)/$(LINTSRC) @@ -93,7 +98,9 @@ LDLIBS += -lsocket -lnsl -lc -lmd -lpkcs11 -lkrb5 -lsec -lidmap CFLAGS += $(CCVERBOSE) CPPFLAGS += -D__EXTENSIONS__ -D_REENTRANT -DMIA \ - -I$(SRCDIR) -I.. -I$(SRC)/uts/common + -I$(SRCDIR) -I.. \ + -I$(SRC)/uts/common \ + -I$(SRC)/common/smbclnt # Debugging ${NOT_RELEASE_BUILD} CPPFLAGS += -DDEBUG @@ -104,15 +111,22 @@ ${NOT_RELEASE_BUILD} CPPFLAGS += -DDEBUG #CTFCONVERT_O= #CTFMERGE_LIB= -# disable some of the less important lint -LINTCHECKFLAGS += -erroff=E_FUNC_RET_ALWAYS_IGNOR2 -LINTCHECKFLAGS += -erroff=E_FUNC_RET_MAYBE_IGNORED2 -LINTCHECKFLAGS += -DDEBUG +# Filter out the less important lint. +# See lgrep.awk +LGREP = nawk -f $(SRCDIR)/lgrep.awk +LTAIL += 2>&1 | $(LGREP) all: $(LIBS) -lint: lintcheck +lint: lintcheck_t include ../../Makefile.targ +lintcheck_t: $$(SRCS) + $(LINT.c) $(LINTCHECKFLAGS) $(SRCS) $(LDLIBS) $(LTAIL) + +objs/%.o pics/%.o: $(CMNDIR)/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + .KEEP_STATE: diff --git a/usr/src/lib/libsmbfs/netsmb/smbfs_acl.h b/usr/src/lib/libsmbfs/netsmb/smbfs_acl.h index d1da5bda22..b8cf6a8036 100644 --- a/usr/src/lib/libsmbfs/netsmb/smbfs_acl.h +++ b/usr/src/lib/libsmbfs/netsmb/smbfs_acl.h @@ -61,37 +61,26 @@ int smbfs_acl_set(int fd, acl_t *, uid_t, gid_t); /* * Slightly lower-level functions, allowing access to * the raw Windows Security Descriptor (SD) + * + * The struct i_ntsid is opaque in this I/F. + * Real decl. in: common/smbclnt/smbfs_ntacl.h */ -typedef struct i_ntsd i_ntsd_t; +struct i_ntsd; /* * Get an "internal form" SD from the FD (opened in smbfs). * Allocates a hierarchy in isdp. Caller must free it via * smbfs_acl_free_isd() */ -int smbfs_acl_getsd(int fd, uint32_t, i_ntsd_t **); +int smbfs_acl_getsd(int fd, uint32_t, struct i_ntsd **); /* * Set an "internal form" SD onto the FD (opened in smbfs). */ -int smbfs_acl_setsd(int fd, uint32_t, i_ntsd_t *); - -/* - * Convert an internal SD to a ZFS-style ACL. - * Get uid/gid too if pointers != NULL. - */ -int smbfs_acl_sd2zfs(i_ntsd_t *, acl_t *, uid_t *, gid_t *); - -/* - * Convert an internal SD to a ZFS-style ACL. - * Include owner/group too if uid/gid != -1. - */ -int smbfs_acl_zfs2sd(acl_t *, uid_t, gid_t, i_ntsd_t **); - -void smbfs_acl_free_sd(i_ntsd_t *); +int smbfs_acl_setsd(int fd, uint32_t, struct i_ntsd *); struct __FILE; -void smbfs_acl_print_sd(struct __FILE *, i_ntsd_t *); +void smbfs_acl_print_sd(struct __FILE *, struct i_ntsd *); #ifdef __cplusplus } diff --git a/usr/src/lib/libsmbfs/smb/acl_api.c b/usr/src/lib/libsmbfs/smb/acl_api.c index 3e9d703c99..b5b6123063 100644 --- a/usr/src/lib/libsmbfs/smb/acl_api.c +++ b/usr/src/lib/libsmbfs/smb/acl_api.c @@ -53,7 +53,7 @@ #include <netsmb/smb_lib.h> #include <netsmb/smbfs_acl.h> -#include "acl_nt.h" +#include "smbfs_ntacl.h" #include "private.h" /* Sanity check SD sizes */ @@ -78,7 +78,7 @@ smbfs_acl_iocget(int fd, uint32_t selector, mbdata_t *mbp) struct mbuf *m; int error; - error = mb_init(mbp, MAX_RAW_SD_SIZE); + error = mb_init_sz(mbp, MAX_RAW_SD_SIZE); if (error) return (error); @@ -157,7 +157,7 @@ smbfs_acl_getsd(int fd, uint32_t selector, i_ntsd_t **sdp) * (like "absolute" form per. NT docs) * Returns allocated data in sdp */ - error = mb_get_ntsd(mbp, sdp); + error = md_get_ntsd(mbp, sdp); } mb_done(mbp); @@ -174,7 +174,9 @@ smbfs_acl_setsd(int fd, uint32_t selector, i_ntsd_t *sd) int error; mbp = &mb_store; - mb_init(mbp, M_MINSIZE); + error = mb_init_sz(mbp, MAX_RAW_SD_SIZE); + if (error) + return (error); /* * Export the "internal" SD into an mb chain. diff --git a/usr/src/lib/libsmbfs/smb/acl_conv.c b/usr/src/lib/libsmbfs/smb/acl_conv.c deleted file mode 100644 index d19b323dfe..0000000000 --- a/usr/src/lib/libsmbfs/smb/acl_conv.c +++ /dev/null @@ -1,942 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * ACL support for smbfs - * - * May want to move some of this to usr/src/common - * and compile with the smbfs kmod too, once we - * implement VOP_GETSECATTR, VOP_SETSECATTR. - */ - -#include <sys/types.h> -#include <sys/errno.h> -#include <sys/cred.h> -#include <sys/cmn_err.h> -#include <sys/kmem.h> -#include <sys/sunddi.h> -#include <sys/acl.h> -#include <sys/vnode.h> -#include <sys/vfs.h> -#include <sys/byteorder.h> - -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <strings.h> -#include <unistd.h> - -#include <umem.h> -#include <idmap.h> - -#include <sys/fs/smbfs_ioctl.h> - -#include <netsmb/mchain.h> -#include <netsmb/smb.h> - -#include <netsmb/smb_lib.h> -#include <netsmb/smbfs_acl.h> - -#include "acl_nt.h" -#include "private.h" - -#ifdef _KERNEL -#define MALLOC(size) kmem_alloc(size, KM_SLEEP) -#define FREESZ(p, sz) kmem_free(p, sz) -#else /* _KERNEL */ -#define MALLOC(size) malloc(size) -#ifndef lint -#define FREESZ(p, sz) free(p) -#else /* lint */ -/* ARGSUSED */ -static void -FREESZ(void *p, size_t sz) -{ - free(p); -} -#endif /* lint */ -#endif /* _KERNEL */ - - -#define ERRCHK(expr) if ((error = expr) != 0) goto errout - -/* - * Security IDentifier (SID) - */ -static void -ifree_sid(i_ntsid_t *sid) -{ - size_t sz; - - if (sid == NULL) - return; - - sz = I_SID_SIZE(sid->sid_subauthcount); - FREESZ(sid, sz); -} - -static int -mb_get_sid(mbdata_t *mbp, i_ntsid_t **sidp) -{ - i_ntsid_t *sid = NULL; - uint8_t revision, subauthcount; - uint32_t *subauthp; - size_t sidsz; - int error, i; - - if ((error = mb_get_uint8(mbp, &revision)) != 0) - return (error); - if ((error = mb_get_uint8(mbp, &subauthcount)) != 0) - return (error); - - sidsz = I_SID_SIZE(subauthcount); - - if ((sid = MALLOC(sidsz)) == NULL) - return (ENOMEM); - - bzero(sid, sidsz); - sid->sid_revision = revision; - sid->sid_subauthcount = subauthcount; - ERRCHK(mb_get_mem(mbp, (char *)sid->sid_authority, 6)); - - subauthp = &sid->sid_subauthvec[0]; - for (i = 0; i < subauthcount; i++) { - ERRCHK(mb_get_uint32le(mbp, subauthp)); - subauthp++; - } - - /* Success! */ - *sidp = sid; - return (0); - -errout: - ifree_sid(sid); - return (error); -} - -static int -mb_put_sid(mbdata_t *mbp, i_ntsid_t *sid) -{ - uint32_t *subauthp; - int error, i; - - if (sid == NULL) - return (EINVAL); - - ERRCHK(mb_put_uint8(mbp, sid->sid_revision)); - ERRCHK(mb_put_uint8(mbp, sid->sid_subauthcount)); - ERRCHK(mb_put_mem(mbp, (char *)sid->sid_authority, 6)); - - subauthp = &sid->sid_subauthvec[0]; - for (i = 0; i < sid->sid_subauthcount; i++) { - ERRCHK(mb_put_uint32le(mbp, *subauthp)); - subauthp++; - } - - /* Success! */ - return (0); - -errout: - return (error); -} - - -/* - * Access Control Entry (ACE) - */ -static void -ifree_ace(i_ntace_t *ace) -{ - - if (ace == NULL) - return; - - ifree_sid(ace->ace_sid); - FREESZ(ace, sizeof (*ace)); -} - -static int -mb_get_ace(mbdata_t *mbp, i_ntace_t **acep) -{ - mbdata_t tmp_mb; - i_ntace_t *ace = NULL; - uint16_t ace_len; - int error; - - if ((ace = MALLOC(sizeof (*ace))) == NULL) - return (ENOMEM); - bzero(ace, sizeof (*ace)); - - /* - * The ACE is realy variable length, - * with format determined by the type. - * XXX: This only decodes types 0-7 - * - * There may also be padding after it, so - * decode the using a copy of the mbdata, - * and then consume the specified length. - */ - tmp_mb = *mbp; - - /* Fixed-size header */ - ERRCHK(mb_get_uint8(&tmp_mb, &ace->ace_type)); - ERRCHK(mb_get_uint8(&tmp_mb, &ace->ace_flags)); - ERRCHK(mb_get_uint16le(&tmp_mb, &ace_len)); - - /* Variable-size body */ - ERRCHK(mb_get_uint32le(&tmp_mb, &ace->ace_rights)); - ERRCHK(mb_get_sid(&tmp_mb, &ace->ace_sid)); - - /* Now actually consume ace_len */ - ERRCHK(mb_get_mem(mbp, NULL, ace_len)); - - /* Success! */ - *acep = ace; - return (0); - -errout: - ifree_ace(ace); - return (error); -} - -static int -mb_put_ace(mbdata_t *mbp, i_ntace_t *ace) -{ - int cnt0, error; - uint16_t ace_len, *ace_len_p; - - if (ace == NULL) - return (EINVAL); - - cnt0 = mbp->mb_count; - - ERRCHK(mb_put_uint8(mbp, ace->ace_type)); - ERRCHK(mb_put_uint8(mbp, ace->ace_flags)); - ERRCHK(mb_fit(mbp, 2, (char **)&ace_len_p)); - ERRCHK(mb_put_uint32le(mbp, ace->ace_rights)); - - ERRCHK(mb_put_sid(mbp, ace->ace_sid)); - - ace_len = mbp->mb_count - cnt0; - *ace_len_p = htoles(ace_len); - - /* Success! */ - return (0); - -errout: - return (error); -} - - -/* - * Access Control List (ACL) - */ - -/* Not an OTW structure, so size can be at our convenience. */ -#define I_ACL_SIZE(cnt) (sizeof (i_ntacl_t) + (cnt) * sizeof (void *)) - -static void -ifree_acl(i_ntacl_t *acl) -{ - i_ntace_t **acep; - size_t sz; - int i; - - if (acl == NULL) - return; - - acep = &acl->acl_acevec[0]; - for (i = 0; i < acl->acl_acecount; i++) { - ifree_ace(*acep); - acep++; - } - sz = I_ACL_SIZE(acl->acl_acecount); - FREESZ(acl, sz); -} - -static int -mb_get_acl(mbdata_t *mbp, i_ntacl_t **aclp) -{ - i_ntacl_t *acl = NULL; - i_ntace_t **acep; - uint8_t revision; - uint16_t acl_len, acecount; - size_t aclsz; - int i, error; - - if ((error = mb_get_uint8(mbp, &revision)) != 0) - return (error); - if ((error = mb_get_uint8(mbp, NULL)) != 0) - return (error); - if ((error = mb_get_uint16le(mbp, &acl_len)) != 0) - return (error); - if ((error = mb_get_uint16le(mbp, &acecount)) != 0) - return (error); - if ((error = mb_get_uint16(mbp, NULL)) != 0) - return (error); - - aclsz = I_ACL_SIZE(acecount); - if ((acl = MALLOC(aclsz)) == NULL) - return (ENOMEM); - bzero(acl, aclsz); - acl->acl_revision = revision; - acl->acl_acecount = acecount; - - acep = &acl->acl_acevec[0]; - for (i = 0; i < acl->acl_acecount; i++) { - ERRCHK(mb_get_ace(mbp, acep)); - acep++; - } - /* - * There may be more data here, but - * the caller takes care of that. - */ - - /* Success! */ - *aclp = acl; - return (0); - -errout: - ifree_acl(acl); - return (error); -} - -static int -mb_put_acl(mbdata_t *mbp, i_ntacl_t *acl) -{ - i_ntace_t **acep; - uint16_t acl_len, *acl_len_p; - int i, cnt0, error; - - cnt0 = mbp->mb_count; - - ERRCHK(mb_put_uint8(mbp, acl->acl_revision)); - ERRCHK(mb_put_uint8(mbp, 0)); /* pad1 */ - ERRCHK(mb_fit(mbp, 2, (char **)&acl_len_p)); - ERRCHK(mb_put_uint16le(mbp, acl->acl_acecount)); - ERRCHK(mb_put_uint16le(mbp, 0)); /* pad2 */ - - acep = &acl->acl_acevec[0]; - for (i = 0; i < acl->acl_acecount; i++) { - ERRCHK(mb_put_ace(mbp, *acep)); - acep++; - } - - /* Fill in acl_len_p */ - acl_len = mbp->mb_count - cnt0; - *acl_len_p = htoles(acl_len); - - /* Success! */ - return (0); - -errout: - return (error); -} - - -/* - * Security Descriptor - */ -void -smbfs_acl_free_sd(i_ntsd_t *sd) -{ - - if (sd == NULL) - return; - - ifree_sid(sd->sd_owner); - ifree_sid(sd->sd_group); - ifree_acl(sd->sd_sacl); - ifree_acl(sd->sd_dacl); - - FREESZ(sd, sizeof (*sd)); -} - -/* - * Import a raw SD (mb chain) into "internal" form. - * (like "absolute" form per. NT docs) - * Returns allocated data in sdp - * - * Note: does NOT consume all the mbp data, so the - * caller has to take care of that if necessary. - */ -int -mb_get_ntsd(mbdata_t *mbp, i_ntsd_t **sdp) -{ - i_ntsd_t *sd = NULL; - mbdata_t top_mb, tmp_mb; - uint32_t owneroff, groupoff, sacloff, dacloff; - int error; - - if ((sd = MALLOC(sizeof (*sd))) == NULL) - return (ENOMEM); - bzero(sd, sizeof (*sd)); - - /* - * Offsets below are relative to this point, - * so save the mbp state for use below. - */ - top_mb = *mbp; - - ERRCHK(mb_get_uint8(mbp, &sd->sd_revision)); - ERRCHK(mb_get_uint8(mbp, NULL)); - ERRCHK(mb_get_uint16le(mbp, &sd->sd_flags)); - ERRCHK(mb_get_uint32le(mbp, &owneroff)); - ERRCHK(mb_get_uint32le(mbp, &groupoff)); - ERRCHK(mb_get_uint32le(mbp, &sacloff)); - ERRCHK(mb_get_uint32le(mbp, &dacloff)); - - /* - * For each section make a temporary copy of the - * top_mb state, advance to the given offset, and - * pass that to the lower mb_get_xxx functions. - * These could be marshalled in any order, but - * are normally found in the order shown here. - */ - if (sacloff) { - tmp_mb = top_mb; - mb_get_mem(&tmp_mb, NULL, sacloff); - ERRCHK(mb_get_acl(&tmp_mb, &sd->sd_sacl)); - } - if (dacloff) { - tmp_mb = top_mb; - mb_get_mem(&tmp_mb, NULL, dacloff); - ERRCHK(mb_get_acl(&tmp_mb, &sd->sd_dacl)); - } - if (owneroff) { - tmp_mb = top_mb; - mb_get_mem(&tmp_mb, NULL, owneroff); - ERRCHK(mb_get_sid(&tmp_mb, &sd->sd_owner)); - } - if (groupoff) { - tmp_mb = top_mb; - mb_get_mem(&tmp_mb, NULL, groupoff); - ERRCHK(mb_get_sid(&tmp_mb, &sd->sd_group)); - } - - /* Success! */ - *sdp = sd; - return (0); - -errout: - smbfs_acl_free_sd(sd); - return (error); -} - -/* - * Export an "internal" SD into an raw SD (mb chain). - * (a.k.a "self-relative" form per. NT docs) - * Returns allocated mbchain in mbp. - */ -int -mb_put_ntsd(mbdata_t *mbp, i_ntsd_t *sd) -{ - uint32_t *owneroffp, *groupoffp, *sacloffp, *dacloffp; - uint32_t owneroff, groupoff, sacloff, dacloff; - int cnt0, error; - - cnt0 = mbp->mb_count; - owneroff = groupoff = sacloff = dacloff = 0; - - ERRCHK(mb_put_uint8(mbp, sd->sd_revision)); - ERRCHK(mb_put_uint8(mbp, 0)); /* pad1 */ - ERRCHK(mb_put_uint16le(mbp, sd->sd_flags)); - ERRCHK(mb_fit(mbp, 4, (char **)&owneroffp)); - ERRCHK(mb_fit(mbp, 4, (char **)&groupoffp)); - ERRCHK(mb_fit(mbp, 4, (char **)&sacloffp)); - ERRCHK(mb_fit(mbp, 4, (char **)&dacloffp)); - - /* - * These could be marshalled in any order, but - * are normally found in the order shown here. - */ - if (sd->sd_sacl) { - sacloff = mbp->mb_count - cnt0; - ERRCHK(mb_put_acl(mbp, sd->sd_sacl)); - } - if (sd->sd_dacl) { - dacloff = mbp->mb_count - cnt0; - ERRCHK(mb_put_acl(mbp, sd->sd_dacl)); - } - if (sd->sd_owner) { - owneroff = mbp->mb_count - cnt0; - ERRCHK(mb_put_sid(mbp, sd->sd_owner)); - } - if (sd->sd_group) { - groupoff = mbp->mb_count - cnt0; - ERRCHK(mb_put_sid(mbp, sd->sd_group)); - } - - /* Fill in the offsets */ - *owneroffp = htolel(owneroff); - *groupoffp = htolel(groupoff); - *sacloffp = htolel(sacloff); - *dacloffp = htolel(dacloff); - - /* Success! */ - return (0); - -errout: - return (error); -} - - -/* - * Helper functions for conversion between ZFS-style ACLs - * and Windows Security Descriptors. - */ - - -/* - * Convert an NT SID to a string. Optionally return the - * last sub-authority (or "relative ID" -- RID) in *ridp - * and truncate the output string after the domain part. - * If ridp==NULL, the output string is the whole SID, - * including both the domain and RID. - * - * Return length written, or -1 on error. - */ -int -smbfs_sid2str(i_ntsid_t *sid, - char *obuf, size_t osz, uint32_t *ridp) -{ - char *s = obuf; - uint64_t auth = 0; - uint_t i, n; - uint32_t subs, *ip; - - n = snprintf(s, osz, "S-%u", sid->sid_revision); - if (n > osz) - return (-1); - s += n; osz -= n; - - for (i = 0; i < 6; i++) - auth = (auth << 8) | sid->sid_authority[i]; - n = snprintf(s, osz, "-%llu", auth); - if (n > osz) - return (-1); - s += n; osz -= n; - - subs = sid->sid_subauthcount; - if (subs < 1 || subs > 15) - return (-1); - if (ridp) - subs--; - - ip = &sid->sid_subauthvec[0]; - for (; subs; subs--, ip++) { - n = snprintf(s, osz, "-%u", *ip); - if (n > osz) - return (-1); - s += n; osz -= n; - } - if (ridp) - *ridp = *ip; - - return (s - obuf); -} - -/* - * Our interface to the idmap service. - */ - -#ifdef _KERNEL -#define I_GetPidBySid kidmap_batch_getpidbysid -#define I_GetMappings kidmap_get_mappings -#else /* _KERNEL */ -#define I_GetPidBySid idmap_get_pidbysid -#define I_GetMappings idmap_get_mappings -#endif /* _KERNEL */ - -struct mapinfo { - uid_t mi_uid; /* or gid */ - int mi_isuser; - idmap_stat mi_status; -}; - -/* - * A special value for mi_isuser (above) to indicate - * that the SID is the well-known "Everyone" (S-1-1-0). - * The idmap library only uses -1, 0, 1, so this value - * is arbitrary but must not overlap w/ idmap values. - * XXX: Could use a way for idmap to tell us when - * it recognizes this well-known SID. - */ -#define IS_WKSID_EVERYONE 11 - -/* - * Build an idmap request. Cleanup is - * handled by the caller (error or not) - */ -static int -mkrq_idmap_sid2ux( - idmap_get_handle_t *idmap_gh, - i_ntsid_t *sid, - struct mapinfo *mip) -{ - char sid_prefix[256]; - uint32_t rid; - idmap_stat idms; - - if (smbfs_sid2str(sid, sid_prefix, sizeof (sid_prefix), &rid) < 0) - return (EINVAL); - - /* - * Give the "Everyone" group special treatment. - */ - if (strcmp(sid_prefix, "S-1-1") == 0 && rid == 0) { - /* This is "Everyone" */ - mip->mi_uid = (uid_t)-1; - mip->mi_isuser = IS_WKSID_EVERYONE; - mip->mi_status = 0; - return (0); - } - - idms = I_GetPidBySid(idmap_gh, sid_prefix, rid, 0, - &mip->mi_uid, &mip->mi_isuser, &mip->mi_status); - if (idms != IDMAP_SUCCESS) - return (EINVAL); - - return (0); -} - -static void -ntace2zace(ace_t *zacep, i_ntace_t *ntace, struct mapinfo *mip) -{ - uint32_t zamask; - uint16_t zflags, ntflags; - uint8_t zatype = ntace->ace_type; - - /* - * Translate NT ACE flags to ZFS ACE flags. - * The low four bits are the same, but not - * others: INHERITED_ACE_FLAG, etc. - */ - ntflags = ntace->ace_flags; - zflags = 0; - - if (ntflags & OBJECT_INHERIT_ACE_FLAG) - zflags |= ACE_FILE_INHERIT_ACE; - if (ntflags & CONTAINER_INHERIT_ACE_FLAG) - zflags |= ACE_DIRECTORY_INHERIT_ACE; - if (ntflags & NO_PROPAGATE_INHERIT_ACE_FLAG) - zflags |= ACE_NO_PROPAGATE_INHERIT_ACE; - if (ntflags & INHERIT_ONLY_ACE_FLAG) - zflags |= ACE_INHERIT_ONLY_ACE; - if (ntflags & INHERITED_ACE_FLAG) - zflags |= ACE_INHERITED_ACE; - - if (ntflags & SUCCESSFUL_ACCESS_ACE_FLAG) - zflags |= ACE_SUCCESSFUL_ACCESS_ACE_FLAG; - if (ntflags & FAILED_ACCESS_ACE_FLAG) - zflags |= ACE_FAILED_ACCESS_ACE_FLAG; - - /* - * Add the "ID type" flags to the ZFS ace flags. - * Would be nice if the idmap header defined some - * manifest constants for these "isuser" values. - */ - switch (mip->mi_isuser) { - case IS_WKSID_EVERYONE: - zflags |= ACE_EVERYONE; - break; - case 0: /* it's a GID */ - zflags |= ACE_IDENTIFIER_GROUP; - break; - default: - case 1: /* it's a UID */ - break; - } - - /* - * The access mask bits are the same, but - * mask off any bits we don't expect. - * Should not see any GENERIC_xxx flags, - * as those are only valid in requested - * access masks, not ACLs. But if we do, - * get those, silently clear them here. - */ - zamask = ntace->ace_rights & ACE_ALL_PERMS; - - /* - * Verify that it's a known ACE type. - * Only handle the types that appear in - * V2, V3, V4 ACLs for now. Avoid failing - * the whole conversion if we get unknown - * ace types, but convert them to something - * that will have no effect on access. - */ - if (zatype > SYSTEM_ALARM_OBJECT_ACE_TYPE) { - zatype = ACCESS_ALLOWED_ACE_TYPE; - zamask = 0; /* harmless */ - } - - /* - * Fill in the ZFS-style ACE - */ - zacep->a_who = mip->mi_uid; /* from ace_sid */ - zacep->a_access_mask = zamask; - zacep->a_flags = zflags; - zacep->a_type = zatype; -} - -/* - * Convert an internal SD to a ZFS-style ACL. - * Note optional args: vsa/acl, uidp, gidp. - */ -int -smbfs_acl_sd2zfs( - i_ntsd_t *sd, -#ifdef _KERNEL - vsecattr_t *acl_info, -#else /* _KERNEL */ - acl_t *acl_info, -#endif /* _KERNEL */ - uid_t *uidp, gid_t *gidp) -{ - struct mapinfo *mip, *mapinfo = NULL; - int error, i, mapcnt, zacecnt, zacl_size; - ace_t *zacep; - i_ntacl_t *ntacl; - i_ntace_t **ntacep; -#ifndef _KERNEL - idmap_handle_t *idmap_h = NULL; -#endif /* _KERNEL */ - idmap_get_handle_t *idmap_gh = NULL; - idmap_stat idms; - - /* - * sanity checks - */ -#ifndef _KERNEL - if (acl_info) { - if (acl_info->acl_type != ACE_T || - acl_info->acl_aclp != NULL || - acl_info->acl_entry_size != sizeof (ace_t)) - return (EINVAL); - } -#endif /* _KERNEL */ - - /* - * First, get all the SID mappings. - * How many? - */ - mapcnt = 0; - if (sd->sd_owner) - mapcnt++; - if (sd->sd_group) - mapcnt++; - if (sd->sd_sacl) - mapcnt += sd->sd_sacl->acl_acecount; - if (sd->sd_dacl) - mapcnt += sd->sd_dacl->acl_acecount; - if (mapcnt == 0) - return (EINVAL); - - mapinfo = MALLOC(mapcnt * sizeof (*mapinfo)); - if (mapinfo == NULL) { - error = ENOMEM; - goto errout; - } - bzero(mapinfo, mapcnt * sizeof (*mapinfo)); - - - /* - * Build our request to the idmap deamon. - */ -#ifdef _KERNEL - idmap_gh = kidmap_get_create(curproc->p_zone); -#else /* _KERNEL */ - idms = idmap_init(&idmap_h); - if (idms != IDMAP_SUCCESS) { - error = ENOTACTIVE; - goto errout; - } - idms = idmap_get_create(idmap_h, &idmap_gh); - if (idms != IDMAP_SUCCESS) { - error = ENOTACTIVE; - goto errout; - } -#endif /* _KERNEL */ - - mip = mapinfo; - if (sd->sd_owner) { - error = mkrq_idmap_sid2ux( - idmap_gh, sd->sd_owner, mip); - if (error) - goto errout; - mip++; - } - if (sd->sd_group) { - error = mkrq_idmap_sid2ux( - idmap_gh, sd->sd_group, mip); - if (error) - goto errout; - mip++; - } - if (sd->sd_sacl) { - ntacl = sd->sd_sacl; - ntacep = &ntacl->acl_acevec[0]; - for (i = 0; i < ntacl->acl_acecount; i++) { - error = mkrq_idmap_sid2ux( - idmap_gh, (*ntacep)->ace_sid, mip); - if (error) - goto errout; - ntacep++; - mip++; - } - } - if (sd->sd_dacl) { - ntacl = sd->sd_dacl; - ntacep = &ntacl->acl_acevec[0]; - for (i = 0; i < ntacl->acl_acecount; i++) { - error = mkrq_idmap_sid2ux( - idmap_gh, (*ntacep)->ace_sid, mip); - if (error) - goto errout; - ntacep++; - mip++; - } - } - - idms = I_GetMappings(idmap_gh); - if (idms != IDMAP_SUCCESS) { -#ifdef DEBUG - printf("idmap_get_mappings: rc=%d\n", idms); -#endif - /* creative error choice */ - error = EIDRM; - goto errout; - } - - /* - * With any luck, we now have Unix user/group IDs - * for every Windows SID in the security descriptor. - * The remaining work is just format conversion. - */ - mip = mapinfo; - if (sd->sd_owner) { - if (uidp) { - if (mip->mi_isuser == 1) - *uidp = mip->mi_uid; - else - *uidp = (uid_t)-1; - } - mip++; - } else { - if (uidp) - *uidp = (uid_t)-1; - } - if (sd->sd_group) { - if (gidp) { - if (mip->mi_isuser == 0) - *gidp = (gid_t)mip->mi_uid; - else - *gidp = (gid_t)-1; - } - mip++; - } else { - if (gidp) - *gidp = (gid_t)-1; - } - - if (acl_info == NULL) { - /* Caller only wanted uid/gid */ - goto ok_out; - } - - /* - * Build the ZFS-style ACL - */ - zacecnt = 0; - if (sd->sd_sacl) - zacecnt += sd->sd_sacl->acl_acecount; - if (sd->sd_dacl) - zacecnt += sd->sd_dacl->acl_acecount; - zacl_size = zacecnt * sizeof (ace_t); - zacep = MALLOC(zacl_size); -#ifdef _KERNEL - acl_info->vsa_aclentp = zacep; - acl_info->vsa_aclentsz = zacl_size; -#else /* _KERNEL */ - if (zacep == NULL) { - error = ENOMEM; - goto errout; - } - acl_info->acl_cnt = zacecnt; - acl_info->acl_aclp = zacep; -#endif /* _KERNEL */ - - if (sd->sd_sacl) { - ntacl = sd->sd_sacl; - ntacep = &ntacl->acl_acevec[0]; - for (i = 0; i < ntacl->acl_acecount; i++) { - ntace2zace(zacep, *ntacep, mip); - zacep++; - ntacep++; - mip++; - } - } - if (sd->sd_dacl) { - ntacl = sd->sd_dacl; - ntacep = &ntacl->acl_acevec[0]; - for (i = 0; i < ntacl->acl_acecount; i++) { - ntace2zace(zacep, *ntacep, mip); - zacep++; - ntacep++; - mip++; - } - } - -ok_out: - error = 0; - -errout: - if (mapinfo) - FREESZ(mapinfo, mapcnt * sizeof (*mapinfo)); - - return (error); -} - - -/* - * Convert an internal SD to a ZFS-style ACL. - * Include owner/group too if uid/gid != -1. - * Note optional arg: vsa/acl - */ -/*ARGSUSED*/ -int smbfs_acl_zfs2sd( -#ifdef _KERNEL - vsecattr_t *vsa, -#else /* _KERNEL */ - acl_t *acl, -#endif /* _KERNEL */ - uid_t uid, gid_t gid, - i_ntsd_t **sdp) -{ - /* XXX - todo */ - return (ENOSYS); -} diff --git a/usr/src/lib/libsmbfs/smb/acl_nt.h b/usr/src/lib/libsmbfs/smb/acl_nt.h deleted file mode 100644 index 844a7e6543..0000000000 --- a/usr/src/lib/libsmbfs/smb/acl_nt.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _ACL_NT_H -#define _ACL_NT_H - -/* - * Internal functions for dealing with - * NT Security data structures. - */ - -#include <netsmb/smbfs_acl.h> - -/* - * Internal form of an NT SID - * Same as on the wire, but possibly byte-swapped. - */ -typedef struct i_ntsid { - uint8_t sid_revision; - uint8_t sid_subauthcount; - uint8_t sid_authority[6]; - uint32_t sid_subauthvec[1]; /* actually len=subauthcount */ -} i_ntsid_t; -#define I_SID_SIZE(sacnt) (8 + 4 * (sacnt)) - -/* - * Internal form of an NT ACE - */ -typedef struct i_ntace { - uint8_t ace_type; - uint8_t ace_flags; - uint32_t ace_rights; /* generic, standard, specific, etc */ - i_ntsid_t *ace_sid; -} i_ntace_t; - -/* - * Internal form of an NT ACL (see sacl/dacl below) - */ -typedef struct i_ntacl { - uint8_t acl_revision; /* 0x02 observed with W2K */ - uint16_t acl_acecount; - i_ntace_t *acl_acevec[1]; /* actually, len=acecount */ -} i_ntacl_t; - -/* - * Internal form of an NT Security Descriptor (SD) - */ -struct i_ntsd { - uint8_t sd_revision; /* 0x01 observed between W2K */ - uint16_t sd_flags; - i_ntsid_t *sd_owner; - i_ntsid_t *sd_group; - i_ntacl_t *sd_sacl; - i_ntacl_t *sd_dacl; -}; - -struct mbdata; - -/* - * Import a raw SD (mb chain) into "internal" form. - * (like "absolute" form per. NT docs) - * Returns allocated data in sdp - */ -int mb_get_ntsd(struct mbdata *mbp, i_ntsd_t **sdp); - -/* - * Export an "internal" SD into an raw SD (mb chain). - * (a.k.a "self-relative" form per. NT docs) - * Returns allocated mbchain in mbp. - */ -int mb_put_ntsd(struct mbdata *mbp, i_ntsd_t *sd); - - -/* - * Get an SD via ioctl on FD (with "selector" bits), - * stroing the raw Windows SD in the mb chain mbp. - */ -int smbfs_acl_iocget(int fd, uint32_t selector, struct mbdata *mbp); - -/* - * Set an SD via ioctl on FD (with "selector" bits), - * with a raw Windows SD from the chain mbp. - */ -int smbfs_acl_iocset(int fd, uint32_t selector, struct mbdata *mbp); - - -int smbfs_sid2str(i_ntsid_t *sid, - char *obuf, size_t olen, uint32_t *ridp); - -#endif /* _ACL_NT_H */ diff --git a/usr/src/lib/libsmbfs/smb/acl_print.c b/usr/src/lib/libsmbfs/smb/acl_print.c index 259258a9f1..6d399e32aa 100644 --- a/usr/src/lib/libsmbfs/smb/acl_print.c +++ b/usr/src/lib/libsmbfs/smb/acl_print.c @@ -53,7 +53,7 @@ #include <netsmb/smb_lib.h> #include <netsmb/smbfs_acl.h> -#include "acl_nt.h" +#include "smbfs_ntacl.h" static void fprint_sid(FILE *fp, i_ntsid_t *sid) diff --git a/usr/src/lib/libsmbfs/smb/ctx.c b/usr/src/lib/libsmbfs/smb/ctx.c index 04057ac334..40a62a3853 100644 --- a/usr/src/lib/libsmbfs/smb/ctx.c +++ b/usr/src/lib/libsmbfs/smb/ctx.c @@ -253,22 +253,30 @@ smb_ctx_init(struct smb_ctx *ctx) ctx->ct_authflags = SMB_AT_DEFAULT; ctx->ct_minauth = SMB_AT_DEFAULT; - nb_ctx_setscope(ctx->ct_nb, ""); + error = nb_ctx_setscope(ctx->ct_nb, ""); + if (error) + return (error); /* * if the user name is not specified some other way, * use the current user name (built-in default) */ if (getpwuid_r(getuid(), &pw, pwbuf, sizeof (pwbuf)) != NULL) { - smb_ctx_setuser(ctx, pw.pw_name, 0); + error = smb_ctx_setuser(ctx, pw.pw_name, 0); + if (error) + return (error); ctx->ct_home = strdup(pw.pw_name); + if (ctx->ct_home == NULL) + return (ENOMEM); } /* * Set a built-in default domain (workgroup). * Using the Windows/NT default for now. */ - smb_ctx_setdomain(ctx, "WORKGROUP", 0); + error = smb_ctx_setdomain(ctx, "WORKGROUP", 0); + if (error) + return (error); return (error); } @@ -571,7 +579,7 @@ smb_ctx_parseunc(struct smb_ctx *ctx, const char *unc, */ if (strchr(tmp, '%')) (void) unpercent(tmp); - smb_ctx_setfullserver(ctx, tmp); + error = smb_ctx_setfullserver(ctx, tmp); if (error) goto out; @@ -771,7 +779,7 @@ smb_ctx_setpassword(struct smb_ctx *ctx, const char *passwd, int from_cmd) memset(ctx->ct_password, 0, sizeof (ctx->ct_password)); if (strncmp(passwd, "$$1", 3) == 0) - smb_simpledecrypt(ctx->ct_password, passwd); + (void) smb_simpledecrypt(ctx->ct_password, passwd); else strlcpy(ctx->ct_password, passwd, sizeof (ctx->ct_password)); @@ -1387,14 +1395,15 @@ smb_ctx_readrcsection(struct smb_ctx *ctx, const char *sname, int level) if (p) { /* * "signing" was set in this section; override - * the current signing settings. + * the current signing settings. Note: + * setsigning flags are: enable, require */ if (strcmp(p, "disabled") == 0) { - smb_ctx_setsigning(ctx, FALSE, FALSE); + (void) smb_ctx_setsigning(ctx, FALSE, FALSE); } else if (strcmp(p, "enabled") == 0) { - smb_ctx_setsigning(ctx, TRUE, FALSE); + (void) smb_ctx_setsigning(ctx, TRUE, FALSE); } else if (strcmp(p, "required") == 0) { - smb_ctx_setsigning(ctx, TRUE, TRUE); + (void) smb_ctx_setsigning(ctx, TRUE, TRUE); } else { /* * Unknown "signing" value. diff --git a/usr/src/lib/libsmbfs/smb/file.c b/usr/src/lib/libsmbfs/smb/file.c index 74630fdd91..3c8184e8a1 100644 --- a/usr/src/lib/libsmbfs/smb/file.c +++ b/usr/src/lib/libsmbfs/smb/file.c @@ -114,7 +114,7 @@ smb_fh_ntcreate( mb_put_uint16le(mbp, 0xff); /* secondary command */ mb_put_uint16le(mbp, 0); /* offset to next command (none) */ mb_put_uint8(mbp, 0); /* MBZ (pad?) */ - mb_fit(mbp, 2, &pathsizep); /* path size - fill in below */ + (void) mb_fit(mbp, 2, &pathsizep); /* path size - fill in below */ mb_put_uint32le(mbp, flags); /* create flags (oplock) */ mb_put_uint32le(mbp, 0); /* FID - basis for path if not root */ mb_put_uint32le(mbp, req_acc); @@ -138,7 +138,7 @@ smb_fh_ntcreate( mb_put_uint8(mbp, 0); } pathstart = mbp->mb_count; - mb_put_dstring(mbp, path, uc); + mb_put_string(mbp, path, uc); smb_rq_bend(rqp); /* Now go back and fill in pathsizep */ @@ -155,30 +155,30 @@ smb_fh_ntcreate( * spec says 26 for word count, but 34 words are defined * and observed from win2000 */ - error = mb_get_uint8(mbp, &wc); + error = md_get_uint8(mbp, &wc); if (error || wc < 26) { smb_error(dgettext(TEXT_DOMAIN, "%s: open failed, bad word count"), 0, path); error = EBADRPC; goto out; } - mb_get_uint8(mbp, NULL); /* secondary cmd */ - mb_get_uint8(mbp, NULL); /* mbz */ - mb_get_uint16le(mbp, NULL); /* andxoffset */ - mb_get_uint8(mbp, NULL); /* oplock lvl granted */ - mb_get_uint16le(mbp, &fh); /* FID */ - mb_get_uint32le(mbp, action_taken); + md_get_uint8(mbp, NULL); /* secondary cmd */ + md_get_uint8(mbp, NULL); /* mbz */ + md_get_uint16le(mbp, NULL); /* andxoffset */ + md_get_uint8(mbp, NULL); /* oplock lvl granted */ + md_get_uint16le(mbp, &fh); /* FID */ + md_get_uint32le(mbp, action_taken); #if 0 /* skip decoding the rest */ - mb_get_uint64le(mbp, NULL); /* creation time */ - mb_get_uint64le(mbp, NULL); /* access time */ - mb_get_uint64le(mbp, NULL); /* write time */ - mb_get_uint64le(mbp, NULL); /* change time */ - mb_get_uint32le(mbp, NULL); /* attributes */ - mb_get_uint64le(mbp, NULL); /* allocation size */ - mb_get_uint64le(mbp, NULL); /* EOF */ - mb_get_uint16le(mbp, NULL); /* file type */ - mb_get_uint16le(mbp, NULL); /* device state */ - mb_get_uint8(mbp, NULL); /* directory (boolean) */ + md_get_uint64le(mbp, NULL); /* creation time */ + md_get_uint64le(mbp, NULL); /* access time */ + md_get_uint64le(mbp, NULL); /* write time */ + md_get_uint64le(mbp, NULL); /* change time */ + md_get_uint32le(mbp, NULL); /* attributes */ + md_get_uint64le(mbp, NULL); /* allocation size */ + md_get_uint64le(mbp, NULL); /* EOF */ + md_get_uint16le(mbp, NULL); /* file type */ + md_get_uint16le(mbp, NULL); /* device state */ + md_get_uint8(mbp, NULL); /* directory (boolean) */ #endif /* success! */ diff --git a/usr/src/lib/libsmbfs/smb/iod_cl.c b/usr/src/lib/libsmbfs/smb/iod_cl.c index 074b2ad848..7449d68ed5 100644 --- a/usr/src/lib/libsmbfs/smb/iod_cl.c +++ b/usr/src/lib/libsmbfs/smb/iod_cl.c @@ -151,7 +151,7 @@ smb_iod_start(smb_ctx_t *ctx) char *argv[2]; argv[0] = "smbiod"; argv[1] = NULL; - execv(smbiod_path, argv); + (void) execv(smbiod_path, argv); _exit(1); } @@ -160,7 +160,7 @@ smb_iod_start(smb_ctx_t *ctx) */ tmo = iod_start_timeout; while (--tmo >= 0) { - sleep(1); + (void) sleep(1); err = smb_iod_open_door(&fd); if (err == 0) goto OK; diff --git a/usr/src/lib/libsmbfs/smb/keychain.c b/usr/src/lib/libsmbfs/smb/keychain.c index da19fd4d0b..c5cf319c21 100644 --- a/usr/src/lib/libsmbfs/smb/keychain.c +++ b/usr/src/lib/libsmbfs/smb/keychain.c @@ -290,8 +290,11 @@ smbfs_default_dom_usr(const char *home, const char *server, if (err) return (err); - if (server) - smb_ctx_setfullserver(ctx, server); + if (server) { + err = smb_ctx_setfullserver(ctx, server); + if (err != 0) + goto out; + } if (home && *home) { if (ctx->ct_home) diff --git a/usr/src/lib/libsmbfs/smb/krb5ssp.c b/usr/src/lib/libsmbfs/smb/krb5ssp.c index fbbd08398b..d473c07c79 100644 --- a/usr/src/lib/libsmbfs/smb/krb5ssp.c +++ b/usr/src/lib/libsmbfs/smb/krb5ssp.c @@ -236,9 +236,9 @@ krb5ssp_put_request(struct ssp_ctx *sp, struct mbdata *out_mb) if ((err = krb5ssp_tkt2gtok(tkt, tktlen, >ok, >oklen)) != 0) goto out; - if ((err = mb_init(out_mb, gtoklen)) != 0) + if ((err = mb_init_sz(out_mb, gtoklen)) != 0) goto out; - if ((err = mb_put_mem(out_mb, gtok, gtoklen)) != 0) + if ((err = mb_put_mem(out_mb, gtok, gtoklen, MB_MSYSTEM)) != 0) goto out; if (ctx->ct_vcflags & SMBV_WILL_SIGN) diff --git a/usr/src/lib/libsmbfs/smb/lgrep.awk b/usr/src/lib/libsmbfs/smb/lgrep.awk new file mode 100644 index 0000000000..8f36708df8 --- /dev/null +++ b/usr/src/lib/libsmbfs/smb/lgrep.awk @@ -0,0 +1,54 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# This is a "lint tail" that removes all the +# uninteresting lines from our lint output. +# It's nawk because sed doesn't do (a|b). +# Also comments are easier here. + +# The mb_put/md_get functions are intentionally used both +# with and without return value checks. Not a concern. +/: mb_put_.* .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } +/: md_get_.* .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } + +# The rc_get* functions clear the out arg even on failure, +# so most callers don't need to check the return value. +/: rc_get[a-z]* .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } + +# These have uninteresting return values, usually ignored. +/: (n|sm)b_ctx_readrcsection .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } +/: nls_str_(lower|upper) .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } +/: rc_(close|freesect) .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } + +# Other functions for which we often ignore return values. +/: [a-z]*close .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } +/: [a-z]*flush .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } +/: [a-z]*printf .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } +/: mem(cpy|move|set) .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } +/: mutex_.* .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } +/: str[ln]?(cat|cpy) .E_FUNC_RET_[A-Z]*_IGNOR/ { next; } + +{ print; } diff --git a/usr/src/lib/libsmbfs/smb/mbuf.c b/usr/src/lib/libsmbfs/smb/mbuf.c index 9380ec12e9..86710f3f94 100644 --- a/usr/src/lib/libsmbfs/smb/mbuf.c +++ b/usr/src/lib/libsmbfs/smb/mbuf.c @@ -53,8 +53,20 @@ #include "private.h" #include "charsets.h" -static int -m_get(size_t len, struct mbuf **mpp) +/* + * Note: Leaving a little space (8 bytes) between the + * mbuf header and the start of the data so we can + * prepend a NetBIOS header in that space. + */ +#define M_ALIGNFACTOR (sizeof (long)) +#define M_ALIGN(len) (((len) + M_ALIGNFACTOR - 1) & ~(M_ALIGNFACTOR - 1)) +#define M_BASESIZE (sizeof (struct mbuf) + 8) +#define M_MINSIZE (1024 - M_BASESIZE) +#define M_TOP(m) ((char *)(m) + M_BASESIZE) +#define M_TRAILINGSPACE(m) ((m)->m_maxlen - (m)->m_len) + +int +m_get(int len, struct mbuf **mpp) { struct mbuf *m; @@ -132,37 +144,42 @@ m_lineup(struct mbuf *m0, struct mbuf **mpp) } int -mb_init(struct mbdata *mbp, size_t size) +mb_init(struct mbdata *mbp) +{ + return (mb_init_sz(mbp, M_MINSIZE)); +} + +int +mb_init_sz(struct mbdata *mbp, int size) { struct mbuf *m; int error; if ((error = m_get(size, &m)) != 0) return (error); - return (mb_initm(mbp, m)); + mb_initm(mbp, m); + return (0); } -int +void mb_initm(struct mbdata *mbp, struct mbuf *m) { bzero(mbp, sizeof (*mbp)); mbp->mb_top = mbp->mb_cur = m; mbp->mb_pos = mtod(m, char *); - return (0); } -int +void mb_done(struct mbdata *mbp) { if (mbp->mb_top) { m_freem(mbp->mb_top); mbp->mb_top = NULL; } - return (0); } int -m_getm(struct mbuf *top, size_t len, struct mbuf **mpp) +m_getm(struct mbuf *top, int len, struct mbuf **mpp) { struct mbuf *m, *mp; int error, ts; @@ -190,13 +207,24 @@ out: * Routines to put data in a buffer */ +void * +mb_reserve(mbchain_t *mbp, int size) +{ + char *p; + + if (mb_fit(mbp, size, &p) != 0) + return (NULL); + + return (p); +} + /* * Check if object of size 'size' fit to the current position and * allocate new mbuf if not. Advance pointers and increase length of mbuf(s). * Return pointer to the object placeholder or NULL if any error occured. */ int -mb_fit(struct mbdata *mbp, size_t size, char **pp) +mb_fit(mbchain_t *mbp, int size, char **pp) { struct mbuf *m, *mn; int error; @@ -217,56 +245,57 @@ mb_fit(struct mbdata *mbp, size_t size, char **pp) } int -mb_put_uint8(struct mbdata *mbp, uint8_t x) +mb_put_uint8(mbchain_t *mbp, uint8_t x) { uint8_t y = x; - return (mb_put_mem(mbp, &y, sizeof (y))); + return (mb_put_mem(mbp, &y, sizeof (y), MB_MINLINE)); } int -mb_put_uint16be(struct mbdata *mbp, uint16_t x) +mb_put_uint16be(mbchain_t *mbp, uint16_t x) { uint16_t y = htobes(x); - return (mb_put_mem(mbp, &y, sizeof (y))); + return (mb_put_mem(mbp, &y, sizeof (y), MB_MINLINE)); } int -mb_put_uint16le(struct mbdata *mbp, uint16_t x) +mb_put_uint16le(mbchain_t *mbp, uint16_t x) { uint16_t y = htoles(x); - return (mb_put_mem(mbp, &y, sizeof (y))); + return (mb_put_mem(mbp, &y, sizeof (y), MB_MINLINE)); } int -mb_put_uint32be(struct mbdata *mbp, uint32_t x) +mb_put_uint32be(mbchain_t *mbp, uint32_t x) { uint32_t y = htobel(x); - return (mb_put_mem(mbp, &y, sizeof (y))); + return (mb_put_mem(mbp, &y, sizeof (y), MB_MINLINE)); } int -mb_put_uint32le(struct mbdata *mbp, uint32_t x) +mb_put_uint32le(mbchain_t *mbp, uint32_t x) { uint32_t y = htolel(x); - return (mb_put_mem(mbp, &y, sizeof (y))); + return (mb_put_mem(mbp, &y, sizeof (y), MB_MINLINE)); } int -mb_put_uint64be(struct mbdata *mbp, uint64_t x) +mb_put_uint64be(mbchain_t *mbp, uint64_t x) { uint64_t y = htobeq(x); - return (mb_put_mem(mbp, &y, sizeof (y))); + return (mb_put_mem(mbp, &y, sizeof (y), MB_MINLINE)); } int -mb_put_uint64le(struct mbdata *mbp, uint64_t x) +mb_put_uint64le(mbchain_t *mbp, uint64_t x) { uint64_t y = htoleq(x); - return (mb_put_mem(mbp, &y, sizeof (y))); + return (mb_put_mem(mbp, &y, sizeof (y), MB_MINLINE)); } +/* ARGSUSED */ int -mb_put_mem(struct mbdata *mbp, const void *vmem, size_t size) +mb_put_mem(mbchain_t *mbp, const void *vmem, int size, int type) { struct mbuf *m; const char *src; @@ -311,14 +340,14 @@ mb_put_mem(struct mbdata *mbp, const void *vmem, size_t size) * This always consumes the passed mbuf. */ int -mb_put_mbuf(struct mbdata *mbp, struct mbuf *m) +mb_put_mbuf(mbchain_t *mbp, struct mbuf *m) { struct mbuf *cm = mbp->mb_cur; int ts = M_TRAILINGSPACE(cm); if (m->m_next == NULL && m->m_len <= ts) { /* just copy */ - mb_put_mem(mbp, m->m_data, m->m_len); + mb_put_mem(mbp, m->m_data, m->m_len, MB_MSYSTEM); m_freem(m); return (0); } @@ -340,7 +369,7 @@ mb_put_mbuf(struct mbdata *mbp, struct mbuf *m) * null terminated, and aligned if necessary. */ int -mb_put_dstring(struct mbdata *mbp, const char *s, int uc) +mb_put_string(mbchain_t *mbp, const char *s, int uc) { int err; @@ -361,7 +390,7 @@ mb_put_dstring(struct mbdata *mbp, const char *s, int uc) * Put an ASCII string (really OEM), given a UTF-8 string. */ int -mb_put_astring(struct mbdata *mbp, const char *s) +mb_put_astring(mbchain_t *mbp, const char *s) { char *abuf; int err, len; @@ -370,7 +399,7 @@ mb_put_astring(struct mbdata *mbp, const char *s) if (abuf == NULL) return (ENOMEM); len = strlen(abuf) + 1; - err = mb_put_mem(mbp, abuf, len); + err = mb_put_mem(mbp, abuf, len, MB_MSYSTEM); free(abuf); return (err); } @@ -379,7 +408,7 @@ mb_put_astring(struct mbdata *mbp, const char *s) * Put UCS-2LE, given a UTF-8 string. */ int -mb_put_ustring(struct mbdata *mbp, const char *s) +mb_put_ustring(mbchain_t *mbp, const char *s) { uint16_t *ubuf; int err, len; @@ -387,8 +416,8 @@ mb_put_ustring(struct mbdata *mbp, const char *s) ubuf = convert_utf8_to_leunicode(s); if (ubuf == NULL) return (ENOMEM); - len = unicode_strlen(ubuf) + 1; - err = mb_put_mem(mbp, ubuf, (len << 1)); + len = 2 * (unicode_strlen(ubuf) + 1); + err = mb_put_mem(mbp, ubuf, len, MB_MSYSTEM); free(ubuf); return (err); } @@ -399,24 +428,18 @@ mb_put_ustring(struct mbdata *mbp, const char *s) #define mb_left(m, p) (mtod(m, char *) + (m)->m_len - (p)) int -mb_get_uint8(struct mbdata *mbp, uint8_t *x) -{ - return (mb_get_mem(mbp, x, 1)); -} - -int -mb_get_uint16(struct mbdata *mbp, uint16_t *x) +md_get_uint8(mdchain_t *mbp, uint8_t *x) { - return (mb_get_mem(mbp, x, 2)); + return (md_get_mem(mbp, x, 1, MB_MINLINE)); } int -mb_get_uint16le(struct mbdata *mbp, uint16_t *x) +md_get_uint16le(mdchain_t *mbp, uint16_t *x) { uint16_t v; int err; - if ((err = mb_get_mem(mbp, &v, 2)) != 0) + if ((err = md_get_mem(mbp, &v, sizeof (v), MB_MINLINE)) != 0) return (err); if (x != NULL) *x = letohs(v); @@ -424,11 +447,11 @@ mb_get_uint16le(struct mbdata *mbp, uint16_t *x) } int -mb_get_uint16be(struct mbdata *mbp, uint16_t *x) { +md_get_uint16be(mdchain_t *mbp, uint16_t *x) { uint16_t v; int err; - if ((err = mb_get_mem(mbp, &v, 2)) != 0) + if ((err = md_get_mem(mbp, &v, sizeof (v), MB_MINLINE)) != 0) return (err); if (x != NULL) *x = betohs(v); @@ -436,18 +459,12 @@ mb_get_uint16be(struct mbdata *mbp, uint16_t *x) { } int -mb_get_uint32(struct mbdata *mbp, uint32_t *x) -{ - return (mb_get_mem(mbp, x, 4)); -} - -int -mb_get_uint32be(struct mbdata *mbp, uint32_t *x) +md_get_uint32be(mdchain_t *mbp, uint32_t *x) { uint32_t v; int err; - if ((err = mb_get_mem(mbp, &v, 4)) != 0) + if ((err = md_get_mem(mbp, &v, sizeof (v), MB_MINLINE)) != 0) return (err); if (x != NULL) *x = betohl(v); @@ -455,12 +472,12 @@ mb_get_uint32be(struct mbdata *mbp, uint32_t *x) } int -mb_get_uint32le(struct mbdata *mbp, uint32_t *x) +md_get_uint32le(mdchain_t *mbp, uint32_t *x) { uint32_t v; int err; - if ((err = mb_get_mem(mbp, &v, 4)) != 0) + if ((err = md_get_mem(mbp, &v, sizeof (v), MB_MINLINE)) != 0) return (err); if (x != NULL) *x = letohl(v); @@ -468,18 +485,12 @@ mb_get_uint32le(struct mbdata *mbp, uint32_t *x) } int -mb_get_uint64(struct mbdata *mbp, uint64_t *x) -{ - return (mb_get_mem(mbp, x, 8)); -} - -int -mb_get_uint64be(struct mbdata *mbp, uint64_t *x) +md_get_uint64be(mdchain_t *mbp, uint64_t *x) { uint64_t v; int err; - if ((err = mb_get_mem(mbp, &v, 8)) != 0) + if ((err = md_get_mem(mbp, &v, sizeof (v), MB_MINLINE)) != 0) return (err); if (x != NULL) *x = betohq(v); @@ -487,20 +498,21 @@ mb_get_uint64be(struct mbdata *mbp, uint64_t *x) } int -mb_get_uint64le(struct mbdata *mbp, uint64_t *x) +md_get_uint64le(mdchain_t *mbp, uint64_t *x) { uint64_t v; int err; - if ((err = mb_get_mem(mbp, &v, 8)) != 0) + if ((err = md_get_mem(mbp, &v, sizeof (v), MB_MINLINE)) != 0) return (err); if (x != NULL) *x = letohq(v); return (0); } +/* ARGSUSED */ int -mb_get_mem(struct mbdata *mbp, void *vmem, size_t size) +md_get_mem(mdchain_t *mbp, void *vmem, int size, int type) { struct mbuf *m = mbp->mb_cur; char *dst = vmem; @@ -539,7 +551,7 @@ mb_get_mem(struct mbdata *mbp, void *vmem, size_t size) * Nothing fancy here - just copy. */ int -mb_get_mbuf(struct mbdata *mbp, int size, struct mbuf **ret) +md_get_mbuf(mdchain_t *mbp, int size, mbuf_t **ret) { mbuf_t *m; int err; @@ -548,7 +560,7 @@ mb_get_mbuf(struct mbdata *mbp, int size, struct mbuf **ret) if (err) return (err); - err = mb_get_mem(mbp, m->m_data, size); + err = md_get_mem(mbp, m->m_data, size, MB_MSYSTEM); if (err) { m_freem(m); return (err); @@ -564,26 +576,27 @@ mb_get_mbuf(struct mbdata *mbp, int size, struct mbuf **ret) * either Unicode or OEM chars. */ int -mb_get_string(struct mbdata *mbp, char **str_pp, int uc) +md_get_string(mdchain_t *mbp, char **str_pp, int uc) { int err; if (uc) - err = mb_get_ustring(mbp, str_pp); + err = md_get_ustring(mbp, str_pp); else - err = mb_get_astring(mbp, str_pp); + err = md_get_astring(mbp, str_pp); return (err); } /* * Get an ASCII (really OEM) string from the mbuf chain * and convert it to UTF-8 - * Similar to mb_get_ustring below. + * + * Similar to md_get_ustring below. */ int -mb_get_astring(struct mbdata *real_mbp, char **str_pp) +md_get_astring(mdchain_t *real_mbp, char **str_pp) { - struct mbdata tmp_mb, *mbp; + mdchain_t tmp_mb, *mbp; char *tstr, *ostr; int err, i, slen; uint8_t ch; @@ -598,7 +611,7 @@ mb_get_astring(struct mbdata *real_mbp, char **str_pp) mbp = &tmp_mb; slen = 0; for (;;) { - err = mb_get_uint8(mbp, &ch); + err = md_get_uint8(mbp, &ch); if (err) break; if (ch == 0) @@ -615,11 +628,11 @@ mb_get_astring(struct mbdata *real_mbp, char **str_pp) return (ENOMEM); mbp = real_mbp; for (i = 0; i < slen; i++) { - mb_get_uint8(mbp, &ch); + md_get_uint8(mbp, &ch); tstr[i] = ch; } tstr[i] = 0; - mb_get_uint8(mbp, NULL); + md_get_uint8(mbp, NULL); /* * Convert OEM to UTF-8 @@ -637,12 +650,12 @@ mb_get_astring(struct mbdata *real_mbp, char **str_pp) * Get a UCS-2LE string from the mbuf chain, and * convert it to UTF-8. * - * Similar to mb_get_astring below. + * Similar to md_get_astring above. */ int -mb_get_ustring(struct mbdata *real_mbp, char **str_pp) +md_get_ustring(mdchain_t *real_mbp, char **str_pp) { - struct mbdata tmp_mb, *mbp; + mdchain_t tmp_mb, *mbp; uint16_t *tstr; char *ostr; int err, i, slen; @@ -652,7 +665,7 @@ mb_get_ustring(struct mbdata *real_mbp, char **str_pp) * First, align(2) on the real_mbp */ if (((uintptr_t)real_mbp->mb_pos) & 1) - mb_get_uint8(real_mbp, NULL); + md_get_uint8(real_mbp, NULL); /* * Next, figure out the string length. @@ -664,7 +677,7 @@ mb_get_ustring(struct mbdata *real_mbp, char **str_pp) mbp = &tmp_mb; slen = 0; for (;;) { - err = mb_get_uint16le(mbp, &ch); + err = md_get_uint16le(mbp, &ch); if (err) break; if (ch == 0) @@ -682,11 +695,11 @@ mb_get_ustring(struct mbdata *real_mbp, char **str_pp) return (ENOMEM); mbp = real_mbp; for (i = 0; i < slen; i++) { - mb_get_uint16le(mbp, &ch); + md_get_uint16le(mbp, &ch); tstr[i] = ch; } tstr[i] = 0; - mb_get_uint16le(mbp, NULL); + md_get_uint16le(mbp, NULL); /* * Convert UCS-2 (native!) to UTF-8 diff --git a/usr/src/lib/libsmbfs/smb/nb_name.c b/usr/src/lib/libsmbfs/smb/nb_name.c index 604d9142cd..812900aca9 100644 --- a/usr/src/lib/libsmbfs/smb/nb_name.c +++ b/usr/src/lib/libsmbfs/smb/nb_name.c @@ -206,7 +206,7 @@ nb_name_encode(struct mbdata *mbp, struct nb_name *nn) return (0); } - mb_fit(mbp, 1, &plen); + (void) mb_fit(mbp, 1, &plen); *plen = 0; /* will update below */ lblen = 0; for (p = nn->nn_scope; ; p++) { @@ -218,7 +218,7 @@ nb_name_encode(struct mbdata *mbp, struct nb_name *nn) } if (*p == '.') { *plen = lblen; - mb_fit(mbp, 1, &plen); + (void) mb_fit(mbp, 1, &plen); *plen = 0; lblen = 0; } else { diff --git a/usr/src/lib/libsmbfs/smb/nb_ssn.c b/usr/src/lib/libsmbfs/smb/nb_ssn.c index bd53ce6fce..44d5a48120 100644 --- a/usr/src/lib/libsmbfs/smb/nb_ssn.c +++ b/usr/src/lib/libsmbfs/smb/nb_ssn.c @@ -178,7 +178,7 @@ nb_ssn_recv(struct smb_ctx *ctx, struct mbdata *mb, /* * Get a message buffer, read the payload */ - if ((err = mb_init(mb, *mlen)) != 0) + if ((err = mb_init_sz(mb, *mlen)) != 0) return (err); buf = mb->mb_top->m_data; len = *mlen; @@ -274,7 +274,7 @@ nb_ssn_request(struct smb_ctx *ctx, char *srvname) bzero(&req, sizeof (req)); bzero(&res, sizeof (res)); - if ((err = mb_init(&req, M_MINSIZE)) != 0) + if ((err = mb_init(&req)) != 0) goto errout; ucwks = utf8_str_toupper(ctx->ct_locname); diff --git a/usr/src/lib/libsmbfs/smb/nbns_rq.c b/usr/src/lib/libsmbfs/smb/nbns_rq.c index d0e85209e7..7dc46f3983 100644 --- a/usr/src/lib/libsmbfs/smb/nbns_rq.c +++ b/usr/src/lib/libsmbfs/smb/nbns_rq.c @@ -373,7 +373,7 @@ nbns_rq_create(int opcode, struct nb_ctx *ctx, struct nbns_rq **rqpp) if (rqp == NULL) return (ENOMEM); bzero(rqp, sizeof (*rqp)); - error = mb_init(&rqp->nr_rq, NBDG_MAXSIZE); + error = mb_init_sz(&rqp->nr_rq, NBDG_MAXSIZE); if (error) { free(rqp); return (error); @@ -416,15 +416,15 @@ nbns_rq_getrr(struct nbns_rq *rqp, struct nbns_rr *rrp) if (len < 1) return (NBERROR(NBERR_INVALIDRESPONSE)); rrp->rr_name = cp; - error = mb_get_mem(mbp, NULL, len); + error = md_get_mem(mbp, NULL, len, MB_MSYSTEM); if (error) return (error); - mb_get_uint16be(mbp, &rrp->rr_type); - mb_get_uint16be(mbp, &rrp->rr_class); - mb_get_uint32be(mbp, &rrp->rr_ttl); - mb_get_uint16be(mbp, &rrp->rr_rdlength); + md_get_uint16be(mbp, &rrp->rr_type); + md_get_uint16be(mbp, &rrp->rr_class); + md_get_uint32be(mbp, &rrp->rr_ttl); + md_get_uint16be(mbp, &rrp->rr_rdlength); rrp->rr_data = (uchar_t *)mbp->mb_pos; - error = mb_get_mem(mbp, NULL, rrp->rr_rdlength); + error = md_get_mem(mbp, NULL, rrp->rr_rdlength, MB_MSYSTEM); return (error); } @@ -436,11 +436,7 @@ nbns_rq_prepare(struct nbns_rq *rqp) uint16_t ofr; /* opcode, flags, rcode */ int error; - /* - * Replacing with one argument. - * error = mb_init(&rqp->nr_rp, NBDG_MAXSIZE); - */ - error = mb_init(&rqp->nr_rp, NBDG_MAXSIZE); + error = mb_init_sz(&rqp->nr_rp, NBDG_MAXSIZE); if (error) return (error); @@ -455,15 +451,19 @@ nbns_rq_prepare(struct nbns_rq *rqp) mb_put_uint16be(mbp, rqp->nr_qdcount); mb_put_uint16be(mbp, rqp->nr_ancount); mb_put_uint16be(mbp, rqp->nr_nscount); - mb_put_uint16be(mbp, rqp->nr_arcount); + error = mb_put_uint16be(mbp, rqp->nr_arcount); if (rqp->nr_qdcount) { if (rqp->nr_qdcount > 1) return (EINVAL); - nb_name_encode(mbp, rqp->nr_qdname); + (void) nb_name_encode(mbp, rqp->nr_qdname); mb_put_uint16be(mbp, rqp->nr_qdtype); - mb_put_uint16be(mbp, rqp->nr_qdclass); + error = mb_put_uint16be(mbp, rqp->nr_qdclass); } - m_lineup(mbp->mb_top, &mbp->mb_top); + if (error) + return (error); + error = m_lineup(mbp->mb_top, &mbp->mb_top); + if (error) + return (error); if (ctx->nb_timo == 0) ctx->nb_timo = 1; /* by default 1 second */ return (0); @@ -652,7 +652,7 @@ do_recv: mbp = &rqp->nr_rp; if (mbp->mb_count < 12) return (NBERROR(NBERR_INVALIDRESPONSE)); - mb_get_uint16be(mbp, &rpid); + md_get_uint16be(mbp, &rpid); if (rpid != rqp->nr_trnid) return (NBERROR(NBERR_INVALIDRESPONSE)); break; @@ -660,14 +660,14 @@ do_recv: if (tries == maxretry) return (NBERROR(NBERR_HOSTNOTFOUND)); - mb_get_uint16be(mbp, &ofr); + md_get_uint16be(mbp, &ofr); rqp->nr_rpnmflags = (ofr >> 4) & 0x7F; rqp->nr_rprcode = ofr & 0xf; if (rqp->nr_rprcode) return (NBERROR(rqp->nr_rprcode)); - mb_get_uint16be(mbp, &rpid); /* QDCOUNT */ - mb_get_uint16be(mbp, &rqp->nr_rpancount); - mb_get_uint16be(mbp, &rqp->nr_rpnscount); - mb_get_uint16be(mbp, &rqp->nr_rparcount); + md_get_uint16be(mbp, &rpid); /* QDCOUNT */ + md_get_uint16be(mbp, &rqp->nr_rpancount); + md_get_uint16be(mbp, &rqp->nr_rpnscount); + md_get_uint16be(mbp, &rqp->nr_rparcount); return (0); } diff --git a/usr/src/lib/libsmbfs/smb/negprot.c b/usr/src/lib/libsmbfs/smb/negprot.c index 6c1649f1bb..cd6e2866df 100644 --- a/usr/src/lib/libsmbfs/smb/negprot.c +++ b/usr/src/lib/libsmbfs/smb/negprot.c @@ -104,7 +104,7 @@ smb_negprot(struct smb_ctx *ctx, struct mbdata *oblob) struct mbdata *mbp; struct smb_dialect *dp; int err, len; - uint8_t wc, stime[8], eklen; + uint8_t wc, eklen; uint16_t dindex, bc; int will_sign = 0; @@ -188,8 +188,8 @@ smb_negprot(struct smb_ctx *ctx, struct mbdata *oblob) * section 2.2.3 */ mbp = &rqp->rq_rp; - (void) mb_get_uint8(mbp, &wc); - err = mb_get_uint16le(mbp, &dindex); + (void) md_get_uint8(mbp, &wc); + err = md_get_uint16le(mbp, &dindex); if (err || dindex > SMB_DIALECT_MAX) { DPRINT("err %d dindex %d", err, (int)dindex); goto errout; @@ -206,17 +206,17 @@ smb_negprot(struct smb_ctx *ctx, struct mbdata *oblob) DPRINT("bad wc %d", (int)wc); goto errout; } - mb_get_uint8(mbp, &sv->sv_sm); /* SecurityMode */ - mb_get_uint16le(mbp, &sv->sv_maxmux); /* MaxMpxCount */ - mb_get_uint16le(mbp, &sv->sv_maxvcs); /* MaxCountVCs */ - mb_get_uint32le(mbp, &sv->sv_maxtx); /* MaxBufferSize */ - mb_get_uint32le(mbp, &sv->sv_maxraw); /* MaxRawSize */ - mb_get_uint32le(mbp, &sv->sv_skey); /* SessionKey */ - mb_get_uint32le(mbp, &sv->sv_caps); /* Capabilities */ - mb_get_mem(mbp, (char *)stime, 8); /* SystemTime(s) */ - mb_get_uint16le(mbp, (uint16_t *)&sv->sv_tz); - mb_get_uint8(mbp, &eklen); /* EncryptionKeyLength */ - err = mb_get_uint16le(mbp, &bc); /* ByteCount */ + md_get_uint8(mbp, &sv->sv_sm); /* SecurityMode */ + md_get_uint16le(mbp, &sv->sv_maxmux); /* MaxMpxCount */ + md_get_uint16le(mbp, &sv->sv_maxvcs); /* MaxCountVCs */ + md_get_uint32le(mbp, &sv->sv_maxtx); /* MaxBufferSize */ + md_get_uint32le(mbp, &sv->sv_maxraw); /* MaxRawSize */ + md_get_uint32le(mbp, &sv->sv_skey); /* SessionKey */ + md_get_uint32le(mbp, &sv->sv_caps); /* Capabilities */ + md_get_mem(mbp, NULL, 8, MB_MSYSTEM); /* SystemTime(s) */ + md_get_uint16le(mbp, (uint16_t *)&sv->sv_tz); + md_get_uint8(mbp, &eklen); /* EncryptionKeyLength */ + err = md_get_uint16le(mbp, &bc); /* ByteCount */ if (err) goto errout; @@ -325,7 +325,7 @@ smb_negprot(struct smb_ctx *ctx, struct mbdata *oblob) /* * Skip the server GUID. */ - err = mb_get_mem(mbp, NULL, SMB_GUIDLEN); + err = md_get_mem(mbp, NULL, SMB_GUIDLEN, MB_MSYSTEM); if (err) goto errout; /* @@ -339,7 +339,7 @@ smb_negprot(struct smb_ctx *ctx, struct mbdata *oblob) /* * Get the (optional) SPNEGO "hint". */ - err = mb_get_mbuf(mbp, len, &m); + err = md_get_mbuf(mbp, len, &m); if (err) goto errout; mb_initm(oblob, m); @@ -358,7 +358,8 @@ smb_negprot(struct smb_ctx *ctx, struct mbdata *oblob) err = EBADRPC; goto errout; } - err = mb_get_mem(mbp, (char *)ctx->ct_ntlm_chal, NTLM_CHAL_SZ); + err = md_get_mem(mbp, ctx->ct_ntlm_chal, + NTLM_CHAL_SZ, MB_MSYSTEM); /* * Server domain follows (ignored) * Note: NOT aligned(2) - unusual! diff --git a/usr/src/lib/libsmbfs/smb/netshareenum.c b/usr/src/lib/libsmbfs/smb/netshareenum.c index 2ee1fd7792..bd2c24caec 100644 --- a/usr/src/lib/libsmbfs/smb/netshareenum.c +++ b/usr/src/lib/libsmbfs/smb/netshareenum.c @@ -280,9 +280,9 @@ smb_rap_NetShareEnum(struct smb_ctx *ctx, int sLevel, void *pbBuffer, error = smb_rap_create(0, "WrLeh", "B13BWz", &rap); if (error) return (error); - smb_rap_setNparam(rap, sLevel); /* W - sLevel */ - smb_rap_setPparam(rap, pbBuffer); /* r - pbBuffer */ - smb_rap_setNparam(rap, *cbBuffer); /* L - cbBuffer */ + (void) smb_rap_setNparam(rap, sLevel); /* W - sLevel */ + (void) smb_rap_setPparam(rap, pbBuffer); /* r - pbBuffer */ + (void) smb_rap_setNparam(rap, *cbBuffer); /* L - cbBuffer */ error = smb_rap_request(rap, ctx); if (error == 0) { *pcEntriesRead = rap->r_entries; diff --git a/usr/src/lib/libsmbfs/smb/ntlm.c b/usr/src/lib/libsmbfs/smb/ntlm.c index 8119e62b65..ffd9ff3d41 100644 --- a/usr/src/lib/libsmbfs/smb/ntlm.c +++ b/usr/src/lib/libsmbfs/smb/ntlm.c @@ -187,11 +187,11 @@ ntlm_put_v1_responses(struct smb_ctx *ctx, int err; /* Get mbuf chain for the LM response. */ - if ((err = mb_init(lm_mbp, NTLM_V1_RESP_SZ)) != 0) + if ((err = mb_init_sz(lm_mbp, NTLM_V1_RESP_SZ)) != 0) return (err); /* Get mbuf chain for the NT response. */ - if ((err = mb_init(nt_mbp, NTLM_V1_RESP_SZ)) != 0) + if ((err = mb_init_sz(nt_mbp, NTLM_V1_RESP_SZ)) != 0) return (err); /* @@ -199,7 +199,9 @@ ntlm_put_v1_responses(struct smb_ctx *ctx, * from the challenge and the ASCII * password (if authflags allow). */ - mb_fit(lm_mbp, NTLM_V1_RESP_SZ, (char **)&lmresp); + err = mb_fit(lm_mbp, NTLM_V1_RESP_SZ, (char **)&lmresp); + if (err) + return (err); bzero(lmresp, NTLM_V1_RESP_SZ); if (ctx->ct_authflags & SMB_AT_LM1) { /* They asked to send the LM hash too. */ @@ -213,7 +215,9 @@ ntlm_put_v1_responses(struct smb_ctx *ctx, * Compute the NTLM response, derived from * the challenge and the NT hash. */ - mb_fit(nt_mbp, NTLM_V1_RESP_SZ, (char **)&ntresp); + err = mb_fit(nt_mbp, NTLM_V1_RESP_SZ, (char **)&ntresp); + if (err) + return (err); bzero(ntresp, NTLM_V1_RESP_SZ); err = ntlm_v1_response(ntresp, ctx->ct_nthash, ctx->ct_ntlm_chal, NTLM_CHAL_SZ); @@ -408,9 +412,9 @@ ntlm_put_v2_responses(struct smb_ctx *ctx, struct mbdata *ti_mbp, uchar_t v2hash[NTLM_HASH_SZ]; struct mbuf *tim = ti_mbp->mb_top; - if ((err = mb_init(lm_mbp, M_MINSIZE)) != 0) + if ((err = mb_init(lm_mbp)) != 0) return (err); - if ((err = mb_init(nt_mbp, M_MINSIZE)) != 0) + if ((err = mb_init(nt_mbp)) != 0) return (err); /* @@ -443,13 +447,13 @@ ntlm_put_v2_responses(struct smb_ctx *ctx, struct mbdata *ti_mbp, * 2: Client nonce */ lmresp = (uchar_t *)lm_mbp->mb_pos; - mb_put_mem(lm_mbp, NULL, NTLM_HASH_SZ); + mb_put_mem(lm_mbp, NULL, NTLM_HASH_SZ, MB_MSYSTEM); err = ntlm_v2_resp_hash(lmresp, v2hash, ctx->ct_ntlm_chal, ctx->ct_clnonce, NTLM_CHAL_SZ); if (err) goto out; - mb_put_mem(lm_mbp, ctx->ct_clnonce, NTLM_CHAL_SZ); + mb_put_mem(lm_mbp, ctx->ct_clnonce, NTLM_CHAL_SZ, MB_MSYSTEM); /* * Compute the NTLMv2 response, derived @@ -461,13 +465,13 @@ ntlm_put_v2_responses(struct smb_ctx *ctx, struct mbdata *ti_mbp, * 2: "target info." blob */ ntresp = (uchar_t *)nt_mbp->mb_pos; - mb_put_mem(nt_mbp, NULL, NTLM_HASH_SZ); + mb_put_mem(nt_mbp, NULL, NTLM_HASH_SZ, MB_MSYSTEM); err = ntlm_v2_resp_hash(ntresp, v2hash, ctx->ct_ntlm_chal, (uchar_t *)tim->m_data, tim->m_len); if (err) goto out; - mb_put_mem(nt_mbp, tim->m_data, tim->m_len); + mb_put_mem(nt_mbp, tim->m_data, tim->m_len, MB_MSYSTEM); /* * Compute the session key @@ -506,7 +510,7 @@ smb_put_blob_name(struct mbdata *mbp, char *name, int type) mb_put_uint16le(mbp, type); mb_put_uint16le(mbp, nlen); - mb_put_mem(mbp, (char *)ucs, nlen); + mb_put_mem(mbp, (char *)ucs, nlen, MB_MSYSTEM); if (ucs) free(ucs); @@ -528,7 +532,7 @@ ntlm_build_target_info(struct smb_ctx *ctx, struct mbuf *names, int err; /* Get mbuf chain for the "target info". */ - if ((err = mb_init(mbp, M_MINSIZE)) != 0) + if ((err = mb_init(mbp)) != 0) return (err); /* @@ -556,7 +560,7 @@ ntlm_build_target_info(struct smb_ctx *ctx, struct mbuf *names, mb_put_uint32le(mbp, 0x101); /* Blob signature */ mb_put_uint32le(mbp, 0); /* reserved */ mb_put_uint64le(mbp, nt_time); /* NT time stamp */ - mb_put_mem(mbp, ctx->ct_clnonce, NTLM_CHAL_SZ); + mb_put_mem(mbp, ctx->ct_clnonce, NTLM_CHAL_SZ, MB_MSYSTEM); mb_put_uint32le(mbp, 0); /* unknown */ /* @@ -564,7 +568,7 @@ ntlm_build_target_info(struct smb_ctx *ctx, struct mbuf *names, * NTLMSSP Type 2 message or composed here. */ if (names) { - err = mb_put_mem(mbp, names->m_data, names->m_len); + err = mb_put_mem(mbp, names->m_data, names->m_len, MB_MSYSTEM); } else { /* Get upper-case names. */ ucdom = utf8_str_toupper(ctx->ct_domain); diff --git a/usr/src/lib/libsmbfs/smb/ntlmssp.c b/usr/src/lib/libsmbfs/smb/ntlmssp.c index 3428fbca36..535777b187 100644 --- a/usr/src/lib/libsmbfs/smb/ntlmssp.c +++ b/usr/src/lib/libsmbfs/smb/ntlmssp.c @@ -87,13 +87,13 @@ static const char ntlmssp_id[ID_SZ] = "NTLMSSP"; * Get a "security buffer" (header part) */ static int -mb_get_sb_hdr(struct mbdata *mbp, struct sec_buf *sb) +md_get_sb_hdr(struct mbdata *mbp, struct sec_buf *sb) { int err; - (void) mb_get_uint16le(mbp, &sb->sb_length); - (void) mb_get_uint16le(mbp, &sb->sb_maxlen); - err = mb_get_uint32le(mbp, &sb->sb_offset); + (void) md_get_uint16le(mbp, &sb->sb_length); + (void) md_get_uint16le(mbp, &sb->sb_maxlen); + err = md_get_uint32le(mbp, &sb->sb_offset); return (err); } @@ -103,7 +103,7 @@ mb_get_sb_hdr(struct mbdata *mbp, struct sec_buf *sb) * the data is delivered as an mbuf. */ static int -mb_get_sb_data(struct mbdata *mbp, struct sec_buf *sb, struct mbuf **mp) +md_get_sb_data(struct mbdata *mbp, struct sec_buf *sb, struct mbuf **mp) { struct mbdata tmp_mb; int err; @@ -115,12 +115,12 @@ mb_get_sb_data(struct mbdata *mbp, struct sec_buf *sb, struct mbuf **mp) mb_initm(&tmp_mb, mbp->mb_top); /* Skip data up to the offset. */ - err = mb_get_mem(&tmp_mb, NULL, sb->sb_offset); + err = md_get_mem(&tmp_mb, NULL, sb->sb_offset, MB_MSYSTEM); if (err) return (err); /* Get the data (as an mbuf). */ - err = mb_get_mbuf(&tmp_mb, sb->sb_maxlen, mp); + err = md_get_mbuf(&tmp_mb, sb->sb_maxlen, mp); return (err); } @@ -174,10 +174,10 @@ mb_put_sb_string(struct mbdata *mbp, struct sec_buf *sb, * then chop off the null terminator * before appending to caller's mbp. */ - err = mb_init(&tmp_mb, M_MINSIZE); + err = mb_init(&tmp_mb); if (err) return (err); - err = mb_put_dstring(&tmp_mb, s, unicode); + err = mb_put_string(&tmp_mb, s, unicode); if (err) return (err); @@ -218,7 +218,7 @@ ntlmssp_put_type1(struct ssp_ctx *sp, struct mbdata *out_mb) char *ucdom = NULL; char *ucwks = NULL; - if ((err = mb_init(&mb2, M_MINSIZE)) != 0) + if ((err = mb_init(&mb2)) != 0) return (err); mb2.mb_count = sizeof (hdr); @@ -269,7 +269,7 @@ ntlmssp_put_type1(struct ssp_ctx *sp, struct mbdata *out_mb) * Marshal the header (in LE order) * then concatenate the 2nd part. */ - (void) mb_put_mem(out_mb, &hdr.h_id, ID_SZ); + (void) mb_put_mem(out_mb, &hdr.h_id, ID_SZ, MB_MSYSTEM); (void) mb_put_uint32le(out_mb, hdr.h_type); (void) mb_put_uint32le(out_mb, hdr.h_flags); (void) mb_put_sb_hdr(out_mb, &hdr.h_cldom); @@ -322,15 +322,15 @@ ntlmssp_get_type2(struct ssp_ctx *sp, struct mbdata *in_mb) /* Parse the fixed size header stuff. */ bzero(&hdr, sizeof (hdr)); - (void) mb_get_mem(in_mb, &hdr.h_id, ID_SZ); - (void) mb_get_uint32le(in_mb, &hdr.h_type); + (void) md_get_mem(in_mb, &hdr.h_id, ID_SZ, MB_MSYSTEM); + (void) md_get_uint32le(in_mb, &hdr.h_type); if (hdr.h_type != 2) { err = EPROTO; goto out; } - (void) mb_get_sb_hdr(in_mb, &hdr.h_target_name); - (void) mb_get_uint32le(in_mb, &hdr.h_flags); - (void) mb_get_mem(in_mb, &hdr.h_challenge, NTLM_CHAL_SZ); + (void) md_get_sb_hdr(in_mb, &hdr.h_target_name); + (void) md_get_uint32le(in_mb, &hdr.h_flags); + (void) md_get_mem(in_mb, &hdr.h_challenge, NTLM_CHAL_SZ, MB_MSYSTEM); /* * Save flags, challenge for later. @@ -344,9 +344,9 @@ ntlmssp_get_type2(struct ssp_ctx *sp, struct mbdata *in_mb) */ if ((m_totlen(top_mb.mb_top) > sizeof (hdr)) && (hdr.h_target_name.sb_offset >= sizeof (hdr))) { - (void) mb_get_uint32le(in_mb, &hdr.h_context[0]); - (void) mb_get_uint32le(in_mb, &hdr.h_context[1]); - (void) mb_get_sb_hdr(in_mb, &hdr.h_target_info); + (void) md_get_uint32le(in_mb, &hdr.h_context[0]); + (void) md_get_uint32le(in_mb, &hdr.h_context[1]); + (void) md_get_sb_hdr(in_mb, &hdr.h_target_info); } /* @@ -354,18 +354,18 @@ ntlmssp_get_type2(struct ssp_ctx *sp, struct mbdata *in_mb) * the data from the offset/length indicated in the * security buffer header; then parse the string. */ - err = mb_get_sb_data(&top_mb, &hdr.h_target_name, &m); + err = md_get_sb_data(&top_mb, &hdr.h_target_name, &m); if (err) goto out; mb_initm(&tmp_mb, m); - err = mb_get_string(&tmp_mb, &ssp_st->ss_target_name, uc); + err = md_get_string(&tmp_mb, &ssp_st->ss_target_name, uc); mb_done(&tmp_mb); /* * Get the target info blob, if present. */ if (hdr.h_target_info.sb_offset >= sizeof (hdr)) { - err = mb_get_sb_data(&top_mb, &hdr.h_target_info, + err = md_get_sb_data(&top_mb, &hdr.h_target_info, &ssp_st->ss_target_info); } @@ -422,7 +422,7 @@ ntlmssp_put_type3(struct ssp_ctx *sp, struct mbdata *out_mb) goto out; } - if ((err = mb_init(&mb2, M_MINSIZE)) != 0) + if ((err = mb_init(&mb2)) != 0) goto out; mb2.mb_count = sizeof (hdr); uc = ssp_st->ss_flags & NTLMSSP_NEGOTIATE_UNICODE; @@ -475,7 +475,7 @@ ntlmssp_put_type3(struct ssp_ctx *sp, struct mbdata *out_mb) * Marshal the header (in LE order) * then concatenate the 2nd part. */ - (void) mb_put_mem(out_mb, &hdr.h_id, ID_SZ); + (void) mb_put_mem(out_mb, &hdr.h_id, ID_SZ, MB_MSYSTEM); (void) mb_put_uint32le(out_mb, hdr.h_type); (void) mb_put_sb_hdr(out_mb, &hdr.h_lm_resp); @@ -555,7 +555,7 @@ ntlmssp_next_token(struct ssp_ctx *sp, struct mbdata *in_mb, } /* Will build an ouptut token. */ - err = mb_init(out_mb, M_MINSIZE); + err = mb_init(out_mb); if (err) goto out; diff --git a/usr/src/lib/libsmbfs/smb/print.c b/usr/src/lib/libsmbfs/smb/print.c index 263cafaa93..268c330a0b 100644 --- a/usr/src/lib/libsmbfs/smb/print.c +++ b/usr/src/lib/libsmbfs/smb/print.c @@ -75,19 +75,19 @@ smb_printer_open(struct smb_ctx *ctx, int setuplen, int mode, smb_rq_wend(rqp); smb_rq_bstart(rqp); mb_put_uint8(mbp, SMB_DT_ASCII); - mb_put_dstring(mbp, ident, uc); + mb_put_string(mbp, ident, uc); smb_rq_bend(rqp); error = smb_rq_simple(rqp); if (error) goto out; mbp = smb_rq_getreply(rqp); - error = mb_get_uint8(mbp, &wc); + error = md_get_uint8(mbp, &wc); if (error || wc < 1) { error = EBADRPC; goto out; } - mb_get_uint16(mbp, &fh); + md_get_uint16le(mbp, &fh); *fhp = fh; error = 0; diff --git a/usr/src/lib/libsmbfs/smb/private.h b/usr/src/lib/libsmbfs/smb/private.h index b95ec1f7f4..e6124f2e57 100644 --- a/usr/src/lib/libsmbfs/smb/private.h +++ b/usr/src/lib/libsmbfs/smb/private.h @@ -47,6 +47,7 @@ #include <sys/byteorder.h> #include <sys/ccompile.h> +#include <netsmb/mchain.h> #include <netsmb/netbios.h> extern void dprint(const char *, const char *, ...) @@ -71,39 +72,6 @@ extern void dprint(const char *, const char *, ...) #define SMBV_EXT_SEC 0x0080 /* conn to use extended security */ #define SMBV_WILL_SIGN 0x0100 /* negotiated signing */ - -/* - * BSD-style mbuf simulation - */ -struct mbuf { - int m_len; - int m_maxlen; - char *m_data; - struct mbuf *m_next; -}; -typedef struct mbuf mbuf_t; - -struct mbdata { - struct mbuf *mb_top; - struct mbuf *mb_cur; - char *mb_pos; - int mb_count; -}; -typedef struct mbdata mbdata_t; - -/* - * Note: Leaving a little space (8 bytes) between the - * mbuf header and the start of the data so we can - * prepend a NetBIOS header in that space. - */ -#define M_ALIGNFACTOR (sizeof (long)) -#define M_ALIGN(len) (((len) + M_ALIGNFACTOR - 1) & ~(M_ALIGNFACTOR - 1)) -#define M_BASESIZE (sizeof (struct mbuf) + 8) -#define M_MINSIZE (1024 - M_BASESIZE) -#define M_TOP(m) ((char *)(m) + M_BASESIZE) -#define M_TRAILINGSPACE(m) ((m)->m_maxlen - (m)->m_len) -#define mtod(m, t) ((t)(m)->m_data) - /* * request handling structures */ @@ -140,52 +108,26 @@ void smb_rq_wend(struct smb_rq *); int smb_rq_simple(struct smb_rq *); int smb_rq_dmem(struct mbdata *, const char *, size_t); int smb_rq_internal(struct smb_ctx *, struct smb_rq *); -int smb_rq_sign(struct smb_rq *); +void smb_rq_sign(struct smb_rq *); int smb_rq_verify(struct smb_rq *); - /* - * Message compose/parse + * This library extends the mchain.h function set a little. */ - -void m_freem(struct mbuf *); -int m_getm(struct mbuf *, size_t, struct mbuf **); +int m_getm(struct mbuf *, int, struct mbuf **); int m_lineup(struct mbuf *, struct mbuf **); size_t m_totlen(struct mbuf *); -int mb_init(struct mbdata *, size_t); -int mb_initm(struct mbdata *, struct mbuf *); -int mb_done(struct mbdata *); -int mb_fit(struct mbdata *mbp, size_t size, char **pp); -int mb_put_uint8(struct mbdata *, uint8_t); -int mb_put_uint16be(struct mbdata *, uint16_t); -int mb_put_uint16le(struct mbdata *, uint16_t); -int mb_put_uint32be(struct mbdata *, uint32_t); -int mb_put_uint32le(struct mbdata *, uint32_t); -int mb_put_uint64be(struct mbdata *, uint64_t); -int mb_put_uint64le(struct mbdata *, uint64_t); -int mb_put_mem(struct mbdata *, const void *, size_t); -int mb_put_mbuf(struct mbdata *, struct mbuf *); +int mb_init_sz(struct mbdata *, int); +int mb_fit(struct mbdata *mbp, int size, char **pp); + +int mb_put_string(struct mbdata *mbp, const char *s, int); int mb_put_astring(struct mbdata *mbp, const char *s); -int mb_put_dstring(struct mbdata *mbp, const char *s, int); int mb_put_ustring(struct mbdata *mbp, const char *s); -int mb_get_uint8(struct mbdata *, uint8_t *); -int mb_get_uint16(struct mbdata *, uint16_t *); -int mb_get_uint16le(struct mbdata *, uint16_t *); -int mb_get_uint16be(struct mbdata *, uint16_t *); -int mb_get_uint32(struct mbdata *, uint32_t *); -int mb_get_uint32be(struct mbdata *, uint32_t *); -int mb_get_uint32le(struct mbdata *, uint32_t *); -int mb_get_uint64(struct mbdata *, uint64_t *); -int mb_get_uint64be(struct mbdata *, uint64_t *); -int mb_get_uint64le(struct mbdata *, uint64_t *); -int mb_get_mem(struct mbdata *, void *, size_t); -int mb_get_mbuf(struct mbdata *, int, struct mbuf **); -int mb_get_string(struct mbdata *, char **, int); -int mb_get_astring(struct mbdata *, char **); -int mb_get_ustring(struct mbdata *, char **); - +int md_get_string(struct mbdata *, char **, int); +int md_get_astring(struct mbdata *, char **); +int md_get_ustring(struct mbdata *, char **); /* * Network stuff (NetBIOS and otherwise) diff --git a/usr/src/lib/libsmbfs/smb/rap.c b/usr/src/lib/libsmbfs/smb/rap.c index 8260e2639c..98f35af5ff 100644 --- a/usr/src/lib/libsmbfs/smb/rap.c +++ b/usr/src/lib/libsmbfs/smb/rap.c @@ -222,9 +222,11 @@ smb_rap_create(int fn, const char *param, const char *data, len += plen; } rap->r_pbuf = rap->r_npbuf = malloc(len); - smb_rap_rqparam(rap, 'W', 1, fn); - smb_rap_rqparam_z(rap, rap->r_sparam); - smb_rap_rqparam_z(rap, rap->r_sdata); + if (rap->r_pbuf == NULL) + return (ENOMEM); + (void) smb_rap_rqparam(rap, 'W', 1, fn); + (void) smb_rap_rqparam_z(rap, rap->r_sparam); + (void) smb_rap_rqparam_z(rap, rap->r_sdata); *rapp = rap; return (0); } diff --git a/usr/src/lib/libsmbfs/smb/rq.c b/usr/src/lib/libsmbfs/smb/rq.c index 7b21708428..6045237393 100644 --- a/usr/src/lib/libsmbfs/smb/rq.c +++ b/usr/src/lib/libsmbfs/smb/rq.c @@ -51,6 +51,8 @@ #include <netsmb/smb_lib.h> #include "private.h" +#define MIN_REPLY_SIZE 4096 + static uint32_t smb_map_doserr(uint8_t, uint16_t); /* @@ -85,11 +87,11 @@ smb_rq_init(struct smb_ctx *ctx, uchar_t cmd, struct smb_rq **rqpp) * Setup the request buffer. * Do the reply buffer later. */ - if (mb_init(&rqp->rq_rq, M_MINSIZE)) + if (mb_init(&rqp->rq_rq)) goto errout; /* Space for the SMB header. (filled in later) */ - mb_put_mem(&rqp->rq_rq, NULL, SMB_HDRLEN); + mb_put_mem(&rqp->rq_rq, NULL, SMB_HDRLEN, MB_MSYSTEM); /* * Copy the ctx flags here, so the caller can @@ -130,7 +132,7 @@ smb_rq_wstart(struct smb_rq *rqp) { struct mbdata *mbp = &rqp->rq_rq; - mb_fit(mbp, 1, &rqp->rq_wcntp); + (void) mb_fit(mbp, 1, &rqp->rq_wcntp); rqp->rq_wcbase = mbp->mb_count; } @@ -176,7 +178,7 @@ smb_rq_bstart(struct smb_rq *rqp) { struct mbdata *mbp = &rqp->rq_rq; - mb_fit(mbp, 2, &rqp->rq_bcntp); + (void) mb_fit(mbp, 2, &rqp->rq_bcntp); rqp->rq_bcbase = mbp->mb_count; } @@ -209,19 +211,16 @@ smb_rq_bend(struct smb_rq *rqp) rqp->rq_bcntp[1] = (bcnt >> 8); } -/* - * Removed: smb_rq_dmem - * which was mostly like: mb_put_mem - */ - int smb_rq_simple(struct smb_rq *rqp) { struct smbioc_rq krq; struct mbdata *mbp; + mbuf_t *m; char *data; uint32_t len; size_t rpbufsz; + int error; bzero(&krq, sizeof (krq)); krq.ioc_cmd = rqp->rq_cmd; @@ -231,7 +230,10 @@ smb_rq_simple(struct smb_rq *rqp) * and fill in the ioctl request. */ mbp = smb_rq_getrequest(rqp); - m_lineup(mbp->mb_top, &mbp->mb_top); + error = m_lineup(mbp->mb_top, &mbp->mb_top); + if (error) + return (error); + data = mtod(mbp->mb_top, char *); len = m_totlen(mbp->mb_top); @@ -246,20 +248,19 @@ smb_rq_simple(struct smb_rq *rqp) krq.ioc_tbuf = data + SMB_HDRLEN; /* - * Setup a buffer to hold the reply. - * - * Default size is M_MINSIZE, but the - * caller may increase rq_rpbufsz - * before calling this. + * Setup a buffer to hold the reply, + * at least MIN_REPLY_SIZE, or larger + * if the caller increased rq_rpbufsz. */ mbp = smb_rq_getreply(rqp); rpbufsz = rqp->rq_rpbufsz; - if (rpbufsz < M_MINSIZE) - rpbufsz = M_MINSIZE; - if (mb_init(mbp, rpbufsz)) - return (ENOMEM); + if (rpbufsz < MIN_REPLY_SIZE) + rpbufsz = MIN_REPLY_SIZE; + if ((error = m_get(rpbufsz, &m)) != 0) + return (error); + mb_initm(mbp, m); krq.ioc_rbufsz = rpbufsz; - krq.ioc_rbuf = mtod(mbp->mb_top, char *); + krq.ioc_rbuf = mtod(m, char *); /* * Call the driver @@ -271,7 +272,7 @@ smb_rq_simple(struct smb_rq *rqp) * Initialize returned mbdata. * SMB header already parsed. */ - mbp->mb_top->m_len = krq.ioc_rbufsz; + m->m_len = krq.ioc_rbufsz; return (0); } @@ -360,14 +361,13 @@ smb_rq_internal(struct smb_ctx *ctx, struct smb_rq *rqp) /* * rewind done; fill it in */ - mb_put_mem(mbp, (char *)SMB_SIGNATURE, SMB_SIGLEN); + mb_put_mem(mbp, ffsmb, SMB_SIGLEN, MB_MSYSTEM); mb_put_uint8(mbp, rqp->rq_cmd); - mb_put_mem(mbp, NULL, 4); /* status */ + mb_put_uint32le(mbp, 0); /* status */ mb_put_uint8(mbp, rqp->rq_hflags); mb_put_uint16le(mbp, rqp->rq_hflags2); - mb_put_uint16le(mbp, 0); /* pid_hi */ - mb_put_mem(mbp, NULL, 8); /* signature */ - mb_put_uint16le(mbp, 0); /* reserved */ + /* pid_hi(2), signature(8), reserved(2) */ + mb_put_mem(mbp, NULL, 12, MB_MZERO); mb_put_uint16le(mbp, rqp->rq_tid); mb_put_uint16le(mbp, 0); /* pid_lo */ mb_put_uint16le(mbp, rqp->rq_uid); @@ -416,22 +416,21 @@ smb_rq_internal(struct smb_ctx *ctx, struct smb_rq *rqp) /* * Decode the SMB header. */ - mb_get_mem(mbp, (char *)sigbuf, 4); + md_get_mem(mbp, (char *)sigbuf, 4, MB_MSYSTEM); if (0 != bcmp(sigbuf, ffsmb, 4)) { DPRINT("not SMB"); return (EBADRPC); } - mb_get_uint8(mbp, &ctmp); /* SMB cmd */ - mb_get_uint32le(mbp, &rqp->rq_status); - mb_get_uint8(mbp, &rqp->rq_hflags); - mb_get_uint16le(mbp, &rqp->rq_hflags2); - mb_get_uint16le(mbp, NULL); /* pid_hi */ - mb_get_mem(mbp, NULL, 8); /* signature */ - mb_get_uint16le(mbp, NULL); /* reserved */ - mb_get_uint16le(mbp, &rqp->rq_tid); - mb_get_uint16le(mbp, NULL); /* pid_lo */ - mb_get_uint16le(mbp, &rqp->rq_uid); - mb_get_uint16le(mbp, &rqp->rq_mid); + md_get_uint8(mbp, &ctmp); /* SMB cmd */ + md_get_uint32le(mbp, &rqp->rq_status); + md_get_uint8(mbp, &rqp->rq_hflags); + md_get_uint16le(mbp, &rqp->rq_hflags2); + /* pid_hi(2), signature(8), reserved(2) */ + md_get_mem(mbp, NULL, 12, MB_MSYSTEM); + md_get_uint16le(mbp, &rqp->rq_tid); + md_get_uint16le(mbp, NULL); /* pid_lo */ + md_get_uint16le(mbp, &rqp->rq_uid); + md_get_uint16le(mbp, &rqp->rq_mid); /* * Figure out the status return. diff --git a/usr/src/lib/libsmbfs/smb/signing.c b/usr/src/lib/libsmbfs/smb/signing.c index ef9a32e2e0..0e9c826bbd 100644 --- a/usr/src/lib/libsmbfs/smb/signing.c +++ b/usr/src/lib/libsmbfs/smb/signing.c @@ -142,7 +142,7 @@ smb_compute_MAC(struct smb_ctx *ctx, mbuf_t *m, /* * Sign a request with HMAC-MD5. */ -int +void smb_rq_sign(struct smb_rq *rqp) { struct smb_ctx *ctx = rqp->rq_ctx; @@ -155,7 +155,7 @@ smb_rq_sign(struct smb_rq *rqp) * but just in case... */ if (m->m_len < SMB_HDRLEN) - return (EIO); + return; sigloc = (uchar_t *)m->m_data + SMBSIGOFF; if (ctx->ct_mackey == NULL) { @@ -165,7 +165,7 @@ smb_rq_sign(struct smb_rq *rqp) * This happens with SPNEGO, NTLMSSP, ... */ bcopy("BSRSPLY", sigloc, 8); - return (0); + return; } /* @@ -178,9 +178,7 @@ smb_rq_sign(struct smb_rq *rqp) if (err) { DPRINT("compute MAC, err %d", err); bzero(sigloc, SMBSIGLEN); - return (ENOTSUP); } - return (0); } /* @@ -247,10 +245,10 @@ smb_rq_verify(struct smb_rq *rqp) * of the sequence # has gotten a bit out of sync. */ for (fudge = 1; fudge <= nsmb_signing_fudge; fudge++) { - smb_compute_MAC(ctx, m, rseqno + fudge, sigbuf); + (void) smb_compute_MAC(ctx, m, rseqno + fudge, sigbuf); if (bcmp(sigbuf, sigloc, SMBSIGLEN) == 0) break; - smb_compute_MAC(ctx, m, rseqno - fudge, sigbuf); + (void) smb_compute_MAC(ctx, m, rseqno - fudge, sigbuf); if (bcmp(sigbuf, sigloc, SMBSIGLEN) == 0) { fudge = -fudge; break; diff --git a/usr/src/lib/libsmbfs/smb/ssnsetup.c b/usr/src/lib/libsmbfs/smb/ssnsetup.c index e4b5ec4f20..712a71f34c 100644 --- a/usr/src/lib/libsmbfs/smb/ssnsetup.c +++ b/usr/src/lib/libsmbfs/smb/ssnsetup.c @@ -405,11 +405,11 @@ smb__ssnsetup(struct smb_ctx *ctx, mb_put_mbuf(mbp, mbc2->mb_top); /* NT password */ mbc2->mb_top = NULL; /* consumed */ } - mb_put_dstring(mbp, ctx->ct_user, uc); - mb_put_dstring(mbp, ctx->ct_domain, uc); + mb_put_string(mbp, ctx->ct_user, uc); + mb_put_string(mbp, ctx->ct_domain, uc); } - mb_put_dstring(mbp, NativeOS, uc); - mb_put_dstring(mbp, LanMan, uc); + mb_put_string(mbp, NativeOS, uc); + mb_put_string(mbp, LanMan, uc); smb_rq_bend(rqp); err = smb_rq_internal(ctx, rqp); @@ -436,7 +436,7 @@ smb__ssnsetup(struct smb_ctx *ctx, is->is_smbuid = rqp->rq_uid; mbp = &rqp->rq_rp; - err = mb_get_uint8(mbp, &wc); + err = md_get_uint8(mbp, &wc); if (err) goto out; @@ -444,18 +444,18 @@ smb__ssnsetup(struct smb_ctx *ctx, if (caps & SMB_CAP_EXT_SECURITY) { if (wc != 4) goto out; - mb_get_uint16le(mbp, NULL); /* secondary cmd */ - mb_get_uint16le(mbp, NULL); /* andxoffset */ - mb_get_uint16le(mbp, actionp); /* action */ - mb_get_uint16le(mbp, &sblen); /* sec. blob len */ - mb_get_uint16le(mbp, &bc); /* byte count */ + md_get_uint16le(mbp, NULL); /* secondary cmd */ + md_get_uint16le(mbp, NULL); /* andxoffset */ + md_get_uint16le(mbp, actionp); /* action */ + md_get_uint16le(mbp, &sblen); /* sec. blob len */ + md_get_uint16le(mbp, &bc); /* byte count */ /* * Get the security blob, after * sanity-checking the length. */ if (sblen == 0 || bc < sblen) goto out; - err = mb_get_mbuf(mbp, sblen, &m); + err = md_get_mbuf(mbp, sblen, &m); if (err) goto out; mb_initm(mbc2, m); @@ -463,10 +463,10 @@ smb__ssnsetup(struct smb_ctx *ctx, } else { if (wc != 3) goto out; - mb_get_uint16le(mbp, NULL); /* secondary cmd */ - mb_get_uint16le(mbp, NULL); /* andxoffset */ - mb_get_uint16le(mbp, actionp); /* action */ - err = mb_get_uint16le(mbp, &bc); /* byte count */ + md_get_uint16le(mbp, NULL); /* secondary cmd */ + md_get_uint16le(mbp, NULL); /* andxoffset */ + md_get_uint16le(mbp, actionp); /* action */ + err = md_get_uint16le(mbp, &bc); /* byte count */ if (err) goto out; } @@ -485,9 +485,9 @@ smb__ssnsetup(struct smb_ctx *ctx, goto out; /* Ignore any parsing errors for these strings. */ - err = mb_get_string(mbp, &ctx->ct_srv_OS, uc); + err = md_get_string(mbp, &ctx->ct_srv_OS, uc); DPRINT("server OS: %s", err ? "?" : ctx->ct_srv_OS); - err = mb_get_string(mbp, &ctx->ct_srv_LM, uc); + err = md_get_string(mbp, &ctx->ct_srv_LM, uc); DPRINT("server LM: %s", err ? "?" : ctx->ct_srv_LM); /* * There's sometimes a server domain folloing diff --git a/usr/src/lib/libsmbfs/smb/ssp.c b/usr/src/lib/libsmbfs/smb/ssp.c index f8433ba8e5..d0b0d86d4f 100644 --- a/usr/src/lib/libsmbfs/smb/ssp.c +++ b/usr/src/lib/libsmbfs/smb/ssp.c @@ -277,7 +277,7 @@ ssp_ctx_next_token(struct smb_ctx *ctx, err = EBADRPC; goto out; } - err = mb_init(&body_in, (size_t)toklen); + err = mb_init_sz(&body_in, (size_t)toklen); if (err) goto out; m = body_in.mb_top; @@ -354,7 +354,7 @@ ssp_ctx_next_token(struct smb_ctx *ctx, err = EBADRPC; goto out; } - err = mb_init(caller_out, (size_t)toklen); + err = mb_init_sz(caller_out, (size_t)toklen); if (err) goto out; m = caller_out->mb_top; |