From fff7b0b7ecaec9c34f702aa1b8dd8854ac7052ef Mon Sep 17 00:00:00 2001 From: srittau Date: Wed, 2 Jan 2002 21:14:10 +0000 Subject: [PATCH] =?utf8?q?Disallow=20leading=20and=20trailing=20spaces=20i?= =?utf8?q?n=20MSWINDOWS=20volumes.=20This=20is=20based=20on=20SourceForge?= =?utf8?q?=20patch=20#480115,=20submitted=20by=20Patrick=20Bihan-Faou=20(p?= =?utf8?q?bf)=20and=20crediting=20Herv=E9=20Masson=20and=20addresses=20SF?= =?utf8?q?=20bug=20#434934.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- etc/afpd/directory.c | 5 ++--- etc/afpd/file.c | 5 ++--- etc/afpd/filedir.c | 8 +++----- etc/afpd/volume.c | 26 +++++++++++++++++++++++++- etc/afpd/volume.h | 4 +++- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/etc/afpd/directory.c b/etc/afpd/directory.c index 9842001b..ea9c3224 100644 --- a/etc/afpd/directory.c +++ b/etc/afpd/directory.c @@ -1,5 +1,5 @@ /* - * $Id: directory.c,v 1.22 2001-12-29 08:22:23 jmarcus Exp $ + * $Id: directory.c,v 1.23 2002-01-02 21:14:10 srittau Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -1425,8 +1425,7 @@ int ibuflen, *rbuflen; } /* check for illegal bits */ - if ((vol->v_flags & AFPVOL_MSWINDOWS) && - strpbrk(path, MSWINDOWS_BADCHARS)) + if (!wincheck(vol, path)) return AFPERR_PARAM; upath = mtoupath(vol, path); diff --git a/etc/afpd/file.c b/etc/afpd/file.c index f7ab51f8..9a65b75f 100644 --- a/etc/afpd/file.c +++ b/etc/afpd/file.c @@ -1,5 +1,5 @@ /* - * $Id: file.c,v 1.31 2001-12-29 08:16:21 jmarcus Exp $ + * $Id: file.c,v 1.32 2002-01-02 21:14:10 srittau Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -409,8 +409,7 @@ int ibuflen, *rbuflen; return( AFPERR_NOOBJ ); } - if ((vol->v_flags & AFPVOL_MSWINDOWS) && - strpbrk(path, MSWINDOWS_BADCHARS)) + if (!wincheck(vol, path)) return AFPERR_PARAM; upath = mtoupath(vol, path); diff --git a/etc/afpd/filedir.c b/etc/afpd/filedir.c index 6fffd3d3..1e1c7c99 100644 --- a/etc/afpd/filedir.c +++ b/etc/afpd/filedir.c @@ -1,5 +1,5 @@ /* - * $Id: filedir.c,v 1.16 2001-12-03 05:03:38 jmarcus Exp $ + * $Id: filedir.c,v 1.17 2002-01-02 21:14:10 srittau Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -379,8 +379,7 @@ int ibuflen, *rbuflen; return AFP_OK; /* check for illegal characters */ - if ((vol->v_flags & AFPVOL_MSWINDOWS) && - strpbrk(ibuf, MSWINDOWS_BADCHARS)) + if (!wincheck(vol, ibuf)) return AFPERR_PARAM; newpath = obj->oldtmp; @@ -674,8 +673,7 @@ int ibuflen, *rbuflen; } /* check for illegal characters */ - if ((vol->v_flags & AFPVOL_MSWINDOWS) && - strpbrk(newname, MSWINDOWS_BADCHARS)) + if (!wincheck(vol, newname)) return AFPERR_PARAM; upath = mtoupath(vol, newname); diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index 36e52fb5..3bff6e88 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -1,5 +1,5 @@ /* - * $Id: volume.c,v 1.15 2001-12-03 05:03:38 jmarcus Exp $ + * $Id: volume.c,v 1.16 2002-01-02 21:14:10 srittau Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -1395,3 +1395,27 @@ int ibuflen, *rbuflen; ad_close(&ad, ADFLAGS_HF); return( AFP_OK ); } + + +int wincheck(struct vol *vol, const char *path) +{ + int len; + + if (!(vol->v_flags & AFPVOL_MSWINDOWS)) + return 1; + + /* empty paths are not allowed */ + if ((len = strlen(path)) == 0) + return 0; + + /* leading or trailing whitespaces are not allowed */ + if ((*path == ' ') || (path[len-1] == ' ')) + return 0; + + /* certain characters are not allowed */ + if (strpbrk(path, MSWINDOWS_BADCHARS)) + return 0; + + /* everything else is okay */ + return 1; +} diff --git a/etc/afpd/volume.h b/etc/afpd/volume.h index dba485b3..eb78adac 100644 --- a/etc/afpd/volume.h +++ b/etc/afpd/volume.h @@ -1,5 +1,5 @@ /* - * $Id: volume.h,v 1.8 2001-12-03 05:03:38 jmarcus Exp $ + * $Id: volume.h,v 1.9 2002-01-02 21:14:10 srittau Exp $ * * Copyright (c) 1990,1994 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -105,6 +105,8 @@ this is going away. */ #define MSWINDOWS_BADCHARS "\\/<>*?|\"" #define MSWINDOWS_CODEPAGE "maccode.iso8859-1" +int wincheck(struct vol *vol, const char *path); + #define AFPVOLSIG_FLAT 0x0001 /* flat fs */ #define AFPVOLSIG_FIX 0x0002 /* fixed ids */ #define AFPVOLSIG_VAR 0x0003 /* variable ids */ -- 2.39.2