#1 2012-02-24 09:02:57

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

DLL and SetUser

I have write 2 DLL to import/export data to/from my database.
When I call the DLL I export my database so the DLL can use it. The "import" library use only framework code, the "export" library use SELECT sql (ExecuteList) to select export field.

If my application is run as server or standalone application (use setUser as Admin), I can call the DLLs but I need use setUser as Admin inside DLL, in alternative the DLL is call but not work (I tested only "export" library that use SELECT sql).

If I try to call the DLL from my client application (use setUser as Supervisor) I have an exception when export the server to my DLL.

I have this problem after use the framework authentication system (without it all works)so:

1) Can only the administrator user export server to DLL?
2) Is there a way to allow my client to use my DLL?
3) Why inside my DLL I need set the user as Admin to call a simple SELECT sql Client.ExecuteList()? setUser as Supervisor DON'T PERMET USE sql to read the database?

Last edited by array81 (2012-02-24 14:45:56)

Offline

#2 2012-02-24 17:26:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: DLL and SetUser

I suspect you did not set the user on the dll client class.

This is difficult to guess what's wrong here - perhaps do you have some code to reproduce the issue?

Online

#3 2012-02-24 19:50:52

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: DLL and SetUser

Ok, this is the code of my application used to call the DLL

var
  fHND: THandle;
  DLLExport: TDLLExport;
begin
  if FileExists(AppPath + 'clexport.dll') then
    begin
      DatabaseServer.ExportServer;

      fHND := LoadLibrary(pChar(AppPath + 'clexport.dll'));

      try
        if fHND <> 0 then
          begin
            @DLLExport := getProcAddress(fHND, 'DLLExport');

            DLLExport(LanguageManager.Folder, LanguageManager.LanguageCode, URIRequest, '', '', '', '', '');
          end
        else
          begin
            MessageDlgLM('ContLab', MSG_DLLNOTLOAD + ' - clexport.dll', mtError, [mbOK]);
          end;
      finally
        if fHND <> 0 then
          FreeLibrary(fHND);
      end;
    end
  else
    begin
      MessageDlgLM('ContLab', MSG_DLLNOTFOUND + ' - clexport.dll', mtError, [mbOK]);
    end;

and this is the code of my DLL:

procedure DLLExport(LangPath, LangCode: string; MyURI: TURIMapRequest; SelectedProjects, SelectedContacts, SelectedAgenda, SelectedPasswords, SelectedNotes: string);
begin
  Client := TSQLRestClientURIDll.Create(GetDatabaseModel(), MyURI);
  //Client.SetUser('Supervisor', 'synopse');
  Client.SetUser('Admin', 'synopse');

  if client <> nil then
    begin

      ASelectedProjects   := SelectedProjects;
      ASelectedContacts   := SelectedContacts;
      ASelectedAgenda     := SelectedAgenda;
      ASelectedPasswords  := SelectedPasswords;
      ASelectedNotes      := SelectedNotes;

      ExportForm := TExportForm.Create(nil);
      try
        ExportForm.nbPages.ActivePageIndex := 0;

        ExportForm.ShowModal;
      finally
        ExportForm.Free;
      end;

      client.Free;

    end
  else
    begin
      //MessageDlg('CLIENT NIL',  mtConfirmation, [mbOK], 0);
    end;
end;

As you see I use setUser() inside DLL. If I use Admin I can use ExecuteList in alternative (if I use Supervisor) ExecuteList return nil object:

sql := 'SELECT Agenda.RecordCreated AS Created, Agenda.RecordModified AS Modified, Agenda.Title AS Title, Agenda.Place AS Place, Agenda.Priority AS Priority, ' + 'Agenda.Kind AS Kind, Agenda.Color AS Color, Agenda.Note AS Note, Agenda.DateFrom AS Date_From, Agenda.DateTo AS Date_To, Agenda.AllDay AS All_Day, ' + 'Agenda.Allarm AS Allarm, Agenda.AllarmKind AS Allarm_Kind, Agenda.AllarmWhen AS Allarm_Where, Agenda.AllarmWhenKind AS Allarm_When_Kind FROM Agenda';

Tabella := Client.ExecuteList([], sql);

Besides I can call the DLL (with the first code of this post) only if I use my application as administrator, if I try to call as supervisor I get an exception...

Any ideas?

Last edited by array81 (2012-03-07 14:42:53)

Offline

#4 2012-03-07 14:44:40

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: DLL and SetUser

Summarizing, I have 2 problem:
1) I need use administrator user to call the DLL. I cannot use it with other type of user (I have problem with supervisor user).
2) I need set administrator user inside the application to call a simple SELECT sql, the supervisor user infact return nil object.

so

1) Can I export the server to a DLL withy different user from Admin? (in my case with Supervisor )
2) I need setUser as Admin inside a DLL to call a SELECT sql?

Last edited by array81 (2012-03-07 14:44:55)

Offline

Board footer

Powered by FluxBB