+#endif /* 0 */
+
+
+/* Printer ClearTxtUAM login */
+static int passwd_printer(start, stop, username, out)
+char *start, *stop, *username;
+struct papfile *out;
+{
+ struct passwd *pwd;
+#ifdef SHADOWPW
+ struct spwd *sp;
+#endif /* SHADOWPW */
+ char *data, *p, *q;
+ char password[PASSWDLEN + 1] = "\0";
+ static const char *loginok = "0\r";
+ int ulen;
+
+ data = (char *)malloc(stop - start + 1);
+ if (!data) {
+ LOG(log_info, logtype_uams,"Bad Login ClearTxtUAM: malloc");
+ return(-1);
+ }
+ strlcpy(data, start, stop - start + 1);
+
+ /* We are looking for the following format in data:
+ * (username) (password)
+ *
+ * Let's hope username doesn't contain ") ("!
+ */
+
+ /* Parse input for username in () */
+ if ((p = strchr(data, '(' )) == NULL) {
+ LOG(log_info, logtype_uams,"Bad Login ClearTxtUAM: username not found in string");
+ free(data);
+ return(-1);
+ }
+ p++;
+ if ((q = strstr(p, ") (" )) == NULL) {
+ LOG(log_info, logtype_uams,"Bad Login ClearTxtUAM: username not found in string");
+ free(data);
+ return(-1);
+ }
+ memcpy(username, p, MIN( UAM_USERNAMELEN, q - p ));
+
+ /* Parse input for password in next () */
+ p = q + 3;
+ if ((q = strrchr(p , ')' )) == NULL) {
+ LOG(log_info, logtype_uams,"Bad Login ClearTxtUAM: password not found in string");
+ free(data);
+ return(-1);
+ }
+ memcpy(password, p, MIN(PASSWDLEN, q - p) );
+
+ /* Done copying username and password, clean up */
+ free(data);
+
+ ulen = strlen(username);
+
+ if (( pwd = uam_getname(NULL, username, ulen)) == NULL ) {
+ LOG(log_info, logtype_uams, "Bad Login ClearTxtUAM: ( %s ) not found ",
+ username);
+ return(-1);
+ }
+
+ if (uam_checkuser(pwd) < 0) {
+ /* syslog of error happens in uam_checkuser */
+ return(-1);
+ }
+
+#ifdef SHADOWPW
+ if (( sp = getspnam( pwd->pw_name )) == NULL ) {
+ LOG(log_info, logtype_uams, "Bad Login ClearTxtUAM: no shadow passwd entry for %s",
+ username);
+ return(-1);
+ }
+ pwd->pw_passwd = sp->sp_pwdp;
+
+ if (sp && sp->sp_max != -1 && sp->sp_lstchg) {
+ time_t now = time(NULL) / (60*60*24);
+ int32_t expire_days = sp->sp_lstchg - now + sp->sp_max;
+ if ( expire_days < 0 ) {
+ LOG(log_info, logtype_uams, "Password for user %s expired", username);
+ return (-1);
+ }
+ }