This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

how to change or add user account for HTTP server in runtime ?

Other Parts Discussed in Thread: EK-TM4C1294XL

Hi All, 

I have encountered user account issue on HTTP server.

I can initialize user account by adding following code at .cfg file

====

var admin = new Global.Account();
admin.username = "admin";
admin.password = "admin";
Global.addUserAccount(admin);

======

This could be initial account, but I think admin could add user account or change account info at runtime.

I have tried following code added at  AddWebFiles(), but not working.

and I have tried with REALM1 -> REALM2, still not working. 

only admin/admin is OK.

======

CI_ACCT CA;
int rc;
HANDLE hCfg;

hCfg = CfgGetDefault();

// Creates the Authorization Realm 1
rc = CfgAddEntry(hCfg, CFGTAG_SYSINFO, CFGITEM_SYSINFO_REALM1, 0, 7, (UINT8 *)"REALM1", 0);

strcpy(CA.Username, "user");
strcpy(CA.Password, "0123");
CA.Flags = CFG_ACCTFLG_CH1; // Adds the user the the Realm 1
rc = CfgAddEntry(hCfg, CFGTAG_ACCT, CFGITEM_ACCT_REALM, 0, sizeof(CI_ACCT), (UINT8 *)&CA, 0);

======

How can I add or change user account info for HTTP server in runtime ?

Thanks in advance.

Best Regards,

Hae Ryong

  • Hae Ryong,
    your code seems correct and should be adding a new user to Realm 1. How do you know it's not working? Are you trying to access some files? Can you show that code and how is it failing?
  • Hello Sasha, 

    Thanks for your feedback.

    I have used protected root page, so when I connected the page, then login window is appeared.

    I have tested both accounts to log in, but only admin/admin is OK

    following is the code for AddWebFiles()

    static int OurRealm = 1;
    
    void AddWebFiles(Void)
    {
        void *pFxn;
        CI_ACCT CA;
        int rc;
        HANDLE hCfg;
    
        hCfg = CfgGetDefault();
    
        // Creates the Authorization Realm 1
        rc = CfgAddEntry(hCfg, CFGTAG_SYSINFO, CFGITEM_SYSINFO_REALM1, 0, 7, (UINT8 *)"REALM1", 0);
    
        strcpy(CA.Username, "user");
        strcpy(CA.Password, "0123");
        CA.Flags = CFG_ACCTFLG_CH1;	// Adds the user the the Realm 1
        rc = CfgAddEntry(hCfg, CFGTAG_ACCT, CFGITEM_ACCT_REALM, 0, sizeof(CI_ACCT), (UINT8 *)&CA, 0);
    
        //Note: both INDEX_SIZE and INDEX are defined in index.h
        efs_createfile("index.html", INDEX_SIZE, (UINT8 *)INDEX);
        efs_createfile("dspchip.gif", DSPCHIP_SIZE, (UINT8 *)DSPCHIP);
        efs_createfile("logobar.gif", LOGOBAR_SIZE, (UINT8 *)LOGOBAR);
        efs_createfile("main.html", MAIN_SIZE, (UINT8 *)MAIN);
        efs_createfile("blink_led.html", BLINK_SIZE, (UINT8 *)BLINK);
        efs_createfile("%R%", 4, (UINT8 *)&OurRealm );
        efs_createfile("sample.htm", SAMPLE_SIZE, (UINT8 *)SAMPLE);
        pFxn = (void*) &cgiSample;
        efs_createfile("sample.cgi", 0, (UINT8*) pFxn);
        pFxn = (void*) &cgiSampleMulti;
        efs_createfile("sample_multi.cgi", 0, (UINT8*) pFxn);
    }

    this is just sample code for testing HTTP server. 

    please let me know anything I need to do for further checking.

    Best Regards,

    Hae Ryong

  • Hae Ryong,
    I don't see any problems with your code. I'll have to ask someone who knows more about NDK. In the meantime, can you tell us if you use your own version of efs_filecheck or you are using the default implementation?
  • Hello Sasha,

    Thanks for your response.

    I don't implement efs function of my own. I'm using default one.

    if you recommend to implement my own version, please let know how to remove default one.

    would you please give some explanation about following code at cfg file ?

    var admin = new Global.Account();
    admin.username = "admin";
    admin.password = "admin";
    Global.addUserAccount(admin);

    If I remove this code, then I can't log on HTTP server.

    Is this actual user account for HTTP server ?

    I think user account for HTTP should be variable of http module, but this is the one of Global module.

    I am just curious about it.

    Thanks for your concern, 

    please let me know your further investigation.

    Best Regards,

    Hae Ryong

  • Hi Sasha,

    There is one more thing to ask.
    I have checked return value of CfgAddEntry(), it is 0.
    Is it OK or NOK ?

    Best Regards,
    Hae Ryong
  • Hi Hae Ryong

    I'll try to reproduce your problem tomorrow. What device are you using? Also what software (e.g. TI-RTOS  or SYS/BIOS & NDK) are you using? What are the version(s)?

    Thanks,

    Todd

  • Hi Todd,

    Thanks for your response, I'm glad to hear that.
    Board is EK-TM4C1294XL and tirtos_tivac_2_16_01_14 is used.
    If you need more information, just let me know.

    Best Regards,
    Hae Ryong
  • Hi Todd, 

    I have tested more about user account.

    I have added following snippet in IP address hook function

        HANDLE  hAcct;
        CI_ACCT CA;
        int     rc;
        int     size, count;
    
    	count = CfgGetEntryCnt( 0, CFGTAG_ACCT, CFGITEM_ACCT_REALM );
    	Log_info1(" CfgGetEntryCnt : count=%d", count);
    
        rc = CfgGetEntry( 0, CFGTAG_ACCT, CFGITEM_ACCT_REALM, 1, &hAcct );
        Log_info1(" CfgGetEntry : rc=%d", rc);
        if(rc > 0)
        {
        	size = sizeof(CA);
        	rc = CfgEntryGetData( hAcct, &size, (UINT8 *)&CA );
        	if(rc > 0)
        	{
        		Log_info4(" username %d %d %d %d", CA.Username[0], CA.Username[1], CA.Username[2], CA.Username[3]);
        		Log_info4(" password %d %d %d %d", CA.Password[0], CA.Password[1], CA.Password[2], CA.Password[3]);
        	}
    
        	memset(CA.Username, 0, CFG_ACCTSTR_MAX);
        	memset(CA.Password, 0, CFG_ACCTSTR_MAX);
            strcpy(CA.Username, "user" );
            strcpy(CA.Password, "0000" );
            CA.Flags = CFG_ACCTFLG_CH1;
            rc = CfgEntrySetData(hAcct, size, (UINT8 *)&CA);
            Log_info1(" CfgEntrySetData : rc=%d", rc);
        }
    
        rc = CfgGetEntry( 0, CFGTAG_ACCT, CFGITEM_ACCT_REALM, 1, &hAcct );
        Log_info1(" CfgGetEntry : rc=%d", rc);
        if(rc > 0)
        {
        	size = sizeof(CA);
        	rc = CfgEntryGetData( hAcct, &size, (UINT8 *)&CA );
        	if(rc > 0)
        	{
        		Log_info4(" username %d %d %d %d", CA.Username[0], CA.Username[1], CA.Username[2], CA.Username[3]);    		
        		Log_info4(" password %d %d %d %d", CA.Password[0], CA.Password[1], CA.Password[2], CA.Password[3]);
        	}
        }

    I could see username and password are changed correctly from the log.

    but I could not log in with old and new account  neither.

    I can't understand the situation.

    Can I add any log messages in HTTP authentication process ?

    Best Regards,

    Hae Ryong

  • Hi Hae Ryong,

    First of all, you cannot add the user/password in the AddWebFiles() function. You have this setup for a stackInitHook. This is called earlier in the NDK startup. You'll notice that the CfgGetDefault() function returned NULL. The default had not been setup yet. So the CfgAddEntry was garbage. The user/password that were setup in the .cfg where in generated code that was called later during the NDK startup, so they worked.

    I had the following in the .cfg

    Global.networkOpenHook = "&users";

    Add then in a source file

    void users()
    {
       CI_ACCT CA;
       int rc;
       HANDLE hCfg;
      
       hCfg = CfgGetDefault();

       //Creates the Authorization Realm 1
       rc = CfgAddEntry(hCfg, CFGTAG_SYSINFO, CFGITEM_SYSINFO_REALM1, 0, 7, (UINT8 *)"REALM1", 0);

       strcpy(CA.Username, "foo");
       strcpy(CA.Password, "bar");
       CA.Flags = CFG_ACCTFLG_CH1; // Adds the user the Realm 1
       rc = CfgAddEntry(hCfg, CFGTAG_ACCT, CFGITEM_ACCT_REALM, 0, sizeof(CI_ACCT), (UINT8 *)&CA, 0);
    }

    This worked fine for me. Both foo/bar and admin/admin (from the .cfg) worked. If this does not work for you, please make a small sample project, clean it, export it and attach it on a reply.

    Todd

    stackInitHook

  • Hi Todd, 

    Thanks for your feedback.

    I have tried as you recommend, but it does not work.

    please take a look at my simplified project for this.

    2046.TM4C_http.zip

    network open hook function is located at net_util.c

    I could see following log with attached project, but both admin/admin and user/0000 did not work. Maybe something wrong with my project.

    #000004 [ 0.003 ] INFO: (../net_utils.c:161) CfgGetEntry : rc=0
    #000005 [ 0.003 ] INFO: (../net_utils.c:168) username 117 115 101 114
    #000006 [ 0.003 ] INFO: (../net_utils.c:169) password 48 48 48 48

    Best Regards,

    Hae Ryong

  • Hi Hae Ryong,

    I built your example and I reproduced the problem. It worked when I changed the following in NetworkTask.c and rebuilt the application.

    static int OurRealm = 2;
    to
    static int OurRealm = 1;

    Note: you are CA.Flags = CFG_ACCTFLG_CH1 when you add the entries. When you add the accounts in the .cfg, it defaults to realm1.

    Todd
  • Hi Todd, 

    Thank you very much.

    I can verify it works. 

    Best Regards,

    Hae Ryong.