Create or open a shared memory block

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!
Post Reply
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Create or open a shared memory block

Post by Otto »

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

********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Create or open a shared memory block

Post by Antonio Linares »

Otto,

For Windows you could use GlobalAlloc()
https://docs.microsoft.com/en-us/window ... lobalalloc

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

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Create or open a shared memory block

Post by Otto »

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

********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Create or open a shared memory block

Post by Antonio Linares »

Code: Select all

#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
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Create or open a shared memory block

Post by Otto »

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

<?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

<?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


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

********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Create or open a shared memory block

Post by Antonio Linares »

Dear Otto,

https://stackoverflow.com/questions/167 ... y-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
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Create or open a shared memory block

Post by Otto »

Dear Antonio,
thank you so much.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Create or open a shared memory block

Post by Antonio Linares »

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_har ... arbour.dll
https://github.com/FiveTechSoft/mod_har ... 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
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Create or open a shared memory block

Post by Otto »

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

********************************************************************
Post Reply