summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-04-12 07:00:08 +0000
committerJeremy Allison <jra@samba.org>2001-04-12 07:00:08 +0000
commit09a5daf032b6e206e9371e63ca06ef60ef841b6a (patch)
tree6fd44623d74d63d1898f5ba5b5e5ad855f0b8e23
parent3e24c65101a7ec9c80892f9bc70c6e11a936385b (diff)
downloadsamba-09a5daf032b6e206e9371e63ca06ef60ef841b6a.tar.gz
samba-09a5daf032b6e206e9371e63ca06ef60ef841b6a.tar.bz2
samba-09a5daf032b6e206e9371e63ca06ef60ef841b6a.zip
Changed lp_add/delete/enum scripts to use lockdir if spool dir doesn't
exist for printer. Rather than using pid for suffix, use a 16 byte random string. Created generate_random_str() function in genrand.c. Still needs more testing but this is the way to go. Jeremy. (This used to be commit 71a330987f990007beb16f00fc468107361b5e9d)
-rw-r--r--source3/include/proto.h4
-rw-r--r--source3/lib/genrand.c24
-rw-r--r--source3/rpc_server/srv_spoolss_nt.c22
3 files changed, 35 insertions, 15 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 57255d403c..78fae3705a 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -126,6 +126,7 @@ int sys_fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
/*The following definitions come from lib/genrand.c */
void generate_random_buffer( unsigned char *out, int len, BOOL re_seed);
+char *generate_random_str(size_t len);
/*The following definitions come from lib/getsmbpass.c */
@@ -1882,9 +1883,8 @@ BOOL pdb_generate_sam_sid(void);
/*The following definitions come from passdb/pampass.c */
-BOOL PAM_session(BOOL instance, const connection_struct *conn, char *tty);
+BOOL pam_session(BOOL flag, const connection_struct *conn, char *tty);
BOOL pam_passcheck(char * user, char * password);
-BOOL pam_passcheck( char * user, char * password );
/*The following definitions come from passdb/pass_check.c */
diff --git a/source3/lib/genrand.c b/source3/lib/genrand.c
index 102eec6300..67fbbc7a06 100644
--- a/source3/lib/genrand.c
+++ b/source3/lib/genrand.c
@@ -227,3 +227,27 @@ void generate_random_buffer( unsigned char *out, int len, BOOL re_seed)
len -= copy_len;
}
}
+
+/*******************************************************************
+ Use the random number generator to generate a random string.
+********************************************************************/
+
+static char c_list[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+ _-#.,";
+
+char *generate_random_str(size_t len)
+{
+ static unsigned char retstr[256];
+ size_t i;
+
+ memset(retstr, '\0', sizeof(retstr));
+
+ if (len > sizeof(retstr)-1)
+ len = sizeof(retstr) -1;
+ generate_random_buffer( retstr, len, False);
+ for (i = 0; i < len; i++)
+ retstr[i] = c_list[ retstr[i] % sizeof(c_list) ];
+
+ retstr[i] = '\0';
+
+ return retstr;
+}
diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c
index c75af92902..f91168d3e4 100644
--- a/source3/rpc_server/srv_spoolss_nt.c
+++ b/source3/rpc_server/srv_spoolss_nt.c
@@ -285,7 +285,6 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd)
if (*lp_deleteprinter_cmd()) {
- pid_t local_pid = sys_getpid();
char *cmd = lp_deleteprinter_cmd();
char *path;
pstring tmp_file;
@@ -296,13 +295,13 @@ static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd)
if (*lp_pathname(lp_servicenumber(PRINTERS_NAME)))
path = lp_pathname(lp_servicenumber(PRINTERS_NAME));
else
- path = tmpdir();
+ path = lp_lockdir();
/* Printer->dev.handlename equals portname equals sharename */
slprintf(command, sizeof(command)-1, "%s \"%s\"", cmd,
Printer->dev.handlename);
dos_to_unix(command, True); /* Convert printername to unix-codepage */
- slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid);
+ slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16));
unlink(tmp_file);
DEBUG(10,("Running [%s > %s]\n", command,tmp_file));
@@ -4133,7 +4132,6 @@ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
****************************************************************************/
static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer)
{
- pid_t local_pid = sys_getpid();
char *cmd = lp_addprinter_cmd();
char *path;
char **qlines;
@@ -4146,15 +4144,15 @@ static BOOL add_printer_hook(NT_PRINTER_INFO_LEVEL *printer)
if (*lp_pathname(lp_servicenumber(PRINTERS_NAME)))
path = lp_pathname(lp_servicenumber(PRINTERS_NAME));
else
- path = tmpdir();
+ path = lp_lockdir();
/* build driver path... only 9X architecture is needed for legacy reasons */
slprintf(driverlocation, sizeof(driverlocation)-1, "\\\\%s\\print$\\WIN40\\0",
global_myname);
/* change \ to \\ for the shell */
all_string_sub(driverlocation,"\\","\\\\",sizeof(pstring));
-
- slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid);
+
+ slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16));
slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
cmd, printer->info_2->printername, printer->info_2->sharename,
printer->info_2->portname, printer->info_2->drivername,
@@ -5418,7 +5416,6 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need
int i=0;
if (*lp_enumports_cmd()) {
- pid_t local_pid = sys_getpid();
char *cmd = lp_enumports_cmd();
char *path;
char **qlines;
@@ -5430,9 +5427,9 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need
if (*lp_pathname(lp_servicenumber(PRINTERS_NAME)))
path = lp_pathname(lp_servicenumber(PRINTERS_NAME));
else
- path = tmpdir();
+ path = lp_lockdir();
- slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid);
+ slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16));
slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1);
unlink(tmp_file);
@@ -5516,7 +5513,6 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need
int i=0;
if (*lp_enumports_cmd()) {
- pid_t local_pid = sys_getpid();
char *cmd = lp_enumports_cmd();
char *path;
char **qlines;
@@ -5528,9 +5524,9 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need
if (*lp_pathname(lp_servicenumber(PRINTERS_NAME)))
path = lp_pathname(lp_servicenumber(PRINTERS_NAME));
else
- path = tmpdir();
+ path = lp_lockdir();
- slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%d", path, local_pid);
+ slprintf(tmp_file, sizeof(tmp_file)-1, "%s/smbcmd.%s", path, generate_random_str(16));
slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 2);
unlink(tmp_file);