[prev in list] [next in list] [prev in thread] [next in thread] 

List:       samba-technical
Subject:    Some contributions
From:       Martin Sheppard <martin.sheppard () hsn ! csiro ! au>
Date:       2000-09-25 4:34:00
[Download RAW message or body]

I have a made a few modifications to Samba and written some Auxiliary 
programs to work with Samba that I thought some people might be interested 
in. Feel free to incorporate them into Samba, or do whatever else you like 
with them.

samba-2.0.6-pam_tally.patch:
We need to be able to use pam_tally with samba so that we can disable 
logins after a certain number of failed attempts. The trouble with Samba is 
that it needs to try many times with different case combinations. This 
patch makes samba attempt to verify the password once with the "smbtal" pam 
service and then it tries however many times it needs on the "samba" 
service. This allows you to set up pam_tally to ignore the failed attempts 
on the "samba" service and still catch failed attempts.

samba-2.0.7-lmhosts-wins.patch:
This patches nmbd so that it serves entries in the lmhosts file from a WINS 
server. I found this useful when we were migrating from one set of netbios 
names to another. I wanted to have the machine respond to queries for both 
names during the transition, but the version of SAMBA running on one of the 
servers didn't support netbios aliases. This doesn't seem work with windows 
machines, presumably because they don't like being called a different name 
to what they think they are. I'm not sure that this is the right way to 
implement this feature, but it worked for me.

makeprinterdef.c:
This is a Windows Visual C++ program to extract information about a printer 
driver from the registry and copy it to a printer$ share and create the 
correct entry for printers.def. This is much easier than other methods I 
have seen used to get automatic printer driver downloads working.

rename.cpp;
This is a Windows Visual C++ program to edit the registry to change the 
netbios name of a Win9x machine. I find this useful to keep Netbios names 
in sync with DNS names. I have a unix script that creates the Windows login 
script. It puts in a call to this program to change the netbios name to 
whatever the DNS name is. It was also very useful when we had to change the 
netbios naming scheme, as it saved a tricp to each computer.

add_smb_printer:
A script for Solaris that can be used to create or modify a print queue 
that prints to an SMB printer.

I can provide executables and/or project files for the Visual c++ programs 
if anyone wants them. I suppose that it wouldn't be too difficult to port 
them to gcc for Windows if people feel this is important. I know that some 
of the code isn't very clean at the moment. If any of this is going to be 
incorporated into Samba then I am happy to spend some time cleaning it up.

Cheers,

Martin.
["makeprinterdef.c" (text/plain)]

/*
 * TODO:
 * 
 * - DLL version checking
 * - handle subdriectories
 * - tidy up code 
 *
 */

#include <stdio.h>
#include <windows.h>
#include <io.h>
#include <fcntl.h>

void printkey(HKEY hkey, char *key)
{
	DWORD slen=500;
	char text[500];
	DWORD type;
	
	if (RegQueryValueEx(hkey,
		key,
		NULL,
		&type,
		(LPBYTE) &text,
		(LPDWORD) &slen) != ERROR_SUCCESS)
			return;

	printf("%s", text);	
}

int main(int argc, char **argv)
{
	char *printer;

	DWORD dw;
	DWORD type;
	char printerKey[500];
	HKEY hkPrinter;
	DWORD slen=5000;
	char text[5000];
	char filename[500];
	char filename2[500];
	DWORD i;

	if (argc != 3) {
		printf("Usage: %s Driver_Name Printer_Share\n", argv[0]);
		return 1;
	};
	
	printer = argv[1];

	_setmode( _fileno( stdout ), _O_BINARY ); // Don't do LF -> CR/LF translation
	
	sprintf(printerKey,"System\\CurrentControlSet\\Control\\Print\\Environments\\Windows \
4.0\\Drivers\\%s", printer);

	if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
		printerKey,
		0, REG_NONE, REG_OPTION_NON_VOLATILE,
		KEY_READ, NULL, &hkPrinter, &dw) != ERROR_SUCCESS)
		return 1;

	printf("%s", printer);
	printf(":");
	printkey(hkPrinter, "Configuration File"); 
	/* should possibly be Driver, but in all cases I have seen Driver and Configureation \
  file are identical */
	printf(":");
	printkey(hkPrinter, "Data File");
	printf(":");
	printkey(hkPrinter, "Help File");
	printf(":");
	printkey(hkPrinter, "Monitor");
	printf(":");
	printkey(hkPrinter, "Datatype");
	printf(":");

	if (RegQueryValueEx(hkPrinter,
		"Dependent Files",
		NULL,
		&type,
		(LPBYTE) &text,
		(LPDWORD) &slen) != ERROR_SUCCESS)
	{
		fprintf(stderr, "error reading files: %i\n", slen);
		return 1;
	}

	for (i = 0; i < slen-2; i++)
	{
		if (text[i] == 0 || i == 0) {
			printf(i==0?"%s":",%s", &text[i==0?0:i+1]);	
			sprintf(filename, "c:\\windows\\system\\%s", &text[i==0?0:i+1]);
			sprintf(filename2,"%s\\%s", argv[2], &text[i==0?0:i+1]);
			CopyFile(filename, filename2, TRUE);
		}
	}
	
	printf("\n");
	
	return 0;

}


["rename.cpp" (text/plain)]

#include <stdio.h>
#include <windows.h>

char *getkey(HKEY base, char *path, char *key)
{
	HKEY hkey;
	DWORD dw;

	int error = RegCreateKeyEx(base, path,
		0, REG_NONE, REG_OPTION_NON_VOLATILE,
		KEY_READ, NULL, &hkey, &dw);
	if (error != ERROR_SUCCESS)
	{
		printf("error1: %i\n", error);
		return NULL;
	}

	DWORD slen=500;
	char text[500];
	DWORD type;
	
	error = RegQueryValueEx(hkey,
		key,
		NULL,
		&type,
		(LPBYTE) &text,
		(LPDWORD) &slen);
	if (error != ERROR_SUCCESS)
	{
		printf("error2: %i\n", error);
		return NULL;
	}

	return strdup(text);
}

bool setkey(HKEY base, char *path, char *key, char *value)
{
	HKEY hkey;
	DWORD dw;

	if (RegCreateKeyEx(base, path,
		0, REG_NONE, REG_OPTION_NON_VOLATILE,
		KEY_READ, NULL, &hkey, &dw) != ERROR_SUCCESS)
		return FALSE;

	DWORD slen=500;
	
	if (RegSetValueEx(hkey,	
		key,
		NULL,
		REG_SZ,
		(LPBYTE) value,
		strlen(value)+1) != ERROR_SUCCESS)
			return FALSE;

	return TRUE;
}

int main(int argc, char **argv)
{
	bool changed = FALSE;
	char *oldname;

	if (argc != 2) {
		printf("ERROR: Incorrect parameters\n");
		return 1;
	}

	oldname = getkey(HKEY_LOCAL_MACHINE, 
			         "System\\CurrentControlSet\\Control\\ComputerName\\ComputerName",
					 "ComputerName");
	if (strcmp(oldname,argv[1]) != 0) {
		printf("Old name was (ComputerName): %s\n", oldname);
		setkey(HKEY_LOCAL_MACHINE, 
			   "System\\CurrentControlSet\\Control\\ComputerName\\ComputerName",
			   "ComputerName",
			   argv[1]);
		changed = TRUE;
	}

	oldname = getkey(HKEY_LOCAL_MACHINE, 
	                 "System\\CurrentControlSet\\Services\\VxD\\VNETSUP",
	    			 "ComputerName");
	if (strcmp(oldname,argv[1]) != 0) {
		printf("Old name was (VNETSUP): %s\n", oldname);
		setkey(HKEY_LOCAL_MACHINE, 
			   "System\\CurrentControlSet\\Services\\VxD\\VNETSUP",
			   "ComputerName",
			   argv[1]);
		changed = TRUE;
	}

	if (changed) {
		return 1;
	} else {
		return 0;
	}
}


["add_smb_printer" (application/octet-stream)]
["samba-2.0.6-pam_tally.patch" (application/octet-stream)]

--- samba-2.0.6/source/passdb/pass_check.c.orig	Thu Jan 27 11:16:15 2000
+++ samba-2.0.6/source/passdb/pass_check.c	Thu Jan 27 11:23:52 2000
@@ -95,7 +95,7 @@ static struct pam_conv PAM_conversation 
 };
 
 
-static BOOL pam_auth(char *user,char *password)
+static BOOL pam_auth(char *service,char *user,char *password)
 {
   pam_handle_t *pamh;
   int pam_error;
@@ -112,7 +112,7 @@ static BOOL pam_auth(char *user,char *pa
    }
   PAM_password = password;
   PAM_username = user;
-  pam_error = pam_start("samba", user, &PAM_conversation, &pamh);
+  pam_error = pam_start(service, user, &PAM_conversation, &pamh);
   PAM_BAIL;
 /* Setting PAM_SILENT stops generation of error messages to syslog
  * to enable debugging on Red Hat Linux set:
@@ -686,7 +686,7 @@ static BOOL password_check(char *passwor
 	   if (pam_auth(user,password)) return(True);
 	   Hence we make a direct return to avoid a second chance!!!
 	*/
-	return (pam_auth(this_user,password));
+	return (pam_auth("samba",this_user,password));
 #endif /* WITH_PAM */
 	
 #ifdef WITH_AFS
@@ -881,6 +881,15 @@ BOOL pass_check(char *user,char *passwor
 			return(True);
 		}
 	}
+
+#ifdef WITH_PAM
+	/* try it once as it came to us on a different service, 
+	   so that pam_tally can use this to cound unsuccessful logins.
+	   We then ignore the result and use the samba service for real
+	   authentication */
+
+        pam_auth("smbtal",this_user,password);
+#endif /* WITH_PAM */
 
 	/* try it as it came to us */
 	if (password_check(password)) {

["samba-2.0.7-lmhosts-wins.patch" (application/octet-stream)]

--- samba-2.0.7/source/nmbd/nmbd_lmhosts.c.orig	Thu Aug 24 16:37:35 2000
+++ samba-2.0.7/source/nmbd/nmbd_lmhosts.c	Thu Aug 24 16:40:43 2000
@@ -49,12 +49,17 @@
     struct subnet_record *subrec = NULL;
     enum name_source source = LMHOSTS_NAME;
 
+    /* add hosts to the wins server database if possible */
+    subrec = wins_server_subnet;
+
     /* We find a relevent subnet to put this entry on, then add it. */
     /* Go through all the broadcast subnets and see if the mask matches. */
-    for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
-    {
-      if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip))
-        break;
+    if(subrec == NULL) {
+      for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
+      {
+	if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip))
+	  break;
+      }
     }
   
     /* If none match add the name to the remote_broadcast_subnet. */


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic