aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/smbfs/lib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/smbfs/lib')
-rw-r--r--contrib/smbfs/lib/Makefile.inc2
-rw-r--r--contrib/smbfs/lib/smb/kiconv.c16
-rw-r--r--contrib/smbfs/lib/smb/nb_name.c9
-rw-r--r--contrib/smbfs/lib/smb/nls.c8
-rw-r--r--contrib/smbfs/lib/smb/subr.c137
5 files changed, 164 insertions, 8 deletions
diff --git a/contrib/smbfs/lib/Makefile.inc b/contrib/smbfs/lib/Makefile.inc
index 43bd23ef2c56..331972700608 100644
--- a/contrib/smbfs/lib/Makefile.inc
+++ b/contrib/smbfs/lib/Makefile.inc
@@ -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)
diff --git a/contrib/smbfs/lib/smb/kiconv.c b/contrib/smbfs/lib/smb/kiconv.c
index ce69c84bb72c..e75f664643e7 100644
--- a/contrib/smbfs/lib/smb/kiconv.c
+++ b/contrib/smbfs/lib/smb/kiconv.c
@@ -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;
}
diff --git a/contrib/smbfs/lib/smb/nb_name.c b/contrib/smbfs/lib/smb/nb_name.c
index 24b1a80cf9df..01500c313a41 100644
--- a/contrib/smbfs/lib/smb/nb_name.c
+++ b/contrib/smbfs/lib/smb/nb_name.c
@@ -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)
diff --git a/contrib/smbfs/lib/smb/nls.c b/contrib/smbfs/lib/smb/nls.c
index 7517c6e0eb41..38db2e183bb1 100644
--- a/contrib/smbfs/lib/smb/nls.c
+++ b/contrib/smbfs/lib/smb/nls.c
@@ -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 *
diff --git a/contrib/smbfs/lib/smb/subr.c b/contrib/smbfs/lib/smb/subr.c
index 9541b629b51c..cd65315e5962 100644
--- a/contrib/smbfs/lib/smb/subr.c
+++ b/contrib/smbfs/lib/smb/subr.c
@@ -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 */