@@ -12,6 +12,7 @@ import std.json;
1212import std.math ;
1313import std.net.curl ;
1414import std.parallelism ;
15+ import process = std.process ;
1516import std.path ;
1617import std.uni ;
1718import std.uuid ;
@@ -32,6 +33,7 @@ import provision;
3233import provision.androidlibrary;
3334
3435__gshared string libraryPath;
36+ __gshared string provisioningPath;
3537
3638enum brandingCode = format! " anisette-v3-server v%s" (provisionVersion);
3739enum clientInfo = " <MacBookPro13,2> <macOS;13.1;22C65> <com.apple.AuthKit/1 (com.apple.dt.Xcode/3594.4.19)>" ;
@@ -92,11 +94,10 @@ int main(string[] args) {
9294
9395 libraryPath = configurationPath.buildPath(" lib" );
9496
95- string provisioningPathV3 = file.getcwd().buildPath(" provisioning" );
97+ string runtimePath = process.environment.get (" RUNTIME_DIRECTORY" , process.environment.get (" XDG_RUNTIME_DIR" , file.getcwd()))
98+ .buildPath(" anisette-v3" );
9699
97- if (! file.exists(provisioningPathV3)) {
98- file.mkdir(provisioningPathV3);
99- }
100+ provisioningPath = runtimePath.buildPath(" provisioning" );
100101
101102 auto coreADIPath = libraryPath.buildPath(" libCoreADI.so" );
102103 auto SSCPath = libraryPath.buildPath(" libstoreservicescore.so" );
@@ -236,23 +237,21 @@ class AnisetteService {
236237 auto log = getLogger();
237238 log.info(" [<<] anisette-v3 /v3/get_headers" );
238239 string identifier = " (null)" ;
240+ string tmpProvisioningPath;
239241 try {
240242 import std.uuid ;
241243 auto json = req.json();
242244 ubyte [] identifierBytes = Base64.decode(json[" identifier" ].to! string ());
243245 ubyte [] adi_pb = Base64.decode(json[" adi_pb" ].to! string ());
244246 identifier = UUID (identifierBytes[0 .. 16 ]).toString();
247+ tmpProvisioningPath = provisioningPath.buildPath(identifier);
245248
246- auto provisioningPath = file.getcwd()
247- .buildPath(" provisioning" )
248- .buildPath(identifier);
249-
250- if (file.exists(provisioningPath)) {
251- file.rmdirRecurse(provisioningPath);
249+ if (file.exists(tmpProvisioningPath)) {
250+ file.rmdirRecurse(tmpProvisioningPath);
252251 }
253252
254- file.mkdir(provisioningPath );
255- file.write(provisioningPath .buildPath(" adi.pb" ), adi_pb);
253+ file.mkdirRecurse(tmpProvisioningPath );
254+ file.write(tmpProvisioningPath .buildPath(" adi.pb" ), adi_pb);
256255
257256 GC .disable(); // garbage collector can deallocate ADI parts since it can't find the pointers.
258257 scope (exit) {
@@ -261,11 +260,11 @@ class AnisetteService {
261260 }
262261
263262 scope ADI adi = makeGarbageCollectedADI(libraryPath);
264- adi.provisioningPath = provisioningPath ;
263+ adi.provisioningPath = tmpProvisioningPath ;
265264 adi.identifier = identifier.toUpper()[0 .. 16 ];
266265
267266 auto otp = adi.requestOTP(dsId);
268- file.rmdirRecurse(provisioningPath );
267+ file.rmdirRecurse(tmpProvisioningPath );
269268
270269 JSONValue response = [ // Provision does no longer have a concept of 'request headers'
271270 " result" : " Headers" ,
@@ -285,16 +284,8 @@ class AnisetteService {
285284 log.info(" [>>] anisette-v3 /v3/get_headers error." );
286285 res.writeBody(error.toString(JSONOptions.doNotEscapeSlashes), " application/json" );
287286 } finally {
288- if (file.exists(
289- file.getcwd()
290- .buildPath(" provisioning" )
291- .buildPath(identifier)
292- )) {
293- file.rmdirRecurse(
294- file.getcwd()
295- .buildPath(" provisioning" )
296- .buildPath(identifier)
297- );
287+ if (file.exists(tmpProvisioningPath)) {
288+ file.rmdirRecurse(tmpProvisioningPath);
298289 }
299290 }
300291 }
@@ -348,13 +339,11 @@ class AnisetteService {
348339 GC .collect();
349340 }
350341 scope ADI adi = makeGarbageCollectedADI(libraryPath);
351- auto provisioningPath = file.getcwd()
352- .buildPath(" provisioning" )
353- .buildPath(identifier);
354- adi.provisioningPath = provisioningPath;
342+ auto tmpProvisioningPath = provisioningPath.buildPath(identifier);
343+ adi.provisioningPath = tmpProvisioningPath;
355344 scope (exit) {
356- if (file.exists(provisioningPath )) {
357- file.rmdirRecurse(provisioningPath );
345+ if (file.exists(tmpProvisioningPath )) {
346+ file.rmdirRecurse(tmpProvisioningPath );
358347 }
359348 }
360349 adi.identifier = identifier.toUpper()[0 .. 16 ];
0 commit comments