-int update_authfile(const char *fn, const char *tokenid, const char *id,
- const char *password, const char *nonce,
- const unsigned char *secret, const int secsize,
- const unsigned char *payload, const int paysize)
+static char *template = "~/.pam_cr/auth";
+
+void authfile_template(char *str)
+{
+ template = str;
+}
+
+static int path_size(const char *tokenid, const char *userid)
+{
+ const char *usub;
+ char *p, *q;
+ struct passwd *pw;
+
+ if ((p = strchr(template, '~')) != strrchr(template, '~')) return 0;
+ if ((q = strchr(template, '?')) != strrchr(template, '?')) return 0;
+ if (p && !userid) return 0;
+ if (q && !tokenid) return 0;
+ if (p == template) {
+ pw = getpwnam(userid);
+ if (!pw) return 0;
+ usub = pw->pw_dir;
+ } else {
+ usub = userid;
+ }
+ return strlen(template) + p?strlen(usub):0 + q?strlen(tokenid):0 + 1;
+}
+
+static void
+make_path(char * const path, const char *tokenid, const char *userid)
+{
+ const char *usub;
+ char *p, *q;
+ struct passwd *pw;
+
+ path[0] = '\0';
+ if (template[0] == '~') {
+ pw = getpwnam(userid);
+ if (!pw) return;
+ usub = pw->pw_dir;
+ } else {
+ usub = userid;
+ }
+ q = path;
+ for (p = template; *p; p++) switch (*p) {
+ case '~':
+ strcpy(q, usub);
+ while (*q) q++;
+ break;
+ case '?':
+ strcpy(q, tokenid);
+ while (*q) q++;
+ break;
+ default:
+ *q++ = *p;
+ break;
+ }
+ *q = '\0';
+}
+
+struct _auth_obj authfile(const char *tokenid,
+ const char *userid, const char *password,
+ void (*update_nonce)(char *nonce, const int nonsize),
+ const unsigned char *secret, const int secsize,
+ const unsigned char *payload, const int paylsize,
+ struct _auth_chunk (*fetch_key)(const unsigned char *chal,
+ const int csize))