Some contributions

Martin Sheppard martin.sheppard at hsn.csiro.au
Mon Sep 25 04:22:00 GMT 2000


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.
-------------- next part --------------
/*
 * 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;

}
-------------- next part --------------
#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;
	}
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: add_smb_printer
Type: application/octet-stream
Size: 2849 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20000925/9ad83a8a/add_smb_printer.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: samba-2.0.6-pam_tally.patch
Type: application/octet-stream
Size: 1516 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20000925/9ad83a8a/samba-2.0.6-pam_tally.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: samba-2.0.7-lmhosts-wins.patch
Type: application/octet-stream
Size: 957 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20000925/9ad83a8a/samba-2.0.7-lmhosts-wins.obj


More information about the samba-technical mailing list