This commit was generated by cvs2svn to compensate for changes in r88282,

which included commits to RCS files with non-trunk default branches.
This commit is contained in:
Sheldon Hearn 2001-12-20 16:16:25 +00:00
commit 2731c8aafa
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=88283
18 changed files with 254 additions and 29 deletions

View File

@ -1,3 +1,8 @@
20.12.2001 1.4.2 (interim)
- Various merges (but not all) from Darwin project.
- Minor man pages corrections.
- Support builds in the FreeBSD main tree.
16.04.2001 1.4.1
- Kernel side of smbfs committed in the FreeBSD-current. It controlled
by following options: LIBMCHAIN, LIBICONV, NETSMB, NETSMBCRYPTO and SMBFS.

View File

@ -1,4 +1,4 @@
# $Id: Makefile.inc,v 1.9 2001/04/16 04:34:26 bp Exp $
# $Id: Makefile.inc,v 1.10 2001/05/03 10:05:47 bp Exp $
.ifmake !clean && !cleandepend
.if !defined(PREFIX)
@ -22,6 +22,8 @@ LIBSMB = ../lib/smb/libsmb.a
.if !exists(${SYSDIR}/netsmb/smb.h)
CFLAGS += -I../kernel
.else
CFLAGS += -I${SYSDIR}
.endif
.if defined(SMBGDB)

View File

@ -6,11 +6,14 @@
This is native SMB/CIFS filesystem (smbfs for short) for FreeBSD.
It is a complete, kernel side implementation of SMB requester and filesystem.
Supportted platforms:
FreeBSD 4.X
Supported platform Comment
FreeBSD 4.X Port
FreeBSD-current kernel module is included in the base source
tree.
FreeBSD 4.5 Everything available in the base system.
FreeBSD-current Everything available in the base system.
Darwin maintained in the Darwin's tree.
I'm would be very grateful for any feedback, bug reports etc.

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: smb_lib.h,v 1.22 2001/04/10 05:37:22 bp Exp $
* $Id: smb_lib.h,v 1.24 2001/12/20 15:19:43 bp Exp $
*/
#ifndef _NETSMB_SMB_LIB_H_
#define _NETSMB_SMB_LIB_H_
@ -37,7 +37,9 @@
#include <netsmb/smb.h>
#include <netsmb/smb_dev.h>
#ifndef SMB_CFG_FILE
#define SMB_CFG_FILE "/usr/local/etc/nsmb.conf"
#endif
#define STDPARAM_ARGS 'A':case 'B':case 'C':case 'E':case 'I': \
case 'L':case 'M': \
@ -208,7 +210,7 @@ int smb_rq_dstring(struct mbdata *, const char *);
int smb_t2_request(struct smb_ctx *, int, int, const char *,
int, void *, int, void *, int *, void *, int *, void *);
void smb_simplecrypt(char *dst, const char *src);
char* smb_simplecrypt(char *dst, const char *src);
int smb_simpledecrypt(char *dst, const char *src);
int m_getm(struct mbuf *, size_t, struct mbuf **);

View File

@ -6,6 +6,8 @@ CFLAGS+= -Wall ${BPCFLAGS}
.if !exists(${SYSDIR}/netsmb/smb.h)
CFLAGS+= -I${.CURDIR}/../../kernel
.else
CFLAGS+= -I${SYSDIR}
.endif
.if defined(SMBGDB)

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: kiconv.c,v 1.2 2001/04/16 04:33:01 bp Exp $
* $Id: kiconv.c,v 1.3 2001/08/22 03:31:36 bp Exp $
*/
#include <sys/types.h>
@ -38,6 +38,11 @@
#include <ctype.h>
#include <errno.h>
#ifdef APPLE
#include <sys/types.h>
extern uid_t real_uid, eff_uid;
#endif
int
kiconv_add_xlat_table(const char *to, const char *from, const u_char *table)
{
@ -54,8 +59,17 @@ kiconv_add_xlat_table(const char *to, const char *from, const u_char *table)
din.ia_data = table;
din.ia_datalen = 256;
olen = sizeof(dout);
#ifdef APPLE
seteuid(eff_uid); /* restore setuid root briefly */
if (sysctlbyname("net.smb.fs.iconv.add", &dout, &olen, &din, sizeof(din)) == -1) {
seteuid(real_uid); /* and back to real user */
return errno;
}
seteuid(real_uid); /* and back to real user */
#else
if (sysctlbyname("kern.iconv.add", &dout, &olen, &din, sizeof(din)) == -1)
return errno;
#endif
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, Boris Popov
* Copyright (c) 2000-2001, Boris Popov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -29,10 +29,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: nb_name.c,v 1.1 2000/07/16 01:52:07 bp Exp $
* $Id: nb_name.c,v 1.2 2001/08/22 03:31:36 bp Exp $
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/mchain.h> /* for endiand macros */
#include <ctype.h>
#include <err.h>
@ -138,8 +139,8 @@ nb_encname_len(const char *str)
return len;
}
#define NBENCODE(c) ((u_short)(((u_char)(c) >> 4) | \
(((u_char)(c) & 0xf) << 8)) + 0x4141)
#define NBENCODE(c) (htoles((u_short)(((u_char)(c) >> 4) | \
(((u_char)(c) & 0xf) << 8)) + 0x4141))
static void
memsetw(char *dst, int n, u_short word)

View File

@ -29,14 +29,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: nls.c,v 1.8 2001/04/16 12:46:46 bp Exp $
* $Id: nls.c,v 1.9 2001/08/22 03:31:36 bp Exp $
*/
#include <sys/types.h>
#include <sys/iconv.h>
#include <sys/sysctl.h>
#include <ctype.h>
#ifndef APPLE
#include <dlfcn.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <strings.h>
@ -80,6 +82,9 @@ nls_setlocale(const char *name)
int
nls_setrecode(const char *local, const char *external)
{
#ifdef APPLE
return ENOENT;
#else
iconv_t icd;
if (iconv_loaded == 2)
@ -113,6 +118,7 @@ nls_setrecode(const char *local, const char *external)
}
nls_toloc = icd;
return 0;
#endif
}
char *

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: subr.c,v 1.11 2001/04/16 04:33:01 bp Exp $
* $Id: subr.c,v 1.12 2001/08/22 03:31:37 bp Exp $
*/
#include <sys/param.h>
@ -50,6 +50,15 @@
#include <netsmb/nb_lib.h>
#include <cflib.h>
#ifdef APPLE
#include <sysexits.h>
#include <sys/wait.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
uid_t real_uid, eff_uid;
#endif
extern char *__progname;
static int smblib_initialized;
@ -174,13 +183,25 @@ smb_dumptree(void)
void *p;
int error;
#ifdef APPLE
seteuid(eff_uid); /* restore setuid root briefly */
#endif
error = sysctlbyname("net.smb.treedump", NULL, &len, NULL, 0);
#ifdef APPLE
seteuid(real_uid); /* and back to real user */
#endif
if (error)
return NULL;
p = malloc(len);
if (p == NULL)
return NULL;
#ifdef APPLE
seteuid(eff_uid); /* restore setuid root briefly */
#endif
error = sysctlbyname("net.smb.treedump", p, &len, NULL, 0);
#ifdef APPLE
seteuid(real_uid); /* and back to real user */
#endif
if (error) {
free(p);
return NULL;
@ -188,11 +209,18 @@ smb_dumptree(void)
return p;
}
void
char *
smb_simplecrypt(char *dst, const char *src)
{
int ch, pos;
char *dp;
if (dst == NULL) {
dst = malloc(4 + 2 * strlen(src));
if (dst == NULL)
return NULL;
}
dp = dst;
*dst++ = '$';
*dst++ = '$';
*dst++ = '1';
@ -208,6 +236,7 @@ smb_simplecrypt(char *dst, const char *src)
dst += 2;
}
*dst = 0;
return dp;
}
int
@ -241,3 +270,107 @@ smb_simpledecrypt(char *dst, const char *src)
*dst = 0;
return 0;
}
#ifdef APPLE
static int
safe_execv(char *args[])
{
int pid;
union wait status;
pid = fork();
if (pid == 0) {
(void)execv(args[0], args);
errx(EX_OSERR, "%s: execv %s failed, %s\n", __progname,
args[0], strerror(errno));
}
if (pid == -1) {
fprintf(stderr, "%s: fork failed, %s\n", __progname,
strerror(errno));
return (1);
}
if (wait4(pid, (int *)&status, 0, NULL) != pid) {
fprintf(stderr, "%s: BUG executing %s command\n", __progname,
args[0]);
return (1);
} else if (!WIFEXITED(status)) {
fprintf(stderr, "%s: %s command aborted by signal %d\n",
__progname, args[0], WTERMSIG(status));
return (1);
} else if (WEXITSTATUS(status)) {
fprintf(stderr, "%s: %s command failed, exit status %d: %s\n",
__progname, args[0], WEXITSTATUS(status),
strerror(WEXITSTATUS(status)));
return (1);
}
return (0);
}
void
dropsuid()
{
/* drop setuid root privs asap */
eff_uid = geteuid();
real_uid = getuid();
seteuid(real_uid);
return;
}
static int
kextisloaded(char * kextname)
{
mach_port_t kernel_port;
kmod_info_t *k, *loaded_modules = 0;
int err, loaded_count = 0;
/* on error return not loaded - to make loadsmbvfs fail */
err = task_for_pid(mach_task_self(), 0, &kernel_port);
if (err) {
fprintf(stderr, "%s: %s: %s\n", __progname,
"unable to get kernel task port",
mach_error_string(err));
return (0);
}
err = kmod_get_info(kernel_port, (void *)&loaded_modules,
&loaded_count); /* never freed */
if (err) {
fprintf(stderr, "%s: %s: %s\n", __progname,
"kmod_get_info() failed",
mach_error_string(err));
return (0);
}
for (k = loaded_modules; k; k = k->next ? k+1 : 0)
if (!strcmp(k->name, kextname))
return (1);
return (0);
}
#define KEXTLOAD_COMMAND "/sbin/kextload"
#define FS_KEXT_DIR "/System/Library/Extensions/smbfs.kext"
#define FULL_KEXTNAME "com.apple.filesystems.smbfs"
int
loadsmbvfs()
{
const char *kextargs[] = {KEXTLOAD_COMMAND, FS_KEXT_DIR, NULL};
int error = 0;
/*
* temporarily revert to root (required for kextload)
*/
seteuid(eff_uid);
if (!kextisloaded(FULL_KEXTNAME)) {
error = safe_execv(kextargs);
if (!error)
error = !kextisloaded(FULL_KEXTNAME);
}
seteuid(real_uid); /* and back to real user */
return (error);
}
#endif /* APPLE */

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)mntopts.h 8.7 (Berkeley) 3/29/95
* $Id: mntopts.h,v 1.1 2000/03/29 01:26:41 bp Exp $
* $Id: mntopts.h,v 1.2 2001/08/22 03:32:52 bp Exp $
*/
struct mntopt {
@ -43,19 +43,25 @@ struct mntopt {
/* User-visible MNT_ flags. */
#define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 }
#ifndef APPLE
#define MOPT_NOATIME { "atime", 1, MNT_NOATIME, 0 }
#endif
#define MOPT_NODEV { "dev", 1, MNT_NODEV, 0 }
#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 }
#define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 }
#ifndef APPLE
#define MOPT_NOSYMFOLLOW { "symfollow", 1, MNT_NOSYMFOLLOW, 0 }
#endif
#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY, 0 }
#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 }
#define MOPT_UNION { "union", 0, MNT_UNION, 0 }
#define MOPT_USERQUOTA { "userquota", 0, 0, 0 }
#define MOPT_GROUPQUOTA { "groupquota", 0, 0, 0 }
#ifndef APPLE
#define MOPT_NOCLUSTERR { "clusterr", 1, MNT_NOCLUSTERR, 0 }
#define MOPT_NOCLUSTERW { "clusterw", 1, MNT_NOCLUSTERW, 0 }
#define MOPT_SUIDDIR { "suiddir", 0, MNT_SUIDDIR, 0 }
#endif
/* Control flags. */
#define MOPT_FORCE { "force", 0, MNT_FORCE, 0 }
@ -72,6 +78,17 @@ struct mntopt {
MOPT_AUTO
/* Standard options which all mounts can understand. */
#ifdef APPLE
#define MOPT_STDOPTS \
MOPT_USERQUOTA, \
MOPT_GROUPQUOTA, \
MOPT_FSTAB_COMPAT, \
MOPT_NODEV, \
MOPT_NOEXEC, \
MOPT_NOSUID, \
MOPT_RDONLY, \
MOPT_UNION
#else
#define MOPT_STDOPTS \
MOPT_USERQUOTA, \
MOPT_GROUPQUOTA, \
@ -86,6 +103,7 @@ struct mntopt {
MOPT_UNION, \
MOPT_NOCLUSTERR, \
MOPT_NOCLUSTERW
#endif /* APPLE */
void getmntopts __P((const char *, const struct mntopt *, int *, int *));
extern int getmnt_silent;

View File

@ -1,4 +1,4 @@
.\" $Id: mount_smbfs.8,v 1.8 2000/06/09 13:52:56 bp Exp $
.\" $Id: mount_smbfs.8,v 1.9 2001/12/20 15:11:45 bp Exp $
.Dd Mar 10, 2000
.Dt MOUNT_SMBFS 8
.Os FreeBSD
@ -100,7 +100,7 @@ The values must be specified as octal numbers.
Default value for the file mode
is taken from mount point, default value for the dir mode adds execute
permission where the file mode gives read permission.
.Pp
Note that these permissions can differ from the rights granted by SMB
server.
.It Fl u Ar uid , Fl g Ar gid
@ -128,7 +128,6 @@ See
.Pa ./examples/dot.nsmbrc
for details.
.El
.Sh EXAMPLES
The following examples illustrate how to connect to a SMB server
.Em SAMBA
@ -149,10 +148,8 @@ for smbfs mounts:
.Bd -literal -offset indent
//guest@samba/public /smb/public smbfs rw,noauto 0 0
.Ed
.Sh BUGS
Please report bugs to the author.
.Sh AUTHORS
.An Boris Popov Aq bp@butya.kz ,
.Aq bp@freebsd.org

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mount_smbfs.c,v 1.13 2001/04/16 12:46:46 bp Exp $
* $Id: mount_smbfs.c,v 1.15 2001/12/20 15:03:41 bp Exp $
*/
#include <sys/param.h>
#include <sys/stat.h>
@ -71,10 +71,19 @@ main(int argc, char *argv[])
struct smb_ctx sctx, *ctx = &sctx;
struct smbfs_args mdata;
struct stat st;
#ifdef APPLE
extern void dropsuid();
extern int loadsmbvfs();
#else
struct vfsconf vfc;
#endif /* APPLE */
char *next;
int opt, error, mntflags, caseopt;
#ifdef APPLE
dropsuid();
#endif /* APPLE */
if (argc == 2) {
if (strcmp(argv[1], "-h") == 0) {
usage();
@ -87,6 +96,9 @@ main(int argc, char *argv[])
if (argc < 3)
usage();
#ifdef APPLE
error = loadsmbvfs();
#else
error = getvfsbyname(SMBFS_VFSNAME, &vfc);
if (error && vfsisloadable(SMBFS_VFSNAME)) {
if(vfsload(SMBFS_VFSNAME))
@ -94,6 +106,7 @@ main(int argc, char *argv[])
endvfsent();
error = getvfsbyname(SMBFS_VFSNAME, &vfc);
}
#endif /* APPLE */
if (error)
errx(EX_OSERR, "SMB filesystem is not available");
@ -204,9 +217,9 @@ main(int argc, char *argv[])
if (smb_getextattr(mount_point, &einfo) == 0)
errx(EX_OSERR, "can't mount on %s twice", mount_point);
*/
if (mdata.uid == -1)
if (mdata.uid == (uid_t)-1)
mdata.uid = st.st_uid;
if (mdata.gid == -1)
if (mdata.gid == (gid_t)-1)
mdata.gid = st.st_gid;
if (mdata.file_mode == 0 )
mdata.file_mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);

View File

@ -15,3 +15,6 @@ void logout_usage(void);
void lookup_usage(void);
void print_usage(void);
void view_usage(void);
#ifdef APPLE
extern int loadsmbvfs();
#endif

View File

@ -4,6 +4,10 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#ifdef APPLE
#include <err.h>
#include <sysexits.h>
#endif
#include <netsmb/smb_lib.h>
#include <netsmb/smb_conn.h>
@ -102,6 +106,10 @@ cmd_dumptree(int argc, char *argv[])
int *itype;
printf("SMB connections:\n");
#ifdef APPLE
if (loadsmbvfs())
errx(EX_OSERR, "SMB filesystem is not available");
#endif
p = smb_dumptree();
if (p == NULL) {
printf("None\n");

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: login.c,v 1.5 2001/01/28 07:35:00 bp Exp $
* $Id: login.c,v 1.6 2001/08/22 03:33:38 bp Exp $
*/
#include <sys/param.h>
#include <sys/errno.h>
@ -78,6 +78,10 @@ cmd_login(int argc, char *argv[])
/*NOTREACHED*/
}
}
#ifdef APPLE
if (loadsmbvfs())
errx(EX_OSERR, "SMB filesystem is not available");
#endif
if (smb_ctx_resolve(ctx) != 0)
exit(1);
level = ctx->ct_parsedlevel;
@ -139,6 +143,11 @@ cmd_logout(int argc, char *argv[])
/*NOTREACHED*/
}
}
#ifdef APPLE
error = loadsmbvfs();
if (error)
errx(EX_OSERR, "SMB filesystem is not available");
#endif
ctx->ct_ssn.ioc_opt &= ~SMBVOPT_CREATE;
ctx->ct_sh.ioc_opt &= ~SMBSOPT_CREATE;
if (smb_ctx_resolve(ctx) != 0)

View File

@ -1,4 +1,4 @@
.\" $Id: smbutil.1,v 1.3 2000/07/17 01:49:27 bp Exp $
.\" $Id: smbutil.1,v 1.4 2001/12/20 15:11:34 bp Exp $
.Dd Feb 14, 2000
.Dt SMBUTIL 1
.Os
@ -117,6 +117,7 @@ keeps description for each connection.
See
.Pa ./examples/dot.nsmbrc
for details.
.El
.Sh AUTHORS
.An Boris Popov Aq bp@butya.kz ,
.Aq bp@freebsd.org

View File

@ -64,10 +64,9 @@ cmd_crypt(int argc, char *argv[])
psw = getpass("Password:");
else
psw = argv[1];
cp = malloc(strlen(psw + 4));
cp = smb_simplecrypt(NULL, psw);
if (cp == NULL)
errx(EX_DATAERR, "out of memory");
smb_simplecrypt(cp, psw);
printf("%s\n", cp);
free(cp);
exit(0);
@ -97,6 +96,11 @@ main(int argc, char *argv[])
struct commands *cmd;
char *cp;
int opt;
#ifdef APPLE
extern void dropsuid();
dropsuid();
#endif /* APPLE */
if (argc < 2)
help();

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: view.c,v 1.7 2001/01/28 07:35:01 bp Exp $
* $Id: view.c,v 1.8 2001/08/22 03:33:38 bp Exp $
*/
#include <sys/param.h>
#include <sys/errno.h>
@ -86,6 +86,10 @@ cmd_view(int argc, char *argv[])
/*NOTREACHED*/
}
}
#ifdef APPLE
if (loadsmbvfs())
errx(EX_OSERR, "SMB filesystem is not available");
#endif
smb_ctx_setshare(ctx, "IPC$", SMB_ST_ANY);
if (smb_ctx_resolve(ctx) != 0)
exit(1);