- unsigned char key[20];
- int keysize = sizeof(key);
- unsigned char mysecret[20];
- int mysecsize = sizeof(mysecret);
- unsigned char myload[256];
- int myloadsize = sizeof(myload);
- unsigned char *authobj = alloca(OBJSIZE);
- int authsize = OBJSIZE;
- char buf[512];
- char *oldtokenid = NULL, *oldid = NULL, *oldnonce = NULL,
- *hauthobj = NULL;
- unsigned char *oldauthobj = NULL;
- int oldauthsize;
-
- if ((fp = fopen(fn, "r"))) {
- if (fgets(buf, sizeof(buf), fp)) {
- oldtokenid = strtok(buf, ":\r\n");
- oldid = strtok(NULL, ":\r\n");
- oldnonce = strtok(NULL, ":\r\n");
- hauthobj = strtok(NULL, ":\r\n");
- } else {
- eprint("error reading from %s: %s\n",
- fn, strerror(errno));
+
+ for (i = 0, p = buf; *p; p = q+1, i++) {
+ for (q = p; *q && *q != ':' && *q != '\r' && *q != '\n'; q++) ;
+ *q = '\0';
+ if (*p && i < argc) argv[i] = p;
+ }
+ return i != argc;
+}
+
+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))
+{
+ struct _auth_obj ret = {0};
+ mode_t oldmask;
+ FILE *fp = NULL;
+ char *fn, *nfn;
+ int fnl;
+ char *buf = NULL;
+ struct {
+ const char *tokenid;
+ const char *userid;
+ const char *nonce;
+ const char *hablob;
+ } w = {"", NULL, NULL, NULL};
+ unsigned char *ablob = NULL;
+ int blobsize = 0;
+ char *newnonce;
+ int nonsize;
+ struct _auth_obj ao;
+
+ if ((fnl = path_size(tokenid, userid)) == 0) {
+ ret.err = "authfile path impossible to build";
+ return ret;
+ }
+ fn = alloca(fnl);
+ make_path(fn, tokenid, userid);
+ nfn = alloca(fnl+32);
+ snprintf(nfn, fnl+32, "%s.%d.%ld", fn, (int)getpid(), (long)time(NULL));
+ fp = fopen(fn, "r");
+ if (fp) {
+ struct stat st;
+ int fd = fileno(fp);
+
+ if (fstat(fd, &st)) st.st_size = 2047;
+ if (st.st_size > 2047) st.st_size = 2047;
+ buf = alloca(st.st_size + 1);
+ if (!fgets(buf, st.st_size + 1, fp)) {
+ ret.err = strerror(errno);
+ } else if (parse(buf, sizeof(w)/sizeof(char*),
+ (const char ** const)&w)){
+ ret.err = "error: unparseable auth file";