s3:lib/afs fix the build with --with-fake-kaserver
[samba.git] / source3 / lib / afs_settoken.c
index aeef1c35203da77bb8cdc75d0e67c66a6fbe8d20..149fc66b0e449f36a8858050823343b7e1988743 100644 (file)
@@ -23,6 +23,9 @@
 
 #define NO_ASN1_TYPEDEFS 1
 
+#include "system/filesys.h"
+
+#include <afs/param.h>
 #include <afs/stds.h>
 #include <afs/afs.h>
 #include <afs/auth.h>
@@ -37,7 +40,24 @@ int afs_syscall( int subcall,
          char * cmarg,
          int follow)
 {
+/*
        return( syscall( SYS_afs_syscall, subcall, path, cmd, cmarg, follow));
+*/
+       int errcode;
+       struct afsprocdata afs_syscall_data;
+       afs_syscall_data.syscall = subcall;
+       afs_syscall_data.param1 = (long)path;
+       afs_syscall_data.param2 = cmd;
+       afs_syscall_data.param3 = (long)cmarg;
+       afs_syscall_data.param4 = follow;
+       int proc_afs_file = open(PROC_SYSCALL_FNAME, O_RDWR);
+       if (proc_afs_file < 0)
+               proc_afs_file = open(PROC_SYSCALL_ARLA_FNAME, O_RDWR);
+       if (proc_afs_file < 0)
+               return -1;
+       errcode = ioctl(proc_afs_file, VIOC_SYSCALL, &afs_syscall_data);
+       close(proc_afs_file);
+       return errcode;
 }
 
 struct ClearToken {
@@ -53,20 +73,21 @@ static bool afs_decode_token(const char *string, char **cell,
 {
        DATA_BLOB blob;
        struct ClearToken result_ct;
+       char *saveptr;
 
        char *s = SMB_STRDUP(string);
 
        char *t;
 
-       if ((t = strtok(s, "\n")) == NULL) {
-               DEBUG(10, ("strtok failed\n"));
+       if ((t = strtok_r(s, "\n", &saveptr)) == NULL) {
+               DEBUG(10, ("strtok_r failed\n"));
                return False;
        }
 
        *cell = SMB_STRDUP(t);
 
-       if ((t = strtok(NULL, "\n")) == NULL) {
-               DEBUG(10, ("strtok failed\n"));
+       if ((t = strtok_r(NULL, "\n", &saveptr)) == NULL) {
+               DEBUG(10, ("strtok_r failed\n"));
                return False;
        }
 
@@ -75,8 +96,8 @@ static bool afs_decode_token(const char *string, char **cell,
                return False;
        }
                
-       if ((t = strtok(NULL, "\n")) == NULL) {
-               DEBUG(10, ("strtok failed\n"));
+       if ((t = strtok_r(NULL, "\n", &saveptr)) == NULL) {
+               DEBUG(10, ("strtok_r failed\n"));
                return False;
        }
 
@@ -93,8 +114,8 @@ static bool afs_decode_token(const char *string, char **cell,
 
        data_blob_free(&blob);
 
-       if ((t = strtok(NULL, "\n")) == NULL) {
-               DEBUG(10, ("strtok failed\n"));
+       if ((t = strtok_r(NULL, "\n", &saveptr)) == NULL) {
+               DEBUG(10, ("strtok_r failed\n"));
                return False;
        }
 
@@ -103,8 +124,8 @@ static bool afs_decode_token(const char *string, char **cell,
                return False;
        }
                
-       if ((t = strtok(NULL, "\n")) == NULL) {
-               DEBUG(10, ("strtok failed\n"));
+       if ((t = strtok_r(NULL, "\n", &saveptr)) == NULL) {
+               DEBUG(10, ("strtok_r failed\n"));
                return False;
        }
 
@@ -113,8 +134,8 @@ static bool afs_decode_token(const char *string, char **cell,
                return False;
        }
                
-       if ((t = strtok(NULL, "\n")) == NULL) {
-               DEBUG(10, ("strtok failed\n"));
+       if ((t = strtok_r(NULL, "\n", &saveptr)) == NULL) {
+               DEBUG(10, ("strtok_r failed\n"));
                return False;
        }
 
@@ -123,8 +144,8 @@ static bool afs_decode_token(const char *string, char **cell,
                return False;
        }
                
-       if ((t = strtok(NULL, "\n")) == NULL) {
-               DEBUG(10, ("strtok failed\n"));
+       if ((t = strtok_r(NULL, "\n", &saveptr)) == NULL) {
+               DEBUG(10, ("strtok_r failed\n"));
                return False;
        }
 
@@ -217,7 +238,7 @@ bool afs_settoken_str(const char *token_string)
        if (!afs_decode_token(token_string, &cell, &ticket, &ct))
                return False;
 
-       if (geteuid() != 0)
+       if (geteuid() != sec_initial_uid())
                ct.ViceId = getuid();
 
        result = afs_settoken(cell, &ct, ticket);