adds samba3

- compiles at ~1MB (or ~1,3MB if log files are enabled)
- patches to make samba3 small come from avm gpl releases
- added patches to match owrt dir layout
- rewritten smbpasswd to be endian safe and small
- printing is not yet tested
- disabled mmap as this breaks and oopses when running on jffs2



git-svn-id: svn://svn.openwrt.org/openwrt/packages@12278 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
blogic 2008-08-11 14:00:58 +00:00
parent e090c5e7f2
commit 2b63fb6a50
12 changed files with 7806 additions and 0 deletions

4
net/samba3/Config.in Normal file
View File

@ -0,0 +1,4 @@
config SAMBA3_DEBUG
bool "Enable Logging for samba3"
depends PACKAGE_samba3
default n

59
net/samba3/Makefile Normal file
View File

@ -0,0 +1,59 @@
#
# Copyright (C) 2008 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
include $(TOPDIR)/rules.mk
PKG_NAME:=samba3
PKG_VERSION:=3.0.24
PKG_RELEASE:=1
#PKG_MD5SUM:=b51b2975f21006f85f7297f3fb1acde1
PKG_SOURCE_URL:=ftp://ftp.samba.org/pub/samba/old-versions/
PKG_SOURCE:=samba-$(PKG_VERSION).tar.gz
PKG_BUILD_DIR:=$(BUILD_DIR)/samba-$(PKG_VERSION)/
include $(INCLUDE_DIR)/package.mk
TARGET_CFLAGS+=$(if $(CONFIG_SAMBA3_DEBUG),-DSAMBA_DEBUG)
define Package/samba3
SECTION:=net
CATEGORY:=Network
TITLE:=samba3
DEPENDS:=+libpthread
URL:=http://www.samba.org/
endef
define Package/samba3/Description
Samba3 - made small with patches taken from AVM GPL releases and freetz
endef
define Package/samba3/config
source "$(SOURCE)/Config.in"
endef
define Build/Compile
CFLAGS="$(TARGET_CFLAGS)" \
CC="$(TARGET_CC)" \
CPPFLAGS="$(TARGET_CPPFLAGS)" \
LDFLAGS="$(TARGET_LDFLAGS)" \
$(MAKE) -C $(PKG_BUILD_DIR)/source \
all bin/smbpasswd
endef
define Package/samba3/install
$(INSTALL_DIR) $(1)/etc/{samba,init.d,config}
$(INSTALL_BIN) ./files/samba.init $(1)/etc/init.d/samba
$(INSTALL_DATA) ./files/samba.config $(1)/etc/config/samba
$(INSTALL_DATA) ./files/smb.conf.template $(1)/etc/samba/
cd $(1)/etc/samba; rm -r smb.conf; ln -s /tmp/smb.conf
touch $(1)/etc/samba/smbpasswd
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/source/bin/smbpasswd $(1)/bin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/source/bin/smbd $(1)/bin/
endef
$(eval $(call BuildPackage,samba3))

View File

@ -0,0 +1,14 @@
config samba
option 'name' 'openwrt'
option 'workgroup' 'openwrt'
option 'description' 'openwrt'
option 'homes' '1'
config sambashare
option 'name' 'tmp'
option 'path' '/tmp'
option 'read_only' 'no'
option 'guest_ok' 'no'
option 'create_mask' '0700'
option 'dir_mask' '0700'
#option 'users' 'abc'

69
net/samba3/files/samba.init Executable file
View File

@ -0,0 +1,69 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2008 OpenWrt.org
. /etc/functions.sh
START=45
smb_header() {
local name
local workgroup
local description
local homes
config_get name $1 name
config_get workgroup $1 workgroup
config_get description $1 description
config_get homes $1 homes
[ -z "$name" ] && name=openwrt
[ -z "$workgroup" ] && workgroup=openwrt
[ -z "$description" ] && description=openwrt
cp /etc/samba/smb.conf.template /tmp/smb.conf
sed -i "s/|NAME|/$name/g" /tmp/smb.conf
sed -i "s/|WORKGROUP|/$workgroup/g" /tmp/smb.conf
sed -i "s/|DESCRIPTION|/$description/g" /tmp/smb.conf
[ "$homes" == "1" ] && {
echo -e "\n[homes]\n\tcomment = Home Directories\n\tbrowseable = no\n\tread only = no\n\tcreate mode = 0750" >> /tmp/smb.conf
}
}
smb_add_share() {
local name
local path
local users
local read_only
local guest_ok
local create_mask
local dir_mask
config_get name $1 name
config_get path $1 path
config_get users $1 users
config_get read_only $1 read_only
config_get guest_ok $1 guest_ok
config_get create_mask $1 create_mask
config_get dir_mask $1 dir_mask
[ -z "$name" -o -z "$path" ] && return
echo -e "\n[$name]\n\tpath = $path" >> /tmp/smb.conf
[ -n "$users" ] && echo -e "\tvalid users = $users" >> /tmp/smb.conf
[ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /tmp/smb.conf
[ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /tmp/smb.conf
[ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /tmp/smb.conf
[ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /tmp/smb.conf
}
start() {
config_load samba
config_foreach smb_header samba
config_foreach smb_add_share sambashare
smbd -D
}
stop() {
killall smbd
}

View File

@ -0,0 +1,16 @@
[global]
netbios name = |NAME|
workgroup = |WORKGROUP|
server string = |DESCRIPTION|
syslog = 10
encrypt passwords = true
passdb backend = smbpasswd
obey pam restrictions = yes
socket options = TCP_NODELAY
unix charset = ISO-8859-1
preferred master = yes
os level = 20
security = user
guest account = nobody
invalid users = root
smb passwd file = /etc/samba/smbpasswd

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,115 @@
Index: samba-3.0.24/source/Makefile
===================================================================
--- samba-3.0.24.orig/source/Makefile 2008-08-07 11:15:02.000000000 +0200
+++ samba-3.0.24/source/Makefile 2008-08-07 11:18:28.000000000 +0200
@@ -10,8 +10,6 @@
SOURCEROOT=$(shell pwd)/../../../..
SHAREDLIBS=$(SOURCEROOT)/sharedlibs
-include ${SHAREDLIBS}/ar7def.mk
-
# AR7
# prefix=/usr/local/samba
prefix=/var/samba
@@ -22,25 +20,27 @@
LIBS= -lcrypt -ldl -lpthread
# AR7
# CC=gcc
-CC=${TARGET}-gcc
+CC?=${TARGET}-gcc
RANLIB = ${TARGET}-ranlib
AR = ${TARGET}-ar
SHLD=${CC} ${CFLAGS}
# AR7
# CFLAGS= -O -D_SAMBA_BUILD_
-CFLAGS= -Os -D_SAMBA_BUILD_ -DAVM_NO_PRINTING
-CFLAGS+= -DAVM_NO_POPT
+CFLAPGS?=
+CFLAGS+= -Os -D_SAMBA_BUILD_ -DAVM_NO_PRINTING
+#CFLAGS+= -DAVM_NO_POPT
CFLAGS+= -DAVM_SMALLER
-
+#CFLAGS+= -DSAMBA_DEBUG
# uncomment this to get debugs
# CFLAGS += -DSAMBA_DEBUG
# AR7
# CPPFLAGS= -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
-CPPFLAGS= -D_GNU_SOURCE
+CPPFLAGS?= -D_GNU_SOURCE
+CPPFLAGS+= -D_GNU_SOURCE
EXEEXT=
-LDFLAGS=
+LDFLAGS?=
AR=ar
LDSHFLAGS=-shared -Wl,-Bsymbolic
WINBIND_NSS_LDSHFLAGS=-shared -Wl,-Bsymbolic
@@ -238,7 +238,9 @@
lib/adt_tree.o lib/gencache.o $(TDB_OBJ) \
lib/module.o lib/ldap_escape.o \
lib/privileges.o lib/secdesc.o lib/secace.o lib/secacl.o \
- lib/arc4.o lib/sharesec.o lib/events.o lib/util_nscd.o
+ lib/arc4.o lib/sharesec.o lib/events.o lib/util_nscd.o \
+ popt/poptparse.o popt/popthelp.o popt/poptconfig.o \
+ lib/popt_common.o popt/popt.o
LIB_NONSMBD_OBJ = $(LIB_OBJ) lib/dummysmbd.o lib/dummyroot.o
Index: samba-3.0.24/source/popt/popt.c
===================================================================
--- samba-3.0.24.orig/source/popt/popt.c 2008-08-07 11:15:00.000000000 +0200
+++ samba-3.0.24/source/popt/popt.c 2008-08-07 11:15:02.000000000 +0200
@@ -10,13 +10,14 @@
#include "system.h"
-#if HAVE_FLOAT_H
+//#if HAVE_FLOAT_H
#include <float.h>
-#endif
+//#endif
#include <math.h>
#include "findme.h"
#include "poptint.h"
+#include "../include/config.h"
#ifdef MYDEBUG
/*@unchecked@*/
@@ -384,7 +385,7 @@
sprintf(s, "%s/%s", con->execPath, item->argv[0]);
argv[argc] = s;
} else {
- argv[argc] = findProgramPath(item->argv[0]);
+ argv[argc] = ""/*findProgramPath(item->argv[0])*/;
}
if (argv[argc++] == NULL) return POPT_ERROR_NOARG;
@@ -1235,4 +1236,3 @@
return numargs;
}
-/*@=boundswrite@*/
Index: samba-3.0.24/source/smbd/server.c
===================================================================
--- samba-3.0.24.orig/source/smbd/server.c 2008-08-07 11:15:02.000000000 +0200
+++ samba-3.0.24/source/smbd/server.c 2008-08-07 11:15:02.000000000 +0200
@@ -47,7 +47,7 @@
void _fLog(char *fmt, ...)
{
va_list va;
- FILE *fp = fopen("/var/tmp/smbd.log", "a");
+ FILE *fp = fopen("/var/log/smbd.log", "a");
time_t t = time(0); /* LOG */
if (!fp) return;
@@ -63,7 +63,7 @@
void _fDebug(char *fmt, ...)
{
va_list va;
- FILE *fp = fopen("/var/tmp/smbd.log", "a");
+ FILE *fp = fopen("/var/log/smbd.log", "a");
time_t t = time(0); /* LOG */
if (!fp) return;

View File

@ -0,0 +1,57 @@
Index: samba-3.0.24/source/Makefile
===================================================================
--- samba-3.0.24.orig/source/Makefile 2008-08-06 23:33:20.000000000 +0200
+++ samba-3.0.24/source/Makefile 2008-08-06 23:34:48.000000000 +0200
@@ -12,7 +12,7 @@
# AR7
# prefix=/usr/local/samba
-prefix=/var/samba
+prefix=
exec_prefix=${prefix}
# AR7
@@ -108,11 +108,11 @@
# These can be overridden by command line switches (see smbd(8))
# or in smb.conf (see smb.conf(5))
LOGFILEBASE = ${VARDIR}
-CONFIGFILE = $(CONFIGDIR)/smb.conf
-LMHOSTSFILE = $(CONFIGDIR)/lmhosts
+CONFIGFILE = /etc/samba/smb.conf
+LMHOSTSFILE = /etc/lmhosts
# This is where smbpasswd et al go
-PRIVATEDIR = ${prefix}/private
+PRIVATEDIR = /etc/samba/
SMB_PASSWD_FILE = $(PRIVATEDIR)/smbpasswd
PRIVATE_DIR = $(PRIVATEDIR)
@@ -121,10 +121,10 @@
SWATDIR = ${prefix}/swat
# the directory where lock files go
-LOCKDIR = ${VARDIR}/locks
+LOCKDIR = ${VARDIR}/lock
# the directory where pid files go
-PIDDIR = ${VARDIR}/locks
+PIDDIR = ${VARDIR}/lock
LIBSMBCLIENT=bin/libsmbclient.a bin/libsmbclient.so
LIBSMBCLIENT_MAJOR=0
Index: samba-3.0.24/source/lib/util.c
===================================================================
--- samba-3.0.24.orig/source/lib/util.c 2008-08-06 23:41:58.000000000 +0200
+++ samba-3.0.24/source/lib/util.c 2008-08-06 23:42:10.000000000 +0200
@@ -300,11 +300,7 @@
char *p;
if ((p = getenv("TMPDIR")))
return p;
-#if 1 /* AR7 */
- return "/var/tmp";
-#else
return "/tmp";
-#endif
}
/****************************************************************************

View File

@ -0,0 +1,216 @@
Index: samba-3.0.24/source/Makefile
===================================================================
--- samba-3.0.24.orig/source/Makefile 2008-08-07 15:56:45.000000000 +0200
+++ samba-3.0.24/source/Makefile 2008-08-07 15:56:45.000000000 +0200
@@ -1015,9 +1015,9 @@
MY_PASS_OBJ = libsmb/smbdes.o lib/md4.o lib/arc4.o
-bin/smbpasswd: utils/avm_smbpasswd.o $(MY_PASS_OBJ)
+bin/smbpasswd: utils/owrt_smbpasswd.o $(MY_PASS_OBJ)
@echo Linking $@
- @$(CC) $(FLAGS) -o $@ utils/avm_smbpasswd.o $(MY_PASS_OBJ) \
+ @$(CC) $(FLAGS) -o $@ utils/owrt_smbpasswd.o $(MY_PASS_OBJ) \
-L$(TARGETFS)/lib
Index: samba-3.0.24/source/utils/owrt_smbpasswd.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ samba-3.0.24/source/utils/owrt_smbpasswd.c 2008-08-07 15:58:25.000000000 +0200
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) John Crispin <blogic@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 675
+ * Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "includes.h"
+#include <endian.h>
+
+void E_md4hash(const char *passwd, uchar p16[16])
+{
+ int len;
+ smb_ucs2_t wpwd[129];
+ int i;
+
+ len = strlen(passwd);
+ for (i = 0; i < len; i++) {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ wpwd[i] = (unsigned char)passwd[i];
+#else
+ wpwd[i] = (unsigned char)passwd[i] << 8;
+#endif
+ }
+ wpwd[i] = 0;
+
+ len = len * sizeof(int16);
+ mdfour(p16, (unsigned char *)wpwd, len);
+ ZERO_STRUCT(wpwd);
+}
+
+/* returns -1 if user is not present in /etc/passwd*/
+int find_uid_for_user(char *user)
+{
+ char t[256];
+ FILE *fp = fopen("/etc/passwd", "r");
+ int ret = -1;
+
+ if(!fp)
+ {
+ printf("failed to open /etc/passwd");
+ goto out;
+ }
+
+ while(!feof(fp))
+ {
+ if(fgets(t, 255, fp))
+ {
+ char *p1, *p2;
+ p1 = strchr(t, ':');
+ if(p1 && (p1 - t == strlen(user)) && (strncmp(t, user, strlen(user))) == 0)
+ {
+ p1 = strchr(t, ':');
+ if(!p1)
+ goto out;
+ p2 = strchr(++p1, ':');
+ if(!p2)
+ goto out;
+ p1 = strchr(++p2, ':');
+ if(!p1)
+ goto out;
+ *p1 = '\0';
+ ret = atoi(p2);
+ goto out;
+ }
+ }
+ }
+ printf("No valid user found in /etc/passwd\n");
+
+out:
+ if(fp)
+ fclose(fp);
+ return ret;
+}
+
+void insert_user_in_smbpasswd(char *user, char *line)
+{
+ char t[256];
+ FILE *fp = fopen("/etc/samba/smbpasswd", "r+");
+
+ if(!fp)
+ {
+ printf("failed to open /etc/samba/smbpasswd");
+ goto out;
+ }
+
+ while(!feof(fp))
+ {
+ if(fgets(t, 255, fp))
+ {
+ char *p;
+ p = strchr(t, ':');
+ if(p && (p - t == strlen(user)) && (strncmp(t, user, strlen(user))) == 0)
+ {
+ fseek(fp, -strlen(line), SEEK_CUR);
+ break;
+ }
+ }
+ }
+
+ fprintf(fp, line);
+
+out:
+ if(fp)
+ fclose(fp);
+}
+
+void delete_user_from_smbpasswd(char *user)
+{
+ char t[256];
+ FILE *fp = fopen("/etc/samba/smbpasswd", "r+");
+
+ if(!fp)
+ {
+ printf("failed to open /etc/samba/smbpasswd");
+ goto out;
+ }
+
+ while(!feof(fp))
+ {
+ if(fgets(t, 255, fp))
+ {
+ char *p;
+ p = strchr(t, ':');
+ if(p && (p - t == strlen(user)) && (strncmp(t, user, strlen(user))) == 0)
+ {
+ fpos_t r_pos, w_pos;
+ char t2[256];
+ fgetpos(fp, &r_pos);
+ w_pos = r_pos;
+ w_pos.__pos -= strlen(t);
+ while(fgets(t2, 256, fp))
+ {
+ fsetpos(fp, &w_pos);
+ fputs(t2, fp);
+ r_pos.__pos += strlen(t2);
+ w_pos.__pos += strlen(t2);
+ fsetpos(fp, &r_pos);
+ }
+ ftruncate(fileno(fp), w_pos.__pos);
+ break;
+ }
+ }
+ }
+
+out:
+ if(fp)
+ fclose(fp);
+}
+
+int main(int argc, char **argv)
+{
+ unsigned uid;
+ uchar new_nt_p16[NT_HASH_LEN];
+ int g;
+ int smbpasswd_present;
+ char smbpasswd_line[256];
+ char *s;
+
+ if(argc != 3)
+ {
+ printf("usage for openwrt_smbpasswd - \n\t%s USERNAME PASSWD\n\t%s -del USERNAME\n", argv[0], argv[0]);
+ exit(1);
+ }
+ if(strcmp(argv[1], "-del") == 0)
+ {
+ printf("deleting user %s\n", argv[2]);
+ delete_user_from_smbpasswd(argv[2]);
+ return 0;
+ }
+ uid = find_uid_for_user(argv[1]);
+ if(uid == -1)
+ exit(2);
+
+ E_md4hash(argv[2], new_nt_p16);
+ s = smbpasswd_line;
+ s += snprintf(s, 256 - (s - smbpasswd_line), "%s:%u:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:", argv[1], uid);
+ for(g = 0; g < 16; g++)
+ s += snprintf(s, 256 - (s - smbpasswd_line), "%02X", new_nt_p16[g]);
+ snprintf(s, 256 - (s - smbpasswd_line), ":[U ]:LCT-00000001:\n");
+
+ insert_user_in_smbpasswd(argv[1], smbpasswd_line);
+
+ return 0;
+}

View File

@ -0,0 +1,27 @@
Index: samba-3.0.24/source/include/config.h
===================================================================
--- samba-3.0.24.orig/source/include/config.h 2008-08-08 17:43:08.000000000 +0200
+++ samba-3.0.24/source/include/config.h 2008-08-08 17:44:02.000000000 +0200
@@ -821,7 +821,7 @@
#define HAVE_MKTIME 1
/* Whether mmap works */
-#define HAVE_MMAP 1
+/* #define HAVE_MMAP 1 */
/* Define to 1 if you have the <mntent.h> header file. */
#define HAVE_MNTENT_H 1
Index: samba-3.0.24/source/tdb/Makefile
===================================================================
--- samba-3.0.24.orig/source/tdb/Makefile 2008-08-08 17:42:47.000000000 +0200
+++ samba-3.0.24/source/tdb/Makefile 2008-08-08 17:44:15.000000000 +0200
@@ -2,7 +2,8 @@
# Makefile for tdb directory
#
-CFLAGS = -DSTANDALONE -DTDB_DEBUG -g -DHAVE_MMAP=1
+CFLAGS = -DSTANDALONE -DTDB_DEBUG -g
+#-DHAVE_MMAP=1
CC = gcc
ADMINPROGS = tdbdump tdbbackup

View File

@ -0,0 +1,15 @@
Index: samba-3.0.24/source/lib/ms_fnmatch.c
===================================================================
--- samba-3.0.24.orig/source/lib/ms_fnmatch.c 2008-08-11 11:08:03.000000000 +0200
+++ samba-3.0.24/source/lib/ms_fnmatch.c 2008-08-11 11:11:33.000000000 +0200
@@ -153,6 +153,10 @@
int ret, count, i;
struct max_n *max_n = NULL;
+ if (strcmp(pattern, "*") == 0) {
+ return 0;
+ }
+
if (strcmp(string, "..") == 0) {
string = ".";
}

View File

@ -0,0 +1,13 @@
Index: samba-3.0.24/source/lib/popt_common.c
===================================================================
--- samba-3.0.24.orig/source/lib/popt_common.c 2008-08-11 11:25:26.000000000 +0200
+++ samba-3.0.24/source/lib/popt_common.c 2008-08-11 11:26:03.000000000 +0200
@@ -54,7 +54,7 @@
else
pname++;
- pstr_sprintf(logfile, "%s/log.%s", arg, pname);
+ pstr_sprintf(logfile, "%s/log/%s.log", arg, pname);
lp_set_logfile(logfile);
}