makeBaseApp: Remove bad characters from user names

Also warns about some bad characters in record names, but only
the ones that are known to cause known bad behaviour.
This commit is contained in:
Andrew Johnson
2012-07-31 13:47:23 -05:00
parent 20c9fa2e8a
commit bdbada28a8
2 changed files with 42 additions and 34 deletions

View File

@@ -907,43 +907,52 @@ static void dbBreakBody(void)
pgphentry->userPvt = pnewbrkTable;
}
static void dbRecordHead(char *recordType,char *name, int visible)
static void dbRecordHead(char *recordType, char *name, int visible)
{
DBENTRY *pdbentry;
long status;
char *badch;
DBENTRY *pdbentry;
long status;
badch = strpbrk(name, " \"'.$");
if (badch) {
epicsPrintf("Bad character '%c' in record name \"%s\"\n",
*badch, name);
}
pdbentry = dbAllocEntry(pdbbase);
if(ellCount(&tempList))
yyerrorAbort("dbRecordHead: tempList not empty");
if (ellCount(&tempList))
yyerrorAbort("dbRecordHead: tempList not empty");
allocTemp(pdbentry);
status = dbFindRecordType(pdbentry,recordType);
if(status) {
epicsPrintf("Record \"%s\" is of unknown type \"%s\" - ",
status = dbFindRecordType(pdbentry, recordType);
if (status) {
epicsPrintf("Record \"%s\" is of unknown type \"%s\" - ",
name, recordType);
yyerrorAbort(NULL);
return;
yyerrorAbort(NULL);
return;
}
/*Duplicate records ok if the same type */
status = dbCreateRecord(pdbentry,name);
if(status==S_dbLib_recExists) {
if(strcmp(recordType,dbGetRecordTypeName(pdbentry))!=0) {
epicsPrintf("Record %s already defined with different type %s\n",
name, dbGetRecordTypeName(pdbentry));
if (status==S_dbLib_recExists) {
if (strcmp(recordType, dbGetRecordTypeName(pdbentry))!=0) {
epicsPrintf("Record \"%s\" already defined with different type "
"\"%s\"\n", name, dbGetRecordTypeName(pdbentry));
yyerror(NULL);
duplicate = TRUE;
return;
} else if (dbRecordsOnceOnly) {
epicsPrintf("Record \"%s\" already defined (dbRecordsOnceOnly is set)\n",
name);
yyerror(NULL);
duplicate = TRUE;
}
} else if(status) {
epicsPrintf("Can't create record \"%s\" of type \"%s\"\n",
name, recordType);
yyerrorAbort(NULL);
duplicate = TRUE;
return;
}
else if (dbRecordsOnceOnly) {
epicsPrintf("Record \"%s\" already defined (dbRecordsOnceOnly is "
"set)\n", name);
yyerror(NULL);
duplicate = TRUE;
}
}
if(visible) dbVisibleRecord(pdbentry);
else if (status) {
epicsPrintf("Can't create record \"%s\" of type \"%s\"\n",
name, recordType);
yyerrorAbort(NULL);
}
if (visible)
dbVisibleRecord(pdbentry);
}
static void dbRecordField(char *name,char *value)

View File

@@ -21,10 +21,10 @@ $app_top = cwd();
$bad_ident_chars = '[^0-9A-Za-z_]';
&GetUser; # Ensure we know who's in charge
&readReleaseFiles("configure/RELEASE", \%release, \@apps);
&expandRelease(\%release);
&get_commandline_opts; # Check command-line options
&GetUser; # Ensure we know who's in charge
#
# Declare two default callback routines for file copy plus two
@@ -164,7 +164,7 @@ exit 0; # END OF SCRIPT
# Get commandline options and check for validity
#
sub get_commandline_opts { #no args
getopts("a:b:dhilp:T:t:") or Cleanup(1);
getopts("a:b:dhilp:T:t:u:") or Cleanup(1);
# Options help
Cleanup(0) if $opt_h;
@@ -395,7 +395,7 @@ EOF
-d Enable debug messages
-i Specifies that ioc boot directories will be generated
-l List valid application types for this installation
If this is specified the other options are not used
If this is specified the other options are not used
-p app Set the application name for use with -i
If not specified, you will be prompted
-T top Set the template top directory (where the application templates are)
@@ -405,6 +405,7 @@ EOF
-t type Set the application type (-l for a list of valid types)
If not specified, type is taken from environment
If not found in environment, \"default\" is used
-u user Set username; overrides OS defaults
Environment:
EPICS_MBA_DEF_APP_TYPE Application type you want to use as default
@@ -419,10 +420,7 @@ EOF
}
sub GetUser {
# add to this list if new possibilities arise,
# currently it's UNIX and WIN32:
$user = $ENV{USER} || $ENV{USERNAME} || Win32::LoginName();
$user =~ s/\s+//g; # Bl**dy Windows stupidity...
$user = $opt_u || $ENV{USER} || $ENV{USERNAME} || Win32::LoginName();
unless ($user) {
print "Strange, I cannot figure out your user name!\n";
@@ -430,5 +428,6 @@ sub GetUser {
$user = <STDIN>;
chomp $user;
}
$user =~ tr/-a-zA-Z0-9_:;[]<>//cd; # Sanitize; these are the legal chars
die "No user name" unless $user;
}