c – Implementation of the square root for real time application

For the real time control software I need square root calculation. I have heard that the sqrt function from the standard library isn’t good choice due to the unpredictable number of iterations used during calculation. Based on that information I have decided to implement the sqrt function in my own based on the Newton tangent method. So I have exploited the iteration formula

$$x_{k+1} = -frac{f(x_k)}{f'(x_k)} + x_k,$$ where $$f(x) = x^2 – a$$ and $$a$$ is the radicant.

Based on the above mentioned formulas I have

$$x_{k+1} = frac{1}{2}cdotleft(x_k + frac{a}{x_k}right)$$

I have chosen $$x(0) = 2$$ and based on my observations four iterations give good results in comparison with the `sqrt` from the standard library.

``````#define ITERATIONS 4

double squareRoot(double a)
{
double xk  = 2.0; // x(k)

uint8_t k;
for(k = 0; k < ITERATIONS; k++)
{
xk  = 0.5*(xk + a/xk);
}

return xk;
}
``````

Despite that fact I have some doubts regarding the choice of the initial value and number of iterations.

root access – Device info changer for android 11

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

root access – Stopping Android updates?

Ok, so I have a question with which android apps/files are responsible for phone updates and app updates?. For instance let’s say using a standard tracfone no particular brand or if needed Samsung A21. And I have the phone set up exactly how I want it and I want absolutely no updates to any system or application files. The phone is rooted. Which files would I remove to keep it exactly like it is? Android version would be of that of the new tracphones found at any walmart.

cron – Edit crontab file in /etc as root user and add a line, Newbie challenged with syntax

I set up my CRM on-premise. Within CRM set up sync to Google Calendar. A manual test run within the CRM demonstrates that sync is working.

The CRM implementation guidelines state the following: For Unix/Linux systems, as a root user, edit the crontab file in /etc, and add an extra line at the end

The documentation provides a sample and explanation below:

*/5 * * * * cd </srv/www/vhosts/1crm>; </usr/bin/php> scheduler.php
where
is the username that the web server runs as (usually defaults to ‘apache’ or ‘wwwrun’),
and where
</srv/www/vhosts/1crm> is the path to your 1CRM directory,
and where
</usr/bin/php> is the path to your php executable file.

I figure how to edit as root or enter crontab e -u root in Konsole of Kubuntu.

I modify the above as follows:

*/5 * * * * www-data cd /var/www/1crm; /usr/bin/php7.4 scheduler.php

And gained no result, so what am I missing? Did I get the user wrong or should it be just PHP, or is it picking up the right scheduler.php (presumably the one in the crm directory). How do I test a cron job, for that matter? Right now, I am going in the crm and checking if calendar new test calendar items got sync, from google calendar to the crm calendar.

drush – “Drupal root not found. Pass –root or a @siteAlias in order to see Drupal-specific commands”

I have multiple sites inside the same htdocs directory. In one, I removed all the folders except vendor under Web. Now drush will not work (it worked before I moved the folders). But now, it cannot find the database, which is correctly defined in web/sites/default/settings.php

``````/srv/www/htdocs/jar/drupal # ./drush status
PHP binary    : /usr/bin/php
PHP config    : /srv/www/php.ini
PHP OS        : Linux
Drush script  : /srv/www/htdocs/jar/drupal/vendor/drush/drush/drush
Drush version : 10.3.6
Drush temp    : /tmp
Drush configs : /srv/www/htdocs/jar/drupal/vendor/drush/drush/drush.yml
Drupal root   : /srv/www/htdocs/jar/drupal
``````

I am running Drupal 9.0.8 and drush 10.3.6 (in /srv/www/htdocs/jar/drupal). I have removed drush using composer (2.0.3) and reinstalled it (recreating vendor in the process).

``````/srv/www/htdocs/jar/drupal # ./drush -vvv cr
(preflight) Config paths: /srv/www/htdocs/jar/drupal/vendor/drush/drush/drush.yml
(preflight) Alias paths: /srv/www/htdocs/jar/drupal/drush/sites,/srv/www/htdocs/jar/drush/sites
(preflight) Commandfile search paths: /srv/www/htdocs/jar/drupal/vendor/drush/drush/src
(debug) Starting bootstrap to site (0.04 sec, 8.17 MB)

In BootstrapHook.php line 32:
(Exception)
Exception trace:
at /srv/www/htdocs/jar/drupal/vendor/drush/drush/src/Boot/BootstrapHook.php:32
DrushBootBootstrapHook->initialize() at /srv/www/htdocs/jar/drupal/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:44
ConsolidationAnnotatedCommandHooksDispatchersInitializeHookDispatcher->doInitializeHook() at /srv/www/htdocs/jar/drupal/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:36
ConsolidationAnnotatedCommandHooksDispatchersInitializeHookDispatcher->callInitializeHook() at /srv/www/htdocs/jar/drupal/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:29
ConsolidationAnnotatedCommandHooksDispatchersInitializeHookDispatcher->initialize() at /srv/www/htdocs/jar/drupal/vendor/consolidation/annotated-command/src/CommandProcessor.php:145
ConsolidationAnnotatedCommandCommandProcessor->initializeHook() at /srv/www/htdocs/jar/drupal/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:296
ConsolidationAnnotatedCommandAnnotatedCommand->initialize() at /srv/www/htdocs/jar/drupal/vendor/symfony/console/Command/Command.php:221
SymfonyComponentConsoleCommandCommand->run() at /srv/www/htdocs/jar/drupal/vendor/symfony/console/Application.php:1018
SymfonyComponentConsoleApplication->doRunCommand() at /srv/www/htdocs/jar/drupal/vendor/symfony/console/Application.php:271
SymfonyComponentConsoleApplication->doRun() at /srv/www/htdocs/jar/drupal/vendor/symfony/console/Application.php:147
SymfonyComponentConsoleApplication->run() at /srv/www/htdocs/jar/drupal/vendor/drush/drush/src/Runtime/Runtime.php:118
DrushRuntimeRuntime->doRun() at /srv/www/htdocs/jar/drupal/vendor/drush/drush/src/Runtime/Runtime.php:49
DrushRuntimeRuntime->run() at /srv/www/htdocs/jar/drupal/vendor/drush/drush/drush.php:72
require() at /srv/www/htdocs/jar/drupal/vendor/drush/drush/drush:4
``````

I looked at all the above suggestions, but am stuck. Drush works perfectly on my other 5 sites…

[WTS] [MilesWeb] Fully Managed VPS Hosting Provider | Full Root Access, Free Migration

Pick the best self-managed Linux VPS hosting plans powered by KVM hypervisor. Get the best cloud infrastructure with advanced technical features such as SSD storage, high performing Intel CPUs – everything at inexpensive rates.

Quote:

Save upto 16% on Unmanaged VPS Hosting plans. Renewal would be at the same cost.

Self-Managed VPS Features

• Full Root Access
• SSD Disk Drives
• 100 Mb/s Network
• India-Based VPS

Below is the list of Self-Managed Linux VPS hosting plans offered by MilesWeb:

SMV1 Plan

• 2 vCPU
• 2 GB RAM
• 50 GB SSD Disk
• 500 GB Bandwidth
• Dedicated IP

Discounted Price: \$5 /mo – Buy Now

SMV2 Plan

• 2 vCPU
• 4 GB RAM
• 100 GB SSD Disk
• 500 GB Bandwidth
• Dedicated IP

Discounted Price: \$9 /mo – Buy Now

SMV3 Plan

• 4 vCPU
• 8 GB RAM
• 150 GB SSD Disk
• 1000 GB Bandwidth
• Dedicated IP

Discounted Price: \$18 /mo – Buy Now

SMV4 Plan

• 6 vCPU
• 12 GB RAM
• 200 GB SSD Disk
• 1000 GB Bandwidth
• Dedicated IP

Discounted Price: \$30 /mo – Buy Now

SMV5 Plan

• 8 vCPU
• 16 GB RAM
• 250 GB SSD Disk
• 2000 GB Bandwidth
• Dedicated IP

Discounted Price: \$38 /mo – Buy Now

SMV6 Plan

• 12 vCPU
• 24 GB RAM
• 300 GB SSD Disk
• 2000 GB Bandwidth
• Dedicated IP

Discounted Price: \$60/mo – Buy Now

For more details on Self-Managed Linux VPS Hosting plans please visit : https://www.milesweb.com/hosting/unmanaged-vps

MilesWeb offers fully managed Linux VPS hosting plans powered by KVM hypervisor and Windows VPS hosting powered by Hyper-V are available in multiple sizes with various technical components, all based on cloud infrastructure with built-in SSD storage.

Quote:

Save upto 10% on VPS Hosting plans. Renewal would be at the same cost.

Below is the list of Linux VPS hosting plans offered by MilesWeb:

V1 Plan

• 2 vCPU
• 2 GB RAM
• 50 GB SSD Disk
• 500 GB Bandwidth
• Free SSL Certificate
• Dedicated IP

Discounted Price: \$9 /mo – Buy Now

V2 Plan

• 2 vCPU
• 4 GB RAM
• 100 GB SSD Disk
• 500 GB Bandwidth
• Free SSL Certificate
• Dedicated IP

Discounted Price: \$15 /mo – Buy Now

V3 Plan

• 4 vCPU
• 8 GB RAM
• 150 GB SSD Disk
• 1000 GB Bandwidth
• Free SSL Certificate
• Dedicated IP

Discounted Price: \$28 /mo – Buy Now

V4 Plan

• 6 vCPU
• 12 GB RAM
• 200 GB SSD Disk
• 1000 GB Bandwidth
• Free SSL Certificate
• Dedicated IP

Discounted Price: \$43 /mo – Buy Now

V5 Plan

• 8 vCPU
• 16 GB RAM
• 250 GB SSD Disk
• 2000 GB Bandwidth
• Free SSL Certificate
• Dedicated IP

Discounted Price: \$58 /mo – Buy Now

V6 Plan

• 12 vCPU
• 24 GB RAM
• 300 GB SSD Disk
• 2000 GB Bandwidth
• Free SSL Certificate
• Dedicated IP

Discounted Price: \$86/mo – Buy Now

For more details on Linux VPS Hosting plans please visit : https://www.milesweb.com/hosting/vps-hosting

MilesWeb offers incredibly powerful self-managed Windows VPS servers for resource-heavy web projects that demand dedicated resources. Get full admin access to your server with RDP and Plesk panel.

Quote:

Save upto 16% on Self-Managed Windows VPS Hosting plans. Renewal would be at the same cost.

Below is the list of Self-Managed Windows VPS Hosting plans offered by MilesWeb:

SMW1 Plan

• 2 vCPU
• 2 GB RAM
• 50 GB SSD Disk
• 500 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$10 /mo – Buy Now

SMW2 Plan

• 2 vCPU
• 4 GB RAM
• 100 GB SSD Disk
• 500 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$18 /mo – Buy Now

SMW3 Plan

• 4 vCPU
• 8 GB RAM
• 150 GB SSD Disk
• 1000 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$36 /mo – Buy Now

SMW4 Plan

• 6 vCPU
• 12 GB RAM
• 200 GB SSD Disk
• 1000 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$60 /mo – Buy Now

SMW5 Plan

• 8 vCPU
• 16 GB RAM
• 250 GB SSD Disk
• 2000 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$76 /mo – Buy Now

SMW6 Plan

• 12 vCPU
• 24 GB RAM
• 300 GB SSD Disk
• 2000 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$120 /mo – Buy Now

For more details on Self-Managed Windows VPS Hosting plans please visit : https://www.milesweb.com/hosting/unmanaged-windows-vps

Below is the list of Fully Managed Windows VPS hosting plans offered by MilesWeb:

W1 Plan

• 2 vCPU
• 2 GB RAM
• 50 GB SSD Disk
• 500 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$18 /mo – Buy Now

W2 Plan

• 2 vCPU
• 4 GB RAM
• 100 GB SSD Disk
• 500 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$30 /mo – Buy Now

W3 Plan

• 4 vCPU
• 8 GB RAM
• 150 GB SSD Disk
• 1000 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$56 /mo – Buy Now

W4 Plan

• 6 vCPU
• 12 GB RAM
• 200 GB SSD Disk
• 1000 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$86 /mo – Buy Now

W5 Plan

• 8 vCPU
• 16 GB RAM
• 250 GB SSD Disk
• 2000 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$116 /mo – Buy Now

W6 Plan

• 12 vCPU
• 24 GB RAM
• 300 GB SSD Disk
• 2000 GB Bandwidth
• Free SSL Certificate

Discounted Price: \$172 /mo – Buy Now

For more details on Windows VPS Hosting plans please visit : https://www.milesweb.com/hosting/windows-vps

.

event sourcing – In CQRS/ES where does an Aggregate Root belong?

Disclaimer: This question may be related to the framework I’m using to support CQRS/ES rather than the concepts themselves but many of these frameworks implement the same strategies, making me think the two are tightly coupled regardless.

CQRS tells us to…

use a different model to update information than the model you use to read information1

And in event sourcing…

The fundamental idea of Event Sourcing is that of ensuring every change to the state of an application is captured in an event object2

My design includes aggregate root objects, upon which methods are called to make changes (in my particular case called from Commands/Handlers). Those methods check the invariants and then publish an event to a bus, which in turn updates some aspect of the aggregate, typically setting properties or adding items to a collection. These events also update my read model so that I have a projection of the most recent state of the system that can be easily queried. Most of my queries simply act upon the most recent state, but occasionally I need to create a projection for an aggregate as it existed at a point in the past (hence the use of event sourcing).

As such my aggregate root and read model share a very similar “shape”, so similar that I’ve created an interface that both implement so that I can treat them equally depending on the type of query being executed.

Given that the aggregate root and read model are so similar, and even though the aggregate appears to belong to the write model (as the commands act upon it) does it in fact belong in the read model?

Or, where does the aggregate root belong? In the write model, the read model or in a shared domain model, which seems to go against the whole CRQS idea?

supersu – How to manually root a phone?

I was looking at the web search results of “how to manually root Android devices” and I noticed that most of those are either just advertising stuff or makes use of dedicated (particularly closed source) rooting solutions. Those which worked some time ago are now obsolete since they depended on some security vulnerability in Android which was fixed over time.

In fact it’s not impossible to root phone manually but it’s not worth the hassle. However as a reference, let me describe an option. But before diving into the technical details, we need to understand what root is and how Android prevents root access. Details can be found here but a few points in short:

• Mostly vendors ship their devices with locked bootloader, and a chain of trust is established during boot process, which won’t let any modification be done to kernel (`boot.img`), recovery or the main OS. So the first step towards rooting is unlocked bootloader. Beware of the risks!
• A part of the chain of trust is `dm-verity` (`VB`/`AVB`); a kernel based phenomenon which makes sure that partitions containing core OS (`/system`, `/vendor`, `/odm`) are always mounted read-only and any malicious attempt to modify them must fail. Modifying `boot.img` or `recovery.img` is usually accompanied by disabling `dm-verity` to avoid surprises like bootloops at later stages. TWRP’s standard warning:

This device uses dm-verity!
This means that swiping to allow system modifications will prevent you from being able to boot if you are using the stock kernel.

• Similarly some vendors particularly Samsung go beyond normal and build extra security features in their devices like Knox, RKP, Defex, proca, TIMA, FIPS, bla bla bla. So you might also need to circumvent those e.g. by building kernel with `SECURITY_SELINUX_DEVELOP=y`, patching kernel binary etc.
• Android apps don’t have capabilities to elevate their privileges by executing binaries which have `setuid` or file capabilities set (which is the standard way to get root access). So the only option is to run a background persistent process (daemon) with root privileges outside the apps (e.g. during boot process) and request it to do privileged tasks on behalf of unprivileged apps when needed.
• Root (i.e. UID 0) is the old Discretionary Access Control (DAC), but Android also makes use of Mandatory Access Control (MAC) i.e. SELinux. A root process running with restricted SELinux context is quite helpless, so we have to break this barrier too. It requires modifying SELinux policy.

I’ll address the last two points here, but first two considerations:

• Android rooting solutions deploy a special `su` binary which – when executed by an app – makes a connection to privileged daemon and gets the app a root shell. So this `su` binary and daemon are specially developed for this purpose. A less sophisticated approach would be to run already available daemons like `adbd`, `sshd` or one of the old inetutils flavors (`telnetd`, `rlogind`, `rshd`, `rexecd`) with root privileges. When running in background, these servers can provide a root shell or execute commands with root privileges when connected by a client. For the sake of simplicity I’m using only a minimal network utility named `netcat` (`nc`) which is a busybox applet. But please note that apps can’t get root access with this approach, it can only be used from commandline.
• We are going to patch monolithic `/sepolicy` file and `/init.rc` file which are part of `ramdisk` in `boot.img`. But starting with Treble Android uses split policy which is loaded/compiled from `/system/etc/selinux/` and `/vendor/etc/selinux/`. Starting with SAR, there’s no ramdisk at all in `boot.img` and `/init.rc` is part of `system.img`. So in both cases you need to necessarily modify `system` partition. I’m not giving details on that here.

STEPS:

• Extract `boot.img` e.g. using AIK or `magiskboot` on Android or PC.
• Create a new SELinux context, say `pseudo_su`. Set it permissive so that to allow any possible interactions with other processes / files etc. Use Magisk’s `supolicy` tool or `sepolicy-inject` (1, 2) on Android or PC:

``````~# supolicy --load sepolicy --save sepolicy 'create pseudo_su"https://android.stackexchange.com/"permissive pseudo_su"https://android.stackexchange.com/"dontaudit pseudo_su * * *"https://android.stackexchange.com/"allow pseudo_su * * *"https://android.stackexchange.com/"allow * pseudo_su * *'
``````

Or to build `split-policy` using Android’s compiler:

``````~# /system/bin/secilc -m -M true -G -N -c \$(cat /sys/fs/selinux/policyvers) -o sepolicy /system/etc/selinux/plat_sepolicy.cil /system/etc/selinux/mapping/\$(cat /vendor/etc/selinux/plat_sepolicy_vers.txt).cil \$(( -f /vendor/etc/selinux/vendor_sepolicy.cil ) && echo /vendor/etc/selinux/vendor_sepolicy.cil /vendor/etc/selinux/plat_pub_versioned.cil "https://android.stackexchange.com/" echo /vendor/etc/selinux/nonplat_sepolicy.cil)
``````

* Get the value of `POLICYDB_VERSION_MAX` from your kernel source.

To use vendor’s `precompiled_sepolicy` or build from `split-policy` and patch:

``````~# supolicy --load-split --save sepolicy 'create pseudo_su"https://android.stackexchange.com/"permissive pseudo_su"https://android.stackexchange.com/"dontaudit pseudo_su * * *"https://android.stackexchange.com/"allow pseudo_su * * *"https://android.stackexchange.com/"allow * pseudo_su * *'
``````
• Define an `init` service which starts a simple TCP server on boot, only listening to on-device connections:

``````# /init.rc
...
service pseudo_su /sbin/busybox nc -lk -s 127.0.0.1 -p 23 -e /sbin/busybox sh
seclabel u:r:pseudo_su:s0
disabled

on property:sys.boot_completed=1
start pseudo_su
``````

* Make sure you get the right `busybox` binary, there are multiple implementations of `netcat`.
* Use port `23` or any other unused port.

• Copy updated `sepolicy` and `init.rc` to root of extracted ramdisk, `busybox` binary to `(ramdisk/)sbin/` and set permissions.
• Repack `boot.img` and flash or test with `fastboot boot boot.img`.

HOW TO RUN ROOT COMMANDS?

Once booted, we can pass commands from a `netcat` client on terminal emulator app (like Termux) or `adb shell`:

``````~\$ echo id | /sbin/busybox nc localhost 23
uid=0(root) gid=0(root) groups=0(root) context=u:r:pseudo_su:s0
``````

* Default SELinux policy doesn’t allow apps traverse `/sbin`. So either inject allow rules or put `busybox` in `/system/*bin/`. Or use some other `nc` e.g. from Termux’s `netcat` package.

For ease of use, create functions (put them in `.bashrc` so that you don’t have to define every time):

``````# ~/.bashrc
...
function psu() { echo "\$@ 2>&1"https://android.stackexchange.com/" /sbin/busybox nc localhost 23; }
function psush() { /sbin/busybox nc localhost 23; }
``````
``````~\$ ls -ld /data/adb
ls: cannot access '/data/adb': Permission denied
drwx------ 7 root root 3488 2019-07-19 00:44 /data/adb
``````

To get root shell:

``````~\$ psush
whoami
root
^C
``````

But it’s just a dumb shell, not connected to terminal. To have a more feature-rich experience, other tools like `socat` can be used which support line editing, pseudo-terminals etc.
Also environment variables aren’t evaluated unless explicitly passed, because commands are executed remotely:

``````~\$ /data/data/com.termux/files/usr/bin/ps -p \$\$,1 -o pid=,comm=
23599 bash
~\$ psu /data/data/com.termux/files/usr/bin/ps -p \$\$,1 -o pid=,comm=
~\$ psu LD_LIBRARY_PATH=/data/data/com.termux/files/usr/lib /data/data/com.termux/files/usr/bin/ps -p \$\$,1 -o pid=,comm=
1 init
23599 bash
``````

So that’s how we can get a minimal root functionality without using any specialized rooting tools.

RELATED:

MYSQL 8, Hierarchy Adjacency list, How each rows to know the top node of the alias root.?

MYSQL 8.
Here are some rows I have in a table containing hierarchical data.

``````+-----+-----------+------+--------------------------------------------+
| id  | parent_id | sort | name                                       |
+-----+-----------+------+--------------------------------------------+
|  30 |      NULL |    1 | AKTIVA                                     |
|  40 |        30 |    2 | Aktiva Lancar                              |
|  41 |        40 |    3 | Kas & Bank                                 |
|  42 |        41 |    4 | Kas                                        |
|  43 |        41 |    5 | Kas Tunai USD                              |
|  44 |        41 |    6 | Kas Tunai Di Brankas                       |
| 213 |      NULL |   56 | HUTANG & MODAL                             |
|  88 |       213 |   57 | Hutang                                     |
|  89 |        88 |   58 | Hutang Jangka Pendek                       |
| 106 |        89 |   59 | Hutang Dagang Lainnya                      |
|  93 |        89 |   60 | Hutang SDL                                 |
|  94 |        89 |   61 | Hutang WHL                                 |
+-----+-----------+------+--------------------------------------------+

``````

I use `CTE` to construct the data without much use of` SELF JOIN`
So far, here are the `query` I’ve used:

``````WITH RECURSIVE account_path (root, id, parent_id, name, lvl, `sort`, account_roll_up_id) AS
(
SELECT id AS root, id, parent_id, `name`, 0 lvl, `sort`, account_roll_up_id
FROM account_type
WHERE id IN (30, 213)

UNION ALL

SELECT 30 AS root, c.id, c.parent_id, c.name, (cp.lvl + 1), c.sort, c.account_roll_up_id
FROM account_path AS cp
JOIN account_type AS c ON cp.id = c.parent_id
)

SELECT root, id, parent_id, CONCAT(REPEAT("  ", lvl), name) AS name, lvl, `sort`, account_roll_up_id FROM account_path
ORDER BY `sort`;
``````

The results are as follows:

``````+------+------+-----------+------------------------------------------------+------+------+--------------------+
| root | id   | parent_id | name                                           | lvl  | sort | account_roll_up_id |
+------+------+-----------+------------------------------------------------+------+------+--------------------+
|   30 |   30 |      NULL | AKTIVA                                         |    0 |    1 |               NULL |
|   30 |   40 |        30 |   Aktiva Lancar                                |    1 |    2 |                  2 |
|   30 |   41 |        40 |     Kas & Bank                                 |    2 |    3 |                  2 |
|   30 |   42 |        41 |       Kas                                      |    3 |    4 |                  2 |
|   30 |   43 |        41 |       Kas Tunai USD                            |    3 |    5 |                  2 |
|   30 |   44 |        41 |       Kas Tunai Di Brankas                     |    3 |    6 |                  2 |
|  213 |  213 |      NULL | HUTANG & MODAL                                 |    0 |   56 |               NULL |
|   30 |   88 |       213 |   Hutang                                       |    1 |   57 |               NULL |
|   30 |   89 |        88 |     Hutang Jangka Pendek                       |    2 |   58 |                  9 |
|   30 |  106 |        89 |       Hutang Dagang Lainnya                    |    3 |   59 |                  9 |
|   30 |   93 |        89 |       Hutang SDL                               |    3 |   60 |                  9 |
|   30 |   94 |        89 |       Hutang WHL                               |    3 |   61 |                  9 |
+------+------+-----------+------------------------------------------------+------+------+--------------------+

``````

My problem is, I need each line to know the top node of the alias `root`.
I need the following data forms.

``````+------+------+-----------+------------------------------------------------+------+------+--------------------+
| root | id   | parent_id | name                                           | lvl  | sort | account_roll_up_id |
+------+------+-----------+------------------------------------------------+------+------+--------------------+
|   30 |   30 |      NULL | AKTIVA                                         |    0 |    1 |               NULL |
|   30 |   40 |        30 |   Aktiva Lancar                                |    1 |    2 |                  2 |
|   30 |   41 |        40 |     Kas & Bank                                 |    2 |    3 |                  2 |
|   30 |   42 |        41 |       Kas                                      |    3 |    4 |                  2 |
|   30 |   43 |        41 |       Kas Tunai USD                            |    3 |    5 |                  2 |
|   30 |   44 |        41 |       Kas Tunai Di Brankas                     |    3 |    6 |                  2 |
|  213 |  213 |      NULL | HUTANG & MODAL                                 |    0 |   56 |               NULL |
|  213 |   88 |       213 |   Hutang                                       |    1 |   57 |               NULL |
|  213 |   89 |        88 |     Hutang Jangka Pendek                       |    2 |   58 |                  9 |
|  213 |  106 |        89 |       Hutang Dagang Lainnya                    |    3 |   59 |                  9 |
|  213 |   93 |        89 |       Hutang SDL                               |    3 |   60 |                  9 |
|  213 |   94 |        89 |       Hutang WHL                               |    3 |   61 |                  9 |
+------+------+-----------+------------------------------------------------+------+------+--------------------+
``````

Thank you for the help.

If a mobile app pins the Root Authority Certificate of a server and verifies its hostname, is it possible an attack via DNS-poisoning?

I have some questions about certificate pinning.
Supposing that a mobile application has pinned only the root CA, it should be possible to an attacker to redirect in some way the victim to a malicious website with the same Root CA. Am I wrong?
What happens, instead, if an app pins the Root CA but verifies the hostname of the server which the app is connecting to?
If the attacker owns a website under the same Root CA, can he poison DNS-cache and let the app connect to his website or there are security mechanisms which prevent such behaviour?