Create or open a shared memory block

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!

Create or open a shared memory block

Postby Otto » Fri May 22, 2020 6:48 pm

Hello,
Is it possible to create or open a shared memory block like in php.
https://www.php.net/manual/en/function.shmop-open.php

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Create or open a shared memory block

Postby Antonio Linares » Sat May 23, 2020 7:03 am

Otto,

For Windows you could use GlobalAlloc()
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc

To make it Linux and OSX compatible, then simply use malloc()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Create or open a shared memory block

Postby Otto » Sat May 23, 2020 7:22 am

Dear Antonio,
thank you. Would you be so kind to post a little sample.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Create or open a shared memory block

Postby Antonio Linares » Sat May 23, 2020 8:56 am

Code: Select all  Expand view
#include <windows.h>
#include <hbapi.h>

HB_FUNC( MEMBLOCK )
{
   hb_retptr( GlobalAlloc( hb_parnl( 1 ), ( SIZE_T ) hb_parnll( 2 ) ) );
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Create or open a shared memory block

Postby Otto » Sat May 23, 2020 3:53 pm

Dear Antonio,
When I restart the server, I save a password in memory.

The data in the databases are encrypted with this password .
There are no saved passwords on the server hard drive.
I use a Form to insert the PW.

Code: Select all  Expand view
<?php
$shm_id = shmop_open(0xff3, "c", 0644, 100);
$shm_size = shmop_size($shm_id);
echo "SHM Block mit: ".$shm_size. " Bytes wurde erstellt.\n";
$shm_bytes_written = shmop_write($shm_id, "my key1234567890", 0);
$my_string = shmop_read($shm_id, 0, $shm_size);
echo "Data written: ".$my_string."\n";
shmop_close($shm_id);
?>
 

The programs read the password like this:

Code: Select all  Expand view
<?php

$shm_id = shmop_open(0xff3, "c", 0644, 100);
$shm_size = shmop_size($shm_id);
echo "SHM Block mit: ".$shm_size. " Bytes wurde erstellt.\n";
$my_string = shmop_read($shm_id, 0, $shm_size);
echo "Data read(PW): ".$my_string."\n";
shmop_close($shm_id);

?>
 


Can you please show how to do this.


Sample from WORDPRESS - I would like to use a similar security for my mod harbourPress.

Best regards,
Otto

Code: Select all  Expand view


function require_wp_db() {
    global $wpdb;


// Erstelle einen 100 Byte grossen gemeinsam genutzten Speicherblock
// mit mit der System_ID if 0xff3
$shm_id = shmop_open(0xff3, "c", 0644, 100);
if(!$shm_id) {
        echo "Konnte kein gemeinsames Speichersegment erstellen\n";
}

// Hole die Gr�sse des gemeinsamen Speicherblocks
$shm_size = shmop_size($shm_id);
echo "SHM Block mit: ".$shm_size. " Bytes wurde erstellt.\n";

// Den Teststring wieder auslesen
$my_string = shmop_read($shm_id, 0, $shm_size);
if(!$my_string) {
        echo "Konnte nicht aus dem gemeinsamen Speicher lesen\n";
}
echo "Die D a t e n im gemeinsamen Speicher waren (PW): |".$my_string."|\n";

// Den Speicherblock l�schen und den gemeinsamen Speicher schliessen
if(!shmop_delete($shm_id)) {
        echo "Konnte den gemeinsamen Speicherblock nicht zum L�schen markieren.";
}
shmop_close($shm_id);




    require_once( ABSPATH . WPINC . '/wp-db.php' );
    if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
        require_once( WP_CONTENT_DIR . '/db.php' );

    if ( isset( $wpdb ) ) {
        return;
    }

    $wpdb = new wpdb( DB_USER, $my_string , DB_NAME, DB_HOST );
}

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Create or open a shared memory block

Postby Antonio Linares » Sun May 24, 2020 6:00 am

Dear Otto,

https://stackoverflow.com/questions/16739533/windows-shared-memory-segments

Ok, here we have the full explanation and a working example:
https://nullprogram.com/blog/2016/04/10/

Thinking how to port this into mod_harbour :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Create or open a shared memory block

Postby Otto » Sun May 24, 2020 10:13 am

Dear Antonio,
thank you so much.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Create or open a shared memory block

Postby Antonio Linares » Mon May 25, 2020 8:57 am

Dear Otto,

I have implemented a first version that is much easier to use (xbase style), you can download it from here:
https://github.com/FiveTechSoft/mod_harbour/blob/master/windows/win64/libharbour.dll
https://github.com/FiveTechSoft/mod_harbour/blob/master/windows/win64/mod_harbour.so

The implementation is quite easy:

MWrite( "pwd", "my password" ) // memory write
? MRead( "pwd" ) // memory read

from other browser tab or another user:
? MRead( "pwd" )

There is also a new MErase( "pwd" ) but it is not working fine yet
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Create or open a shared memory block

Postby Otto » Mon May 25, 2020 10:21 am

Dear Antonio,

Thank you. I will update my mod and test.
This opens so many possibilities.

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 3 guests