summaryrefslogtreecommitdiffstats
path: root/source3/lib/genrand.c
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 /source3/lib/genrand.c
parent3e24c65101a7ec9c80892f9bc70c6e11a936385b (diff)
downloadsamba-09a5daf032b6e206e9371e63ca06ef60ef841b6a.tar.gz
samba-09a5daf032b6e206e9371e63ca06ef60ef841b6a.tar.xz
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)
Diffstat (limited to 'source3/lib/genrand.c')
-rw-r--r--source3/lib/genrand.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/source3/lib/genrand.c b/source3/lib/genrand.c
index 102eec63009..67fbbc7a06c 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;
+}