2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Volker Lendecke 2004
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifdef WITH_FAKE_KASERVER
28 #include <afs/venus.h>
29 #include <asm/unistd.h>
30 #include <openssl/des.h>
31 #include <sys/syscall.h>
33 int afs_syscall( int subcall
,
39 return( syscall( SYS_afs_syscall
, subcall
, path
, cmd
, cmarg
, follow
));
46 uint32 BeginTimestamp
;
50 static BOOL
afs_decode_token(const char *string
, char **cell
,
51 DATA_BLOB
*ticket
, struct ClearToken
*ct
)
54 struct ClearToken result_ct
;
56 char *s
= strdup(string
);
60 if ((t
= strtok(s
, "\n")) == NULL
) {
61 DEBUG(10, ("strtok failed\n"));
67 if ((t
= strtok(NULL
, "\n")) == NULL
) {
68 DEBUG(10, ("strtok failed\n"));
72 if (sscanf(t
, "%u", &result_ct
.AuthHandle
) != 1) {
73 DEBUG(10, ("sscanf AuthHandle failed\n"));
77 if ((t
= strtok(NULL
, "\n")) == NULL
) {
78 DEBUG(10, ("strtok failed\n"));
82 blob
= base64_decode_data_blob(t
);
84 if ( (blob
.data
== NULL
) ||
85 (blob
.length
!= sizeof(result_ct
.HandShakeKey
) )) {
86 DEBUG(10, ("invalid key: %x/%d\n", (uint32
)blob
.data
,
91 memcpy(result_ct
.HandShakeKey
, blob
.data
, blob
.length
);
93 data_blob_free(&blob
);
95 if ((t
= strtok(NULL
, "\n")) == NULL
) {
96 DEBUG(10, ("strtok failed\n"));
100 if (sscanf(t
, "%u", &result_ct
.ViceId
) != 1) {
101 DEBUG(10, ("sscanf ViceId failed\n"));
105 if ((t
= strtok(NULL
, "\n")) == NULL
) {
106 DEBUG(10, ("strtok failed\n"));
110 if (sscanf(t
, "%u", &result_ct
.BeginTimestamp
) != 1) {
111 DEBUG(10, ("sscanf BeginTimestamp failed\n"));
115 if ((t
= strtok(NULL
, "\n")) == NULL
) {
116 DEBUG(10, ("strtok failed\n"));
120 if (sscanf(t
, "%u", &result_ct
.EndTimestamp
) != 1) {
121 DEBUG(10, ("sscanf EndTimestamp failed\n"));
125 if ((t
= strtok(NULL
, "\n")) == NULL
) {
126 DEBUG(10, ("strtok failed\n"));
130 blob
= base64_decode_data_blob(t
);
132 if (blob
.data
== NULL
) {
133 DEBUG(10, ("Could not get ticket\n"));
144 Put an AFS token into the Kernel so that it can authenticate against
145 the AFS server. This assumes correct local uid settings.
147 This is currently highly Linux and OpenAFS-specific. The correct API
148 call for this would be ktc_SetToken. But to do that we would have to
149 import a REALLY big bunch of libraries which I would currently like
153 static BOOL
afs_settoken(const char *cell
,
154 const struct ClearToken
*ctok
,
160 uint16 in_size
, out_size
;
167 memcpy(p
, &ticket
.length
, sizeof(uint32
));
169 memcpy(p
, ticket
.data
, ticket
.length
);
172 tmp
= sizeof(struct ClearToken
);
173 memcpy(p
, &tmp
, sizeof(uint32
));
175 memcpy(p
, ctok
, tmp
);
180 memcpy(p
, &tmp
, sizeof(uint32
));
184 if (tmp
>= MAXKTCREALMLEN
) {
185 DEBUG(1, ("Realm too long\n"));
189 strncpy(p
, cell
, tmp
);
195 iob
.in_size
= PTR_DIFF(p
,buf
);
197 iob
.out_size
= sizeof(buf
);
200 file_save("/tmp/ioctlbuf", iob
.in
, iob
.in_size
);
203 ret
= afs_syscall(AFSCALL_PIOCTL
, 0, VIOCSETTOK
, (char *)&iob
, 0);
205 DEBUG(10, ("afs VIOCSETTOK returned %d\n", ret
));
209 BOOL
afs_settoken_str(const char *token_string
)
212 struct ClearToken ct
;
216 if (!afs_decode_token(token_string
, &cell
, &ticket
, &ct
))
220 ct
.ViceId
= getuid();
222 result
= afs_settoken(cell
, &ct
, ticket
);
225 data_blob_free(&ticket
);
232 BOOL
afs_settoken_str(const char *token_string
)