Annotation of OpenXM_contrib2/asir2000/parse/id.c, Revision 1.4
1.4 ! noro 1: /*
! 2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
! 3: * All rights reserved.
! 4: *
! 5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
! 6: * non-exclusive and royalty-free license to use, copy, modify and
! 7: * redistribute, solely for non-commercial and non-profit purposes, the
! 8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
! 9: * conditions of this Agreement. For the avoidance of doubt, you acquire
! 10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
! 11: * third party developer retains all rights, including but not limited to
! 12: * copyrights, in and to the SOFTWARE.
! 13: *
! 14: * (1) FLL does not grant you a license in any way for commercial
! 15: * purposes. You may use the SOFTWARE only for non-commercial and
! 16: * non-profit purposes only, such as academic, research and internal
! 17: * business use.
! 18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
! 19: * international copyright treaties. If you make copies of the SOFTWARE,
! 20: * with or without modification, as permitted hereunder, you shall affix
! 21: * to all such copies of the SOFTWARE the above copyright notice.
! 22: * (3) An explicit reference to this SOFTWARE and its copyright owner
! 23: * shall be made on your publication or presentation in any form of the
! 24: * results obtained by use of the SOFTWARE.
! 25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
! 26: * e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification
! 27: * for such modification or the source code of the modified part of the
! 28: * SOFTWARE.
! 29: *
! 30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
! 31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
! 32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
! 33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
! 34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
! 35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
! 36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
! 37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
! 38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
! 39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
! 40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
! 41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
! 42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
! 43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
! 44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
! 45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
! 46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
! 47: *
! 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/id.c,v 1.3 2000/01/26 02:39:33 noro Exp $
! 49: */
1.1 noro 50: #include <stdio.h>
51:
52: static table1(),namemain(),host(),cgen(),instruction();
53:
54: #define MOD 37
55: #define MU 0xa9
56:
57: static unsigned int table[37] = {
58: 0x951abd73,0x13945025,0x3aade018,0x9eabf429,
59: 0xa93f9dc1,0x0e4250b8,0x7eacdf20,0x5edf4cf1,
60: 0x15ccd258,0xfe254fba,0xce4ab7ec,0x85be6c82,
61: 0x35de8043,0xcafc9597,0x0e6237a8,0x16c00729,
62: 0x1622eb3c,0x16d23b40,0xada88ff1,0xf21647cd,
63: 0xc4ce7500,0xac501ff2,0x9e254cc4,0x1e52f533,
64: 0x1fa449cb,0x309aaa45,0x78ae06e3,0x1f3858b2,
65: 0x781fdb92,0xa79eb329,0x7613effb,0xc01f87d1,
66: 0xad4fc2ec,0x9e60acb4,0xb41fdbb3,0x1facf09d,
67: 0x1fd027a3,
68: };
69:
70: static int p[7] = { 5, 7, 13, 23, 29, 61, 59 };
71: static int m[7] = { 1, 4, 9, 12, 16, 57, 51 };
72: static int s[7] = { 0, 3, 6, 10, 15, 20, 26 };
73:
74: static table1(seed,index,tab,r)
75: unsigned int seed;
76: int index;
77: unsigned int *tab,*r;
78: {
79: unsigned int v0,v1,v2,v3,v;
80:
81: v3 = seed & 0xff;
82: v2 = ((seed & 0xff00) >> 8) ^ v3;
83: v1 = ((seed & 0xff0000) >> 16) ^ v2;
84: v0 = ((seed & 0xff000000) >> 24) ^ v1;
85: v = tab[index];
86: *r = ((((v0&0xff)<<24)|((v1&0xff)<<16)|((v2&0xff)<<8)|(v3&0xff))^v);
87: }
88:
89: static namemain(namebuf,id)
90: char *namebuf;
91: unsigned int *id;
92: {
93: unsigned int v,i,b[4];
94:
95: v = 0;
96: while ( 1 ) {
97: for ( i = 0; i < 4; i++ ) b[i] = 0;
98: for ( i = 0; ( i < 4 ) && *namebuf; namebuf++,i++ )
99: b[i] = (int) *namebuf;
100: v ^= ( ( b[3] & 0xff ) << 24 |
101: ( b[2] & 0xff ) << 16 |
102: ( b[1] & 0xff ) << 8 |
103: ( b[0] & 0xff ) );
104: if ( *namebuf == 0 ) {
105: *id = v; return;
106: }
107: }
108: }
109:
110: static host(id)
111: unsigned int *id;
112: {
113: char name[BUFSIZ];
114:
115: #if !defined(_PA_RISC1_1)
116: if ( !(*id = gethostid()) ) {
117: #endif
118: gethostname(name,BUFSIZ);
119: if ( strlen(name) > 0x40 )
120: name[0x40] = 0;
121: namemain(name,id);
122: #if !defined(_PA_RISC1_1)
123: }
124: #endif
125: }
126:
127: static cgen(m1,m2,m3)
128: unsigned m1,m2,m3;
129: {
130: unsigned int n1,n2,n3,v1;
131: unsigned short xml;
132: unsigned int id;
133: int i;
134:
135: host(&id);
136: table1(id,id % MOD,table,&n1);
137: if ( n1 != m1 )
138: return 0;
139: xml = ((unsigned short)(m2&0xffff))^((unsigned short)(table[id%MOD]&0xffff));
140: if ( ((xml>>8)^(xml&0xff)) != MU )
141: return 0;
142: n3 = 0;
143: for ( i = 0; i < 7; i++ )
144: n3 |= ( ( ( ( m1 % p[i] ) * m[i] + ( m2 % p[i] ) ) % p[i] ) << s[i] );
145: if ( n3 != m3 )
146: return 0;
147: return 1;
148: }
149:
150: check_key()
151: {
152: unsigned int n1,n2,n3;
153: int c;
154: FILE *fp;
155: char key_file[BUFSIZ],buf[BUFSIZ];
156: extern char *asir_libdir;
157: char *asir_key;
158:
159: asir_key = (char *)getenv("ASIR_KEY");
160: if ( asir_key )
161: strcpy(key_file,asir_key);
162: else
163: key_file[0] = 0;
164: if ( !key_file[0] || !(fp = fopen(key_file,"r")) ) {
165: sprintf(key_file,"%s/asir_key",".");
166: if ( !(fp = fopen(key_file,"r")) ) {
167: sprintf(key_file,"%s/asir_key",asir_libdir);
168: if ( !(fp = fopen(key_file,"r")) ) {
169: fprintf(stderr,"asir_key not found.\n");
170: instruction();
171: }
172: }
173: }
174: while ( 1 ) {
175: c = fgetc(fp);
176: if ( c == EOF )
177: break;
178: else
179: ungetc(c,fp);
180: fgets(buf,BUFSIZ,fp);
181: sscanf(buf,"%x %x %x",&n1,&n2,&n3);
182: if ( cgen(n1,n2,n3) ) {
183: fclose(fp);
184: return;
185: }
186: }
1.2 noro 187: fprintf(stderr,"Key for this machine not found in \"%s\".\n",key_file);
1.1 noro 188: instruction();
189: }
190:
191: static instruction()
192: {
193: unsigned int id;
1.2 noro 194: extern char *asir_libdir;
1.1 noro 195:
196: host(&id);
1.2 noro 197: fprintf(stderr,
1.3 noro 198: "\nYou need a key for each machine on which you want to run Asir.\n\
199: In order to get the key, send an e-mail consisting of the following\n\
200: single line to risa@sec.flab.fujitsu.co.jp.\n\n\
201: ASIR %08x\n\n\
202: After a while, an e-mail will be returned containing only one line like\n\n\
203: YYYYYYYY YYYYYYYY YYYYYYYY\n\n\
204: Create '%s/asir_key'\n\
1.2 noro 205: if necessary and append the returned string to the file.\n",
206: id,asir_libdir,asir_libdir);
1.1 noro 207: ExitAsir();
208: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>