]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libauthsrv/convPR2M.c
archacpi: make *acpi=1 the default
[plan9front.git] / sys / src / libauthsrv / convPR2M.c
1 #include <u.h>
2 #include <libc.h>
3 #include <authsrv.h>
4
5 extern int form1B2M(char *ap, int n, uchar key[32]);
6
7 int
8 convPR2M(Passwordreq *f, char *ap, int n, Ticket *t)
9 {
10         uchar *p;
11
12         if(n < 1+2*PASSWDLEN+1+SECRETLEN)
13                 return 0;
14
15         p = (uchar*)ap;
16         *p++ = f->num;
17         memmove(p, f->old, PASSWDLEN), p += PASSWDLEN;
18         memmove(p, f->new, PASSWDLEN), p += PASSWDLEN;
19         *p++ = f->changesecret;
20         memmove(p, f->secret, SECRETLEN), p += SECRETLEN;
21         switch(t->form){
22         case 0:
23                 n = p - (uchar*)ap;
24                 encrypt(t->key, ap, n);
25                 return n;
26         case 1:
27                 if(n < 12+2*PASSWDLEN+1+SECRETLEN+16)
28                         return 0;
29                 return form1B2M(ap, p - (uchar*)ap, t->key);
30         }
31
32         return 0;
33 }
34