1212enum RootImplState apatch_get_existence (void ) {
1313 struct stat s ;
1414 if (stat ("/data/adb/apd" , & s ) != 0 ) {
15- LOGE ("APATCH | Failed to stat /data/adb/apd: %s\n" , strerror (errno ));
15+ if (errno != ENOENT ) LOGE ("Failed to stat APatch apd binary: %s\n" , strerror (errno ));
16+ errno = 0 ;
1617
1718 return Inexistent ;
1819 }
1920
2021 char apatch_version [32 ];
2122 char * const argv [] = { "apd" , "-V" , NULL };
2223
23- LOGI ("APATCH | Checking for apd existence\n" );
2424 if (!exec_command (apatch_version , sizeof (apatch_version ), "/data/adb/apd" , argv )) {
25- LOGE ("APATCH | Failed to execute apd binary: %s\n" , strerror (errno ));
25+ LOGE ("Failed to execute apd binary: %s\n" , strerror (errno ));
2626 errno = 0 ;
2727
2828 return Inexistent ;
2929 }
3030
3131 int version = atoi (apatch_version + strlen ("apd " ));
32- LOGI ("APATCH | apd version: %d\n" , version );
33- if (version == 0 ) return Abnormal ;
3432
33+ if (version == 0 ) return Abnormal ;
3534 if (version >= MIN_APATCH_VERSION && version <= 999999 ) return Supported ;
3635 if (version >= 1 && version <= MIN_APATCH_VERSION - 1 ) return TooOld ;
3736
@@ -49,38 +48,54 @@ struct packages_config {
4948 size_t size ;
5049};
5150
52- bool _apatch_get_package_config (struct packages_config * config ) {
51+ /* WARNING: Dynamic memory based */
52+ bool _apatch_get_package_config (struct packages_config * restrict config ) {
5353 FILE * fp = fopen ("/data/adb/ap/package_config" , "r" );
5454 if (fp == NULL ) {
55- LOGE ("APATCH | Failed to open package_config: %s\n" , strerror (errno ));
55+ LOGE ("Failed to open APatch's package_config: %s\n" , strerror (errno ));
5656
5757 return false;
5858 }
5959
60- char line [256 ];
60+ char line [1024 ];
6161 /* INFO: Skip the CSV header */
6262 fgets (line , sizeof (line ), fp );
6363
64+ LOGI ("meow meow: %s\n" , line );
65+
66+ config -> size = 0 ;
6467 while (fgets (line , sizeof (line ), fp ) != NULL ) {
65- config -> configs = realloc (config , (config -> size + 1 ) * sizeof (struct package_config ));
68+ LOGI ("meow meow\n" );
69+
70+ config -> configs = realloc (config -> configs , (config -> size + 1 ) * sizeof (struct package_config ));
6671 if (config -> configs == NULL ) {
67- LOGE ("APATCH | Failed to realloc package config: %s\n" , strerror (errno ));
72+ LOGE ("Failed to realloc APatch config struct : %s\n" , strerror (errno ));
6873
6974 fclose (fp );
7075
7176 return false;
7277 }
7378
79+ LOGI ("meow meow (1): %s\n" , line );
80+
7481 strtok (line , "," );
7582
83+ LOGI ("meow meow (2)\n" );
84+
7685 char * exclude_str = strtok (NULL , "," );
7786 if (exclude_str == NULL ) continue ;
7887
88+ LOGI ("meow meow: %s\n" , exclude_str );
89+
7990 char * allow_str = strtok (NULL , "," );
8091 if (allow_str == NULL ) continue ;
8192
93+ LOGI ("meow meow: %s\n" , allow_str );
94+
8295 char * uid_str = strtok (NULL , "," );
83- if (uid_str == NULL ) continue ;
96+ if (uid_str == NULL ) continue ;
97+
98+ LOGI ("meow meow: %s\n" , uid_str );
8499
85100 config -> configs [config -> size ].uid = atoi (uid_str );
86101 config -> configs [config -> size ].root_granted = strcmp (allow_str , "1" ) == 0 ;
@@ -138,7 +153,12 @@ bool apatch_uid_should_umount(uid_t uid) {
138153
139154bool apatch_uid_is_manager (uid_t uid ) {
140155 struct stat s ;
141- if (stat ("/data/user_de/0/me.bmax.apatch" , & s ) == -1 ) return false;
156+ if (stat ("/data/user_de/0/me.bmax.apatch" , & s ) == -1 ) {
157+ if (errno != ENOENT ) LOGE ("Failed to stat APatch manager data directory: %s\n" , strerror (errno ));
158+ errno = 0 ;
159+
160+ return false;
161+ }
142162
143163 return s .st_uid == uid ;
144164}
0 commit comments