|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Client interface for granting other processes to token to access |
|
15 * particular files in app directory |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include "alf/ftokenclient.h" |
|
22 #include "ftokenconsts.h" |
|
23 |
|
24 EXPORT_C TInt RFTokenClient::Connect() |
|
25 { |
|
26 TInt err = KErrNone; |
|
27 TFindServer serveFinder(FTOKEN_SERVER_NAME); |
|
28 TFullName fullName; |
|
29 if (serveFinder.Next(fullName) != KErrNone) |
|
30 { |
|
31 const TUidType serverUid(KNullUid,KNullUid,KServerUid3); |
|
32 |
|
33 RProcess server; |
|
34 err = server.Create(_L("Z:\\sys\\bin\\!ftokenserver.exe"),FTOKEN_SERVER_NAME,serverUid); |
|
35 if (!err) |
|
36 { |
|
37 TRequestStatus stat; |
|
38 server.Rendezvous(stat); |
|
39 if (stat!=KRequestPending) |
|
40 { |
|
41 server.Kill(0); // abort startup |
|
42 } |
|
43 else |
|
44 { |
|
45 server.Resume(); // logon OK - start the server |
|
46 } |
|
47 User::WaitForRequest(stat); // wait for start or death |
|
48 err = stat.Int(); |
|
49 } |
|
50 } |
|
51 |
|
52 if ( !err ) |
|
53 { |
|
54 err = CreateSession(FTOKEN_SERVER_NAME,TVersion(1,1,1)); |
|
55 } |
|
56 |
|
57 return err; |
|
58 } |
|
59 |
|
60 EXPORT_C TInt RFTokenClient::GenerateToken(const TDesC& aFileName, const TUid& aConsumerUid, TDes8& aToken) const |
|
61 { |
|
62 TSecureId consumerUid(aConsumerUid); |
|
63 return GenerateToken(aFileName, TSecurityPolicy(consumerUid), aToken); |
|
64 } |
|
65 |
|
66 EXPORT_C TInt RFTokenClient::GenerateToken(const TDesC& aFileName, const TSecurityPolicy& aSecurityPolicy, TDes8& aToken) const |
|
67 { |
|
68 // unefficient, but this way we can make _easily_ sure that client is actually allowed to open a file |
|
69 // Not sure if we were allowed to just change CEikonEnv's file server session to shared, so we could acutally save |
|
70 // this extra session.. |
|
71 RFs fs; |
|
72 TInt err = fs.Connect(); |
|
73 if (!err) |
|
74 { |
|
75 err = fs.ShareProtected(); |
|
76 if (!err) |
|
77 { |
|
78 RFile file; |
|
79 err = file.Open(fs, aFileName, EFileShareReadersOnly); // Todo: check the correct mode |
|
80 if (!err) |
|
81 { |
|
82 err = GenerateToken(file, aSecurityPolicy, aToken); |
|
83 } |
|
84 file.Close(); |
|
85 } |
|
86 fs.Close(); |
|
87 } |
|
88 |
|
89 return err; |
|
90 //return SendReceive(EGenerateTokenBasedOnName, TIpcArgs(&aFileName, aAllowedProcessUid.iUid, &aToken)); |
|
91 } |
|
92 |
|
93 EXPORT_C TInt RFTokenClient::GenerateToken(const RFile& aOpenFile, const TUid& aConsumerUid,TDes8& aToken) const |
|
94 { |
|
95 TSecureId consumerUid(aConsumerUid); |
|
96 return GenerateToken(aOpenFile, TSecurityPolicy(consumerUid), aToken); |
|
97 } |
|
98 |
|
99 EXPORT_C TInt RFTokenClient::GenerateToken(const RFile& aOpenFile, const TSecurityPolicy& aSecurityPolicy,TDes8& aToken) const |
|
100 { |
|
101 TPtrC8 ptr = aSecurityPolicy.Package(); |
|
102 TIpcArgs ipcArgs(&ptr, &aToken, 0, 0); |
|
103 TInt ret = aOpenFile.TransferToServer(ipcArgs, 2, 3); |
|
104 if (ret == KErrNone) |
|
105 { |
|
106 ret = SendReceive(EGenerateTokenBasedOnOpenHandle, ipcArgs); |
|
107 } |
|
108 return ret; |
|
109 } |
|
110 |
|
111 EXPORT_C TInt RFTokenClient::GenerateToken(const TDesC8& aExistingToken, const TUid& aConsumerUid,TDes8& aToken) const |
|
112 { |
|
113 TSecureId consumerUid(aConsumerUid); |
|
114 return GenerateToken(aExistingToken, TSecurityPolicy(consumerUid), aToken); |
|
115 } |
|
116 |
|
117 EXPORT_C TInt RFTokenClient::GenerateToken(const TDesC8& aExistingToken, const TSecurityPolicy& aSecurityPolicy,TDes8& aToken) const |
|
118 { |
|
119 TPtrC8 ptr = aSecurityPolicy.Package(); |
|
120 return SendReceive(EGenerateTokenBasedOnAnotherToken, TIpcArgs(&ptr, &aExistingToken, &aToken)); |
|
121 } |
|
122 |
|
123 EXPORT_C TInt RFTokenClient::OpenFileForToken(RFile& aHandle, const TDesC8& aToken) const |
|
124 { |
|
125 TInt serverhandle = 0; |
|
126 TPckg<TInt> buf(serverhandle); |
|
127 TInt rfsHandle = SendReceive(EOpenHandleForToken, TIpcArgs(&buf, &aToken)); |
|
128 return aHandle.AdoptFromServer(rfsHandle, serverhandle); |
|
129 } |
|
130 |
|
131 // end of file |