* true - OK
* false - bad name
* errors:
- * EINVAL Invalid name characters or sequences
+ * EINVAL Invalid name
+ * EILSEQ Invalid name character sequence (acceptable with --badname)
* EOVERFLOW Name longer than maximum size
*/
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
+#include <string.h>
#include <unistd.h>
#include "defines.h"
#include "chkname.h"
+#include "string/ctype/strchrisascii/strchriscntrl.h"
#include "string/ctype/strisascii/strisdigit.h"
#include "string/strcmp/streq.h"
+#include "string/strcmp/strcaseeq.h"
#ifndef LOGIN_NAME_MAX
static bool
is_valid_name(const char *name)
{
+ if (streq(name, "")
+ || streq(name, ".")
+ || streq(name, "..")
+ || strspn(name, "-")
+ || strpbrk(name, " \"#',/:;")
+ || strchriscntrl(name)
+ || strisdigit(name))
+ {
+ errno = EINVAL;
+ return false;
+ }
+
if (allow_bad_names) {
return true;
}
*
* as a non-POSIX, extension, allow "$" as the last char for
* sake of Samba 3.x "add machine script"
- *
- * Also do not allow fully numeric names or just "." or "..".
*/
- if (strisdigit(name)) {
- errno = EINVAL;
- return false;
- }
-
- if (streq(name, "") ||
- streq(name, ".") ||
- streq(name, "..") ||
- !((*name >= 'a' && *name <= 'z') ||
+ if (!((*name >= 'a' && *name <= 'z') ||
(*name >= 'A' && *name <= 'Z') ||
(*name >= '0' && *name <= '9') ||
*name == '_' ||
*name == '.'))
{
- errno = EINVAL;
+ errno = EILSEQ;
return false;
}
streq(name, "$")
))
{
- errno = EINVAL;
+ errno = EILSEQ;
return false;
}
}
/* Check if this is a valid user name */
if (!is_valid_user_name(name)) {
- if (errno == EINVAL) {
+ if (errno == EILSEQ) {
fprintf(stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, name);
user_name = argv[optind];
if (!is_valid_user_name(user_name)) {
- if (errno == EINVAL) {
+ if (errno == EILSEQ) {
fprintf(stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, user_name);