D3 and mvBase

 View Only
  • 1.  forking _CP_logon

    Posted 01-25-2022 13:18
    Hopefully this is the right forum for this question.  Has anyone used fork (or forkpty) and successfully called _CP_logon from inside of a C program?  Is there a trick to making this work? When I try it, the child dies with a segfault somewhere in pick_init_termio in a call to strcpy.

    ------------------------------
    Tom Marracci
    General Manager
    Aircraft Spruce
    corona CA US
    ------------------------------


  • 2.  RE: forking _CP_logon

    ROCKETEER
    Posted 01-25-2022 13:56
    Got small example code? I can then ask somebody.

    ------------------------------
    Brian S. Cram
    Principal Technical Support Engineer
    Rocket Software
    ------------------------------



  • 3.  RE: forking _CP_logon

    Posted 01-25-2022 14:14
    Hi Brian,

    I guess the post went through after all. I couldn’t see it on the list of open threads

    Here’s a snippet:

    int master;
    pid_t pid = forkpty(&master,0,0,0);
    if (pid > 0) {
    int stat = 0;
    waitpid(pid,&stat,0);
    return stat != 0;
    }
    MimeRunner rr(&r);
    if (c.login(config->machine, config->user, config->password, config->account, config->account_password)) {
    c.run(rr);
    c.logout();
    exit(r.send(200,"OK",getContentType(),rr.c_str(),rr.size()));
    } else {
    exit(r.send(500,"SERVER ERROR","text/html","",13));
    }


    and the login method in the c object (which I have as class called Runtime) is:

    int Runtime::login(const char* machine, const char* user, const char* psw, const char* acct, const char* apsw)
    {
    CPSTR* m = _CP_mkstr((char*)machine);
    CPSTR* u = _CP_mkstr((char*)user);
    CPSTR* p = psw[0] ? _CP_mkstr((char*)psw) : _CP_str_null;
    CPSTR* a = _CP_mkstr((char*)acct);
    CPSTR* w = apsw[0] ? _CP_mkstr((char*)apsw) : _CP_str_null;

    int n = _CP_logon(m,u,p,a,w,-1,0);

    _CP_str_free(m);
    _CP_str_free(u);
    _CP_str_free(a);
    if (psw[0]) _CP_str_free(p);
    if (apsw[0]) _CP_str_free(w);
    return n>-1;
    }

    When I run it, _CP_logon never returns, but instead the child dies. I’ve run it with gdb and from the stack trace it shows it dies in strcpy() called from pick_init_termio(). The session does not need to be user interactive. I’m trying to use it as a database connection with basic calling and access to standard D3 functions via the _CP_ api. The program is owned by root with the +s option set.


    Any advice would be most appreciated.

    Tom


    > On Jan 25, 2022, at 10:58 AM, Brian Cram via Rocket Forum <mail@forum.rocketsoftware.com> wrote:
    >
    > Invite your colleagues to join the Rocket Forum and grow our expert network.
    > <https: community.rocketsoftware.com/="">
    > D3 and mvBase <https: community.rocketsoftware.com/forums/forum-home/digestviewer?tab="digestviewer&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b">
    > Post New Message Online <http: community.rocketsoftware.com/participate/postmessage?groupid="55">
    > Invite your colleagues to join the Rocket Forum and grow our expert network. Share this link. <https: community.rocketsoftware.com/register="">
    > Re: forking _CP_logon <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=4e2ed5fe-098a-45ae-8ec7-0433c806beba">
    > Reply to Group Online <https: community.rocketsoftware.com/forums/all-discussions/postreply?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&ListKey=365735ee-5669-4857-ac99-8f7ea2cb2c9d"> Reply to Group <mailto:rocket_d3andmvbase_4e2ed5fe-098a-45ae-8ec7-0433c806beba@connectedcommunity.org?subject=re:%20forking%20_cp_logon>
    > <https: community.rocketsoftware.com/network/members/profile?userkey="12bb05f9-486d-4acf-93d3-6ac050875652">
    > Jan 25, 2022 1:56 PM
    > Brian Cram <https: community.rocketsoftware.com/network/members/profile?userkey="12bb05f9-486d-4acf-93d3-6ac050875652">
    > Got small example code? I can then ask somebody.
    >
    > ------------------------------
    > Brian S. Cram
    > Principal Technical Support Engineer
    > Rocket Software
    > ------------------------------
    > Reply to Group Online <https: community.rocketsoftware.com/forums/all-discussions/postreply?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&ListKey=365735ee-5669-4857-ac99-8f7ea2cb2c9d"> View Thread <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=4e2ed5fe-098a-45ae-8ec7-0433c806beba"> Recommend <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=4e2ed5fe-098a-45ae-8ec7-0433c806beba&cmd=rate&cmdarg=add"> Forward <https: community.rocketsoftware.com/forums/all-discussions/forwardmessages?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&ListKey=365735ee-5669-4857-ac99-8f7ea2cb2c9d"> Flag as Inappropriate <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=4e2ed5fe-098a-45ae-8ec7-0433c806beba&MarkAppropriate=4e2ed5fe-098a-45ae-8ec7-0433c806beba"> Post New Message Online <http: community.rocketsoftware.com/participate/postmessage?groupid="55">
    > -------------------------------------------
    > Original Message:
    > Sent: 01-25-2022 13:00
    > From: Tom Marracci
    > Subject: forking _CP_logon
    >
    > Hopefully this is the right forum for this question. Has anyone used fork (or forkpty) and successfully called _CP_logon from inside of a C program? Is there a trick to making this work? When I try it, the child dies with a segfault somewhere in pick_init_termio in a call to strcpy.
    >
    > ------------------------------
    > Tom Marracci
    > General Manager
    > Aircraft Spruce
    > corona CA US
    > ------------------------------
    >
    >
    >
    >
    > You are receiving this message because you followed the 'forking _CP_logon' message thread. To unsubscribe from this message thread, go to Unsubscribe <https: community.rocketsoftware.com/higherlogic/common/unfollow.aspx?userkey="be3cdfc2-ad06-43d5-8ba7-699e69103658&sKey=KeyRemoved&ItemKey=7b81e67f-d20f-434e-98eb-59400620e1a9">.
    > Update your email preferences <https: community.rocketsoftware.com/go.aspx?c="Preferences§ion=email"> to choose the types of email you receive
    >
    > Unsubscribe from all participation emails <https: community.rocketsoftware.com/higherlogic/egroups/unsubscribe.aspx?userkey="be3cdfc2-ad06-43d5-8ba7-699e69103658&sKey=KeyRemoved&mClass=Social">




  • 4.  RE: forking _CP_logon

    Posted 01-25-2022 14:41
    Brian,

    A little more to this story.

    When I run the code provided from within my program (which actually forks as a server and then forks child processes to logon) I get the break where I said it was.

    When I run it standalone, it still does not return from _CP_logon, but instead heads to a bash shell before dying. Not the same error, but the same effect. Maybe that’s a clue to the cure.

    here’s another snippet that still does not work:

    #include <stdio.h>
    #include <sys types.h="">
    #include <pty.h>
    #include <cpuser.h>

    int main()
    {
    int m;
    pid_t pid;

    pid = forkpty(&m,0,0,0);
    if (pid == 0) {
    int n = _CP_logon(_CP_mkstr(“pick0”),_CP_mkstr(“DM”),_CP_str_null,_CP_mkstr(“DM”),_CP_str_null,-1,0); // this never returns
    printf(“logon returned %d\r\n”,n);
    if (n > -1) _CP_logoff();
    } else {
    m = 0;
    waitpid(pid,&m,0);
    }

    return 0;
    }

    However, if I remove the forking and run it like:

    int main()
    {
    int n = _CP_logon(_CP_mkstr(“pick0”),_CP_mkstr(“DM”),_CP_str_null,_CP_mkstr(“DM”),_CP_str_null,-1,0);
    printf(“logon returned %d\r\n”,n);
    if (n > -1) _CP_logoff();

    return 0;
    }

    it works fine
    Tom


    > On Jan 25, 2022, at 10:58 AM, Brian Cram via Rocket Forum <mail@forum.rocketsoftware.com> wrote:
    >
    > Invite your colleagues to join the Rocket Forum and grow our expert network.
    > <https: community.rocketsoftware.com/="">
    > D3 and mvBase <https: community.rocketsoftware.com/forums/forum-home/digestviewer?tab="digestviewer&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b">
    > Post New Message Online <http: community.rocketsoftware.com/participate/postmessage?groupid="55">
    > Invite your colleagues to join the Rocket Forum and grow our expert network. Share this link. <https: community.rocketsoftware.com/register="">
    > Re: forking _CP_logon <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=4e2ed5fe-098a-45ae-8ec7-0433c806beba">
    > Reply to Group Online <https: community.rocketsoftware.com/forums/all-discussions/postreply?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&ListKey=365735ee-5669-4857-ac99-8f7ea2cb2c9d"> Reply to Group <mailto:rocket_d3andmvbase_4e2ed5fe-098a-45ae-8ec7-0433c806beba@connectedcommunity.org?subject=re:%20forking%20_cp_logon>
    > <https: community.rocketsoftware.com/network/members/profile?userkey="12bb05f9-486d-4acf-93d3-6ac050875652">
    > Jan 25, 2022 1:56 PM
    > Brian Cram <https: community.rocketsoftware.com/network/members/profile?userkey="12bb05f9-486d-4acf-93d3-6ac050875652">
    > Got small example code? I can then ask somebody.
    >
    > ------------------------------
    > Brian S. Cram
    > Principal Technical Support Engineer
    > Rocket Software
    > ------------------------------
    > Reply to Group Online <https: community.rocketsoftware.com/forums/all-discussions/postreply?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&ListKey=365735ee-5669-4857-ac99-8f7ea2cb2c9d"> View Thread <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=4e2ed5fe-098a-45ae-8ec7-0433c806beba"> Recommend <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=4e2ed5fe-098a-45ae-8ec7-0433c806beba&cmd=rate&cmdarg=add"> Forward <https: community.rocketsoftware.com/forums/all-discussions/forwardmessages?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&ListKey=365735ee-5669-4857-ac99-8f7ea2cb2c9d"> Flag as Inappropriate <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="4e2ed5fe-098a-45ae-8ec7-0433c806beba&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=4e2ed5fe-098a-45ae-8ec7-0433c806beba&MarkAppropriate=4e2ed5fe-098a-45ae-8ec7-0433c806beba"> Post New Message Online <http: community.rocketsoftware.com/participate/postmessage?groupid="55">
    > -------------------------------------------
    > Original Message:
    > Sent: 01-25-2022 13:00
    > From: Tom Marracci
    > Subject: forking _CP_logon
    >
    > Hopefully this is the right forum for this question. Has anyone used fork (or forkpty) and successfully called _CP_logon from inside of a C program? Is there a trick to making this work? When I try it, the child dies with a segfault somewhere in pick_init_termio in a call to strcpy.
    >
    > ------------------------------
    > Tom Marracci
    > General Manager
    > Aircraft Spruce
    > corona CA US
    > ------------------------------
    >
    >
    >
    >
    > You are receiving this message because you followed the 'forking _CP_logon' message thread. To unsubscribe from this message thread, go to Unsubscribe <https: community.rocketsoftware.com/higherlogic/common/unfollow.aspx?userkey="be3cdfc2-ad06-43d5-8ba7-699e69103658&sKey=KeyRemoved&ItemKey=7b81e67f-d20f-434e-98eb-59400620e1a9">.
    > Update your email preferences <https: community.rocketsoftware.com/go.aspx?c="Preferences§ion=email"> to choose the types of email you receive
    >
    > Unsubscribe from all participation emails <https: community.rocketsoftware.com/higherlogic/egroups/unsubscribe.aspx?userkey="be3cdfc2-ad06-43d5-8ba7-699e69103658&sKey=KeyRemoved&mClass=Social">




  • 5.  RE: forking _CP_logon

    ROCKETEER
    Posted 01-25-2022 15:26
    Tom, I see you opened a case, and that was probably the smart move ( unless anyone else out there has ideas ??? Hint hint ??? ). So I'm going to take the content from here and post it in the case.

    ------------------------------
    Brian S. Cram
    Principal Technical Support Engineer
    Rocket Software
    ------------------------------



  • 6.  RE: forking _CP_logon

    Posted 01-25-2022 15:58
    cool beans.

    I replied to the cast with the missing content. I’ll include it here for you as well

    Here’s what was after the includes:

    int main()
    {
    int m;
    pid_t pid;

    pid = forkpty(&m,0,0,0);
    if (pid == 0) {
    int n = _CP_logon(_CP_mkstr(“pick0”),_CP_mkstr(“DM”),_CP_str_null,_CP_mkstr(“DM”),_CP_str_null,-1,0); // this never returns
    printf(“logon returned %d\r\n”,n);
    if (n > -1) _CP_logoff();
    } else {
    m = 0;
    waitpid(pid,&m,0);
    }

    return 0;
    }

    However, if I remove the forking and run it like:

    int main()
    {
    int n = _CP_logon(_CP_mkstr(“pick0”),_CP_mkstr(“DM”),_CP_str_null,_CP_mkstr(“DM”),_CP_str_null,-1,0);
    printf(“logon returned %d\r\n”,n);
    if (n > -1) _CP_logoff();

    return 0;
    }

    it works fine
    Tom

    > On Jan 25, 2022, at 12:28 PM, Brian Cram via Rocket Forum <mail@forum.rocketsoftware.com> wrote:
    >
    > Invite your colleagues to join the Rocket Forum and grow our expert network.
    > <https: community.rocketsoftware.com/="">
    > D3 and mvBase <https: community.rocketsoftware.com/forums/forum-home/digestviewer?tab="digestviewer&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b">
    > Post New Message Online <http: community.rocketsoftware.com/participate/postmessage?groupid="55">
    > Invite your colleagues to join the Rocket Forum and grow our expert network. Share this link. <https: community.rocketsoftware.com/register="">
    > Re: forking _CP_logon <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="826fac69-5fbf-45c3-9378-14967f7773ca&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=826fac69-5fbf-45c3-9378-14967f7773ca">
    > Reply to Group Online <https: community.rocketsoftware.com/forums/all-discussions/postreply?messagekey="826fac69-5fbf-45c3-9378-14967f7773ca&ListKey=365735ee-5669-4857-ac99-8f7ea2cb2c9d"> Reply to Group <mailto:rocket_d3andmvbase_826fac69-5fbf-45c3-9378-14967f7773ca@connectedcommunity.org?subject=re:%20forking%20_cp_logon>
    > <https: community.rocketsoftware.com/network/members/profile?userkey="12bb05f9-486d-4acf-93d3-6ac050875652">
    > Jan 25, 2022 3:26 PM
    > Brian Cram <https: community.rocketsoftware.com/network/members/profile?userkey="12bb05f9-486d-4acf-93d3-6ac050875652">
    > Tom, I see you opened a case, and that was probably the smart move ( unless anyone else out there has ideas ??? Hint hint ??? ). So I'm going to take the content from here and post it in the case.
    >
    > ------------------------------
    > Brian S. Cram
    > Principal Technical Support Engineer
    > Rocket Software
    > ------------------------------
    > Reply to Group Online <https: community.rocketsoftware.com/forums/all-discussions/postreply?messagekey="826fac69-5fbf-45c3-9378-14967f7773ca&ListKey=365735ee-5669-4857-ac99-8f7ea2cb2c9d"> View Thread <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="826fac69-5fbf-45c3-9378-14967f7773ca&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=826fac69-5fbf-45c3-9378-14967f7773ca"> Recommend <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="826fac69-5fbf-45c3-9378-14967f7773ca&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=826fac69-5fbf-45c3-9378-14967f7773ca&cmd=rate&cmdarg=add"> Forward <https: community.rocketsoftware.com/forums/all-discussions/forwardmessages?messagekey="826fac69-5fbf-45c3-9378-14967f7773ca&ListKey=365735ee-5669-4857-ac99-8f7ea2cb2c9d"> Flag as Inappropriate <https: community.rocketsoftware.com/forums/forum-home/digestviewer/viewthread?messagekey="826fac69-5fbf-45c3-9378-14967f7773ca&CommunityKey=7cdcd1ff-6009-4df2-8b8c-e5ea4293200b&tab=digestviewer&bm=826fac69-5fbf-45c3-9378-14967f7773ca&MarkAppropriate=826fac69-5fbf-45c3-9378-14967f7773ca"> Post New Message Online <http: community.rocketsoftware.com/participate/postmessage?groupid="55">
    > -------------------------------------------
    > Original Message:
    > Sent: 01-25-2022 14:41
    > From: Tom Marracci
    > Subject: forking _CP_logon
    >
    > Brian,
    >
    > A little more to this story.
    >
    > When I run the code provided from within my program (which actually forks as a server and then forks child processes to logon) I get the break where I said it was.
    >
    > When I run it standalone, it still does not return from _CP_logon, but instead heads to a bash shell before dying. Not the same error, but the same effect. Maybe that's a clue to the cure.
    >
    > here's another snippet that still does not work:
    >
    > #include <https: community.rocketsoftware.com/search?s="%23include&executesearch=true">
    >
    >
    >
    > You are receiving this message because you followed the 'forking _CP_logon' message thread. To unsubscribe from this message thread, go to Unsubscribe <https: community.rocketsoftware.com/higherlogic/common/unfollow.aspx?userkey="be3cdfc2-ad06-43d5-8ba7-699e69103658&sKey=KeyRemoved&ItemKey=7b81e67f-d20f-434e-98eb-59400620e1a9">.
    > Update your email preferences <https: community.rocketsoftware.com/go.aspx?c="Preferences§ion=email"> to choose the types of email you receive
    >
    > Unsubscribe from all participation emails <https: community.rocketsoftware.com/higherlogic/egroups/unsubscribe.aspx?userkey="be3cdfc2-ad06-43d5-8ba7-699e69103658&sKey=KeyRemoved&mClass=Social">




  • 7.  RE: forking _CP_logon

    Posted 01-25-2022 16:24

    hy... 

    i only one question... why do that ?

    you can have some improvements ? i never thought about using cp_logon for anything

    what are the beneficts ?



    ------------------------------
    Alberto Leal
    System Analyst
    Millano Distribuidora de Auto Pecas Ltda
    Varzea Grande MT BR
    ------------------------------



  • 8.  RE: forking _CP_logon

    Posted 01-25-2022 18:13
    This is for a web server ala php. That is, basic code will be compiled and intepreted on the fly with access to the D3 system of database and other functions available in basic.

    So, for example, you would make a page for url https://localhost/test.bas?custid=12345

    <DOCTYPE! html>
    <html>
    <head><title>Some Title</title><head>
    <body>
    <*
      print 'hello world<br>'
      print 'the time is ':oconv(time(),'mth'):'<br>'
      open 'customer' to customer else stop 201,'customer'
      read rec from customer,$_GET['custid'] else rec = ''
      print 'your customers details:'
      for i = 1 to 10
        print '[':i:'] ':htmlencode(rec<i>):'<br>'
      next i
    *>
    </body>
    </html>

    Easy access to the GET, POST, COOKIE, SESSION, and SERVER variables (like php), same syntax as pick basic (with some minor exceptions) and it's really fast and secured by SSL.  Compile time for the above script on my Linux VM is a  few microseconds, execution is on par with running basic within D3 on my Linux server.  

    So to get here, I have a server that preforks some number of worker processes (like apache) and the basic compiler does everything but input (this handled by the browser) and has extra functions like hashing (md5, sha1, sha256), simple AES encryption interface, json encode/decode, urlencode, htmlencode, and some other functions that I found I need but do not come with basic out of the box.  Akin to flash connect without a lot of extra software, licenses, and some other obstacles that I couldn't get around.  My only problem now is _CP_logon does not want to complete the logon process. It crashes half way through and just dies.

    ------------------------------
    Tom Marracci
    General Manager
    Aircraft Spruce
    corona CA US
    ------------------------------