summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2005-12-11 05:06:35 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:05:48 -0500
commit2c0114d2116488de195ca99a0f1d46d79a7bdbd6 (patch)
tree3ff4c74030bb2c4c3ed8f98ea7f60a09784bc4bd /source3
parent7cd1af4a639b0852df25fe936519c9613b342dca (diff)
downloadsamba-2c0114d2116488de195ca99a0f1d46d79a7bdbd6.tar.gz
samba-2c0114d2116488de195ca99a0f1d46d79a7bdbd6.tar.bz2
samba-2c0114d2116488de195ca99a0f1d46d79a7bdbd6.zip
r12177: last of outstanding patches in my queue to deal with MMC.
Validate the share name and fail when trying to creating a share with bad characters. (This used to be commit 174fe494f9cbec3386ed687007e137fa7064373d)
Diffstat (limited to 'source3')
-rw-r--r--source3/rpc_server/srv_srvsvc_nt.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/source3/rpc_server/srv_srvsvc_nt.c b/source3/rpc_server/srv_srvsvc_nt.c
index 0e7ded39f5..1d574d82fb 100644
--- a/source3/rpc_server/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srv_srvsvc_nt.c
@@ -29,6 +29,26 @@ extern struct generic_mapping file_generic_mapping;
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_SRV
+#define INVALID_SHARENAME_CHARS "<>*?|"
+
+/********************************************************************
+ Check a string for any occurrences of a specified list of invalid
+ characters.
+********************************************************************/
+
+static BOOL validate_net_name( const char *name, const char *invalid_chars, int max_len )
+{
+ int i;
+
+ for ( i=0; i<max_len && name[i]; i++ ) {
+ /* fail if strchr_m() finds one of the invalid characters */
+ if ( name[i] && strchr_m( invalid_chars, name[i] ) )
+ return False;
+ }
+
+ return True;
+}
+
/*******************************************************************
Utility function to get the 'type' of a share from an snum.
********************************************************************/
@@ -1760,6 +1780,13 @@ WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_S
return WERR_UNKNOWN_LEVEL;
}
+ /* check for invalid share names */
+
+ if ( !validate_net_name( share_name, INVALID_SHARENAME_CHARS, sizeof(share_name) ) ) {
+ DEBUG(5,("_srv_net_name_validate: Bad sharename \"%s\"\n", share_name));
+ return WERR_INVALID_NAME;
+ }
+
if ( strequal(share_name,"IPC$")
|| ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") )
|| strequal(share_name,"global") )
@@ -2276,17 +2303,26 @@ WERROR _srv_net_disk_enum(pipes_struct *p, SRV_Q_NET_DISK_ENUM *q_u, SRV_R_NET_D
return r_u->status;
}
+/********************************************************************
+********************************************************************/
+
WERROR _srv_net_name_validate(pipes_struct *p, SRV_Q_NET_NAME_VALIDATE *q_u, SRV_R_NET_NAME_VALIDATE *r_u)
{
- fstring share_name;
+ fstring sharename;
switch ( q_u->type ) {
case 0x9:
- /* check if share name is ok.
- TODO: check for invalid characters in name? */
-
- unistr2_to_ascii(share_name, &q_u->uni_name, sizeof(share_name));
+ /* Run the name through alpha_strcpy() to remove any unsafe
+ shell characters. Compare the copied string with the original
+ and fail if the strings don't match */
+
+ unistr2_to_ascii(sharename, &q_u->uni_name, sizeof(sharename));
+ if ( !validate_net_name( sharename, INVALID_SHARENAME_CHARS, sizeof(sharename) ) ) {
+ DEBUG(5,("_srv_net_name_validate: Bad sharename \"%s\"\n", sharename));
+ return WERR_INVALID_NAME;
+ }
break;
+
default:
return WERR_UNKNOWN_LEVEL;
}