summaryrefslogtreecommitdiff
path: root/usr.sbin/user/user.c
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2007-03-02 04:23:36 +0000
committerRay Lai <ray@cvs.openbsd.org>2007-03-02 04:23:36 +0000
commit28c653b086bdcef89d97eb759e9c1d6471f5e051 (patch)
treec5c9f42b5111803de45b447a0df580934b83ae5f /usr.sbin/user/user.c
parent0c01f8adb1cf5503abe450badfc85a7f81674cd6 (diff)
Replace regex(3) routines with simple string searching and comparison
routines. OK millert@.
Diffstat (limited to 'usr.sbin/user/user.c')
-rw-r--r--usr.sbin/user/user.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/usr.sbin/user/user.c b/usr.sbin/user/user.c
index c10e1dc03bf..4e65d51db46 100644
--- a/usr.sbin/user/user.c
+++ b/usr.sbin/user/user.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: user.c,v 1.68 2007/01/12 13:25:12 otto Exp $ */
+/* $OpenBSD: user.c,v 1.69 2007/03/02 04:23:35 ray Exp $ */
/* $NetBSD: user.c,v 1.69 2003/04/14 17:40:07 agc Exp $ */
/*
@@ -45,7 +45,6 @@
#endif
#include <paths.h>
#include <pwd.h>
-#include <regex.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -866,15 +865,17 @@ typedef struct passwd_type_t {
const char *type; /* optional type descriptor */
int desc_length; /* length of type descriptor */
int length; /* length of password */
- const char *regex; /* regexp to output the password */
- int re_sub; /* subscript of regexp to use */
} passwd_type_t;
+#define BLF "$2a"
+#define MD5 "$1"
+#define DES ""
+
static passwd_type_t passwd_types[] = {
- { "$2a", 3, 54, "\\$[^$]+\\$[^$]+\\$(.*)", 1 }, /* Blowfish */
- { "$1", 2, 34, NULL, 0 }, /* MD5 */
- { "", 0, DES_Len,NULL, 0 }, /* standard DES */
- { NULL, -1, -1, NULL, 0 } /* none - terminate search */
+ { BLF, 3, 54 }, /* Blowfish */
+ { MD5, 2, 34 }, /* MD5 */
+ { DES, 0, DES_Len }, /* standard DES */
+ { NULL, -1, -1 } /* none - terminate search */
};
/* return non-zero if it's a valid password - check length for cipher type */
@@ -882,20 +883,20 @@ static int
valid_password_length(char *newpasswd)
{
passwd_type_t *pwtp;
- regmatch_t matchv[10];
- regex_t r;
for (pwtp = passwd_types ; pwtp->desc_length >= 0 ; pwtp++) {
if (strncmp(newpasswd, pwtp->type, pwtp->desc_length) == 0) {
- if (pwtp->regex == NULL) {
+ char *p;
+
+ if (strcmp(pwtp->type, BLF) != 0) {
return strlen(newpasswd) == pwtp->length;
}
- (void) regcomp(&r, pwtp->regex, REG_EXTENDED);
- if (regexec(&r, newpasswd, 10, matchv, 0) == 0) {
- regfree(&r);
- return (int)(matchv[pwtp->re_sub].rm_eo - matchv[pwtp->re_sub].rm_so + 1) == pwtp->length;
- }
- regfree(&r);
+ /* Skip first three `$'. */
+ if ((p = strchr(newpasswd, '$')) == NULL ||
+ *(++p) == '$' || (p = strchr(p, '$')) == NULL ||
+ *(++p) == '$' || (p = strchr(p, '$')) == NULL)
+ continue;
+ return (strlen(p) - 1);
}
}
return 0;
@@ -1271,21 +1272,16 @@ rm_user_from_groups(char *login_name)
static int
is_local(char *name, const char *file)
{
- regmatch_t matchv[10];
- regex_t r;
FILE *fp;
char buf[LINE_MAX];
- char re[LINE_MAX];
+ size_t len;
int ret;
int cc;
- (void) snprintf(re, sizeof(re), "^%s:", name);
- if (regcomp(&r, re, REG_EXTENDED) != 0) {
- errx(EXIT_FAILURE, "can't compile regular expression `%s'", re);
- }
if ((fp = fopen(file, "r")) == NULL) {
err(EXIT_FAILURE, "can't open `%s'", file);
}
+ len = strlen(name);
for (ret = 0 ; fgets(buf, sizeof(buf), fp) != NULL ; ) {
cc = strlen(buf);
if (buf[cc - 1] != '\n' && !feof(fp)) {
@@ -1295,7 +1291,7 @@ is_local(char *name, const char *file)
file, buf, cc);
continue;
}
- if (regexec(&r, buf, 10, matchv, 0) == 0) {
+ if (strncmp(buf, name, len) == 0 && buf[len] == ':') {
ret = 1;
break;
}