Skip to content

Commit

Permalink
[Server] Make sure loginid corresponds to the POSIX.1-2008 standard.
Browse files Browse the repository at this point in the history
Conflicts:
	src/XrdXrootd/XrdXrootdXeq.cc
  • Loading branch information
abh3 authored and simonmichal committed Jun 30, 2020
1 parent 925e2f5 commit 1f372b8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
20 changes: 20 additions & 0 deletions src/XrdOuc/XrdOucUtils.cc
Expand Up @@ -633,6 +633,26 @@ int XrdOucUtils::ReLink(const char *path, const char *target, mode_t mode)
return 0;
}

/******************************************************************************/
/* S a n i t i z e */
/******************************************************************************/

void XrdOucUtils::Sanitize(char *str, char subc)
{

// Sanitize string according to POSIX.1-2008 stanadard using only the
// Portable Filename Character Set: a-z A-Z 0-9 ._- with 1st char not being -
//
if (*str)
{if (*str == '-') *str = subc;
str++;
while(*str)
{if (!isalnum(*str) && index("_-.", *str) == 0) *str = subc;
str++;
}
}
}

/******************************************************************************/
/* s u b L o g f n */
/******************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions src/XrdOuc/XrdOucUtils.hh
Expand Up @@ -85,6 +85,8 @@ static int makePath(char *path, mode_t mode);
static char *parseHome(XrdSysError &eDest, XrdOucStream &Config, int &mode);

static int ReLink(const char *path, const char *target, mode_t mode=0);

static void Sanitize(char *instr, char subc='_');

static char *subLogfn(XrdSysError &eDest, const char *inst, char *logfn);

Expand Down
12 changes: 4 additions & 8 deletions src/XrdXrootd/XrdXrootdXeq.cc
Expand Up @@ -880,16 +880,12 @@ int XrdXrootdProtocol::do_Login()
//
SI->Bump(SI->LoginAT);

// Unmarshall the data
// Unmarshall the pid and construct username using the POSIX.1-2008 standard
//
pid = (int)ntohl(Request.login.pid);
for (i = 0; i < (int)sizeof(Request.login.username); i++)
{if (Request.login.username[i] == '\0' ||
Request.login.username[i] == ' ') break;
uname[i] = Request.login.username[i];
if (!isprint(uname[i])) uname[i] = '_';
}
uname[i] = '\0';
strncpy(uname, (const char *)Request.login.username, sizeof(uname)-2);
uname[sizeof(uname)-1] = 0;
XrdOucUtils::Sanitize(uname);

// Make sure the user is not already logged in
//
Expand Down

0 comments on commit 1f372b8

Please sign in to comment.