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: 6419
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 43 times
Been thanked: 3 times
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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 42739
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 105 times
Been thanked: 108 times
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/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
Otto
Posts: 6419
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 43 times
Been thanked: 3 times
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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 42739
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 105 times
Been thanked: 108 times
Contact:

Re: Create or open a shared memory block

Post by Antonio Linares »

Code: Select all | Expand

#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: 6419
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 43 times
Been thanked: 3 times
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 | Expand

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

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

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 schliessenif(!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
Antonio Linares
Site Admin
Posts: 42739
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 105 times
Been thanked: 108 times
Contact:

Re: Create or open a shared memory block

Post by Antonio Linares »

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
Otto
Posts: 6419
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 43 times
Been thanked: 3 times
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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 42739
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 105 times
Been thanked: 108 times
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_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
Otto
Posts: 6419
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 43 times
Been thanked: 3 times
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
https://www.facebook.com/groups/modharbour.club
********************************************************************
Post Reply