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>
32 _syscall5(int, afs_syscall, int, subcall,
42 uint32 BeginTimestamp;
46 static BOOL afs_decode_token(const char *string, char **cell,
47 DATA_BLOB *ticket, struct ClearToken *ct)
50 struct ClearToken result_ct;
52 char *s = strdup(string);
56 if ((t = strtok(s, "\n")) == NULL) {
57 DEBUG(10, ("strtok failed\n"));
63 if ((t = strtok(NULL, "\n")) == NULL) {
64 DEBUG(10, ("strtok failed\n"));
68 if (sscanf(t, "%u", &result_ct.AuthHandle) != 1) {
69 DEBUG(10, ("sscanf AuthHandle failed\n"));
73 if ((t = strtok(NULL, "\n")) == NULL) {
74 DEBUG(10, ("strtok failed\n"));
78 blob = base64_decode_data_blob(t);
80 if ( (blob.data == NULL) ||
81 (blob.length != sizeof(result_ct.HandShakeKey) )) {
82 DEBUG(10, ("invalid key: %x/%d\n", (uint32)blob.data,
87 memcpy(result_ct.HandShakeKey, blob.data, blob.length);
89 data_blob_free(&blob);
91 if ((t = strtok(NULL, "\n")) == NULL) {
92 DEBUG(10, ("strtok failed\n"));
96 if (sscanf(t, "%u", &result_ct.ViceId) != 1) {
97 DEBUG(10, ("sscanf ViceId failed\n"));
101 if ((t = strtok(NULL, "\n")) == NULL) {
102 DEBUG(10, ("strtok failed\n"));
106 if (sscanf(t, "%u", &result_ct.BeginTimestamp) != 1) {
107 DEBUG(10, ("sscanf BeginTimestamp failed\n"));
111 if ((t = strtok(NULL, "\n")) == NULL) {
112 DEBUG(10, ("strtok failed\n"));
116 if (sscanf(t, "%u", &result_ct.EndTimestamp) != 1) {
117 DEBUG(10, ("sscanf EndTimestamp failed\n"));
121 if ((t = strtok(NULL, "\n")) == NULL) {
122 DEBUG(10, ("strtok failed\n"));
126 blob = base64_decode_data_blob(t);
128 if (blob.data == NULL) {
129 DEBUG(10, ("Could not get ticket\n"));
140 Put an AFS token into the Kernel so that it can authenticate against
141 the AFS server. This assumes correct local uid settings.
143 This is currently highly Linux and OpenAFS-specific. The correct API
144 call for this would be ktc_SetToken. But to do that we would have to
145 import a REALLY big bunch of libraries which I would currently like
149 static BOOL afs_settoken(const char *cell,
150 const struct ClearToken *ctok,
156 uint16 in_size, out_size;
163 memcpy(p, &ticket.length, sizeof(uint32));
165 memcpy(p, ticket.data, ticket.length);
168 tmp = sizeof(struct ClearToken);
169 memcpy(p, &tmp, sizeof(uint32));
171 memcpy(p, ctok, tmp);
176 memcpy(p, &tmp, sizeof(uint32));
180 if (tmp >= MAXKTCREALMLEN) {
181 DEBUG(1, ("Realm too long\n"));
185 strncpy(p, cell, tmp);
191 iob.in_size = PTR_DIFF(p,buf);
193 iob.out_size = sizeof(buf);
196 file_save("/tmp/ioctlbuf", iob.in, iob.in_size);
199 ret = afs_syscall(AFSCALL_PIOCTL, 0, VIOCSETTOK, (char *)&iob, 0);
201 DEBUG(10, ("afs VIOCSETTOK returned %d\n", ret));
205 BOOL afs_settoken_str(const char *token_string)
208 struct ClearToken ct;
212 if (!afs_decode_token(token_string, &cell, &ticket, &ct))
216 ct.ViceId = getuid();
218 result = afs_settoken(cell, &ct, ticket);
221 data_blob_free(&ticket);
228 BOOL afs_settoken_str(const char *token_string)