* can't be a palindrome - like `R A D A R' or `M A D A M'
*/
-static int palindrome(const char *old, const char *newval)
+static int palindrome(const char *newval)
{
int i, j;
* a nice mix of characters.
*/
-static int simple(const char *old, const char *newval)
+static int simple(const char *newval)
{
int digits = 0;
int uppers = 0;
int lowers = 0;
int others = 0;
+ int c;
int size;
int i;
- for (i = 0; newval[i]; i++) {
- if (isdigit(newval[i]))
- digits++;
- else if (isupper(newval[i]))
- uppers++;
- else if (islower(newval[i]))
- lowers++;
+ for (i = 0; (c = *newval++) != 0; i++) {
+ if (isdigit(c))
+ digits = c;
+ else if (isupper(c))
+ uppers = c;
+ else if (islower(c))
+ lowers = c;
else
- others++;
+ others = c;
}
/*
return string;
}
-static char *password_check(const char *old, const char *newval, const struct passwd *pwdp)
+static const char *
+password_check(const char *old, const char *newval, const struct passwd *pwdp)
{
- char *msg = NULL;
- char *oldmono, *newmono, *wrapped;
+ const char *msg;
+ char *newmono, *wrapped;
+ int lenwrap;
if (strcmp(newval, old) == 0)
return "no change";
+ if (simple(newval))
+ return "too simple";
- newmono = str_lower(xstrdup(newval));
- oldmono = str_lower(xstrdup(old));
- wrapped = (char *) xmalloc(strlen(oldmono) * 2 + 1);
- strcpy(wrapped, oldmono);
- strcat(wrapped, oldmono);
+ msg = NULL;
+ newmono = str_lower(bb_xstrdup(newval));
+ lenwrap = strlen(old);
+ wrapped = (char *) xmalloc(lenwrap * 2 + 1);
+ str_lower(strcpy(wrapped, old));
- if (palindrome(oldmono, newmono))
+ if (palindrome(newmono))
msg = "a palindrome";
- if (!msg && strcmp(oldmono, newmono) == 0)
+ else if (strcmp(wrapped, newmono) == 0)
msg = "case changes only";
- if (!msg && similiar(oldmono, newmono))
+ else if (similiar(wrapped, newmono))
msg = "too similiar";
- if (!msg && simple(old, newval))
- msg = "too simple";
-
- if (!msg && strstr(wrapped, newmono))
- msg = "rotated";
+ else {
+ safe_strncpy(wrapped + lenwrap, wrapped, lenwrap + 1);
+ if (strstr(wrapped, newmono))
+ msg = "rotated";
+ }
bzero(newmono, strlen(newmono));
- bzero(oldmono, strlen(oldmono));
- bzero(wrapped, strlen(wrapped));
+ bzero(wrapped, lenwrap * 2);
free(newmono);
- free(oldmono);
free(wrapped);
return msg;
}
-static char *obscure_msg(const char *old, const char *newval, const struct passwd *pwdp)
+static const char *
+obscure_msg(const char *old, const char *newval, const struct passwd *pwdp)
{
int maxlen, oldlen, newlen;
- char *new1, *old1, *msg;
+ char *new1, *old1;
+ const char *msg;
oldlen = strlen(old);
newlen = strlen(newval);
if (oldlen <= maxlen && newlen <= maxlen)
return NULL;
- new1 = (char *) xstrdup(newval);
- old1 = (char *) xstrdup(old);
+ new1 = (char *) bb_xstrdup(newval);
+ old1 = (char *) bb_xstrdup(old);
if (newlen > maxlen)
new1[maxlen] = '\0';
if (oldlen > maxlen)
extern int obscure(const char *old, const char *newval, const struct passwd *pwdp)
{
- char *msg = obscure_msg(old, newval, pwdp);
+ const char *msg = obscure_msg(old, newval, pwdp);
/* if (msg) { */
if (msg != NULL) {