Domino 9 und frühere Versionen > ND8: Entwicklung
c api - mit copydb.exe erzeugte DB lässt sich nicht öffnen?
LisaS:
Hallo,
Folgendes Problem versuche ich zu lösen:
Da per Lotusscript erzeugte Repliken nicht automatisch lokal Medium encrypted ist, versuche ich nun per C API das Problem zu umgehen.
Ich habe dafür das Beispiel copydb so geändert, dass die Quell-DB vom Server gewählt werden kann und zum erstellen der DB benutze ich
--- Code: ---NSFDbCreateExtended (output_path, DBCLASS_NOTEFILE, TRUE,DBCREATE_LOCALSECURITY,DBCREATE_ENCRYPT_MEDIUM,0)
--- Ende Code ---
statt
--- Code: ---NSFDbCreate (output_path, DBCLASS_NOTEFILE, FALSE)
--- Ende Code ---
Wenn ich nicht volle Admin-Rechte habe bricht das Programm irgendwo beim Kopieren der Dokumente
--- Code: ---NSFDbCopyNote
--- Ende Code ---
ab. Meldung.
--- Code: ---you are not authorised to perform this operation
--- Ende Code ---
.
Mit NotesPeek kann ich sehen, das nicht alle Dokumente kopiert wurden und auch nicht alle Design-Elemente.
Mit Admin-Rechten wird alles ohne Fehler kopiert, aber die DB lässt sich nicht öffnen, die selbe Fehler Meldung
--- Code: ---you are not authorised to perform this operation
--- Ende Code ---
.
Wo könnte das Problem liegen? - Gibt es eine andere Möglichkeit die Lokal-Encryption Medium zu setzten?
Grüße
Lisa
--- Code: ---/****************************************************************************
PROGRAM: copydb
FILE: copydb.c
PURPOSE: Create a replica copy of a Domino database.w
SYNTAX: copydb <input db> <output db> <output title>
or
copydb
****************************************************************************/
#if defined(OS400)
#pragma convert(850)
#endif
#define _CRT_SECURE_NO_WARNINGS
/* C and OS include files */
#include <stdio.h>
#include <string.h>
/* Lotus C API for Domino and Notes include files */
#include <global.h>
#include <stdnames.h>
#include <nsfdb.h>
#include <nsferr.h>
#include <nsfnote.h>
#include <misc.h>
#include <idtable.h>
#include <osmem.h>
#include <osmisc.h>
#include <osfile.h>
void LNPUBLIC ProcessArgs (int argc, char *argv[],
char *server_name,
char *file_name,
char *output_path,
char *output_title);
void PrintAPIError (STATUS);
#define STRING_LENGTH 256
/************************************************************************
FUNCTION: Main
PURPOSE: Lotus C API for Domino and Notes subroutine
*************************************************************************/
int main(int argc, char *argv[])
{
/*char input_path[STRING_LENGTH]; /* pathname of input database */
char server_name[STRING_LENGTH]; /* Server-Name */
char file_name[STRING_LENGTH]; /* Server-Name */
char fullpath_name[STRING_LENGTH]; /* Server-Name */
char output_path[STRING_LENGTH]; /* pathname of output database */
char output_title[NSF_INFO_SIZE]; /* title of output database */
char output_db_info[NSF_INFO_SIZE]; /* database info buffer */
DBHANDLE input_handle; /* handle of input database */
DBHANDLE output_handle; /* handle of output database */
DBID input_dbid; /* dbid of input database */
DBID output_dbid; /* dbid of output database */
DBREPLICAINFO replica_info; /* replication info for the databases */
TIMEDATE start_time; /* time and date used to control what
notes we copy */
TIMEDATE last_time; /* returned from
NSFDbGetModifiedNoteTable */
HANDLE idtable_p; /* handle to id table */
DWORD num_scanned, num_entries;
NOTEID note_id;
NOTEHANDLE hIconNote; /* handle to the icon note */
STATUS error = NOERROR; /* return status from API calls */
ProcessArgs (argc, argv,
server_name, file_name, output_path, output_title);
if (error = NotesInitExtended (argc, argv))
{
printf("\n Unable to initialize Notes.\n");
return (1);
}
/* Construct fully qualified path from components */
if (strlen(server_name))
{
if (error = OSPathNetConstruct(NULL, server_name,
file_name, fullpath_name))
{
PrintAPIError (error);
NotesTerm();
return (1);
}
}
else
strcpy(fullpath_name, file_name);
if (error = NSFDbOpen(fullpath_name, &input_handle))
{
PrintAPIError (error);
NotesTerm();
return (1);
}
/* Construct fully qualified path from components */
/* Open the input database. */
/* if (error = NSFDbOpen (input_path, &input_handle))
{
PrintAPIError (error);
NotesTerm();
return (1);
}
*/
printf("\nOpened \"%s\" as the input database", fullpath_name);
fflush(stdout);
/* Create and open the output database.
if (error = NSFDbCreate (output_path, DBCLASS_NOTEFILE, FALSE))
{
NSFDbClose (input_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}*/
/* Create and open the output database. RM - mit der option Medium Encrypted*/
if (error = NSFDbCreateExtended (output_path, DBCLASS_NOTEFILE, TRUE,DBCREATE_LOCALSECURITY,DBCREATE_ENCRYPT_MEDIUM,0))
{
NSFDbClose (input_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
if (error = NSFDbOpen (output_path, &output_handle))
{
NSFDbClose (input_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
printf("\nCreated \"%s\" as the output database", output_path);
fflush(stdout);
/* Copy the replication settings (not the replication history) from
the input database to the output database. The replication settings
include the database replica ID. This makes the destination database
a replica copy of the source database. */
if (error = NSFDbReplicaInfoGet (input_handle, &replica_info))
{
NSFDbClose (input_handle);
NSFDbClose (output_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
printf("\nGetReplicaINFO");
fflush(stdout);
if (error = NSFDbReplicaInfoSet (output_handle, &replica_info))
{
NSFDbClose (input_handle);
NSFDbClose (output_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
printf("\nSetReplicaINFO");
fflush(stdout);
/* Copy the ACL from the input database to the output database. */
if (error = NSFDbCopyACL (input_handle, output_handle))
{
NSFDbClose (input_handle);
NSFDbClose (output_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
printf("\nSNSFDbCopyACL");
fflush(stdout);
/* Set a time/date structure that will determine the date of the earliest
note copied in the next call. Use TimeConstant with TIMEDATE_WILDCARD
specified to indicate that we do not want any cutoff date. */
TimeConstant (TIMEDATE_WILDCARD, &start_time);
/* Do not use NSFDbCopy to copy all notes in the input database to the
output database. Such copies are not guaranteed to be replicas of
the original notes. Instead get an IDTABLE of all notes in the
database, use IDScan to obtain each NOTEID, and then call
NSFDbCopyNote to copy each note from one database to the other.
*/
NSFDbIDGet (input_handle, &input_dbid);
NSFDbIDGet (output_handle, &output_dbid);
printf("\nNSFDbIDGet");
fflush(stdout);
/* Get the NoteID table for all notes in the input database */
if (error = NSFDbGetModifiedNoteTable (input_handle,
NOTE_CLASS_ALL,
start_time, &last_time,
&idtable_p) )
if (error == ERR_NO_MODIFIED_NOTES)
printf ("There are no documents in the Database.\n");
else
{
NSFDbClose (input_handle);
NSFDbClose (output_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
printf("\nTestpunkt1");
fflush(stdout);
num_scanned = 0L;
num_entries = IDEntries (idtable_p);
if (num_entries)
while (IDScan (idtable_p, (FLAG)(num_scanned++ == 0), ¬e_id) )
if (error = NSFDbCopyNote (input_handle, NULL,
&replica_info.ID, note_id,
output_handle, &output_dbid,
&replica_info.ID, NULL,
NULL) )
{
IDDestroyTable (idtable_p);
NSFDbClose (input_handle);
NSFDbClose (output_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
printf("\nTestpunkt2");
fflush(stdout);
IDDestroyTable (idtable_p);
printf("\nDatabase documents copied");
fflush(stdout);
/* Now we can change the title of the output database
by following these steps:
- Get the info buffer of the database (NSFDbInfoGet);
- Modify the title information in the buffer (NSFDbInfoModify);
- Write the modified info buffer into the database (NSFDbInfoSet);
- If necessary, update the ICON note with the updated database
information buffer. This is required for databases created from
a template.
*/
/* Clear out the database information buffer */
output_db_info[0] = '\0';
/* Get the output database information buffer. */
if (error = NSFDbInfoGet (output_handle, output_db_info))
{
NSFDbClose (input_handle);
NSFDbClose (output_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
/* Add the database title to the database information buffer */
NSFDbInfoModify (output_db_info, INFOPARSE_TITLE, output_title);
if (error = NSFDbInfoSet (output_handle, output_db_info))
{
NSFDbClose (input_handle);
NSFDbClose (output_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
/* If creating a new database from a template, in order to change
the database title or any other component of the database information
buffer, you also need to update this information in the ICON
note after updating it in the database information buffer. */
if (!NSFNoteOpen(output_handle, NOTE_ID_SPECIAL+NOTE_CLASS_ICON,
0, &hIconNote))
{
/* Update the FIELD_TITLE ("$TITLE") field if present */
if (NSFItemIsPresent (hIconNote, FIELD_TITLE, (WORD) strlen (FIELD_TITLE)) )
{
NSFItemSetText(hIconNote, FIELD_TITLE, output_db_info, MAXWORD);
NSFNoteUpdate(hIconNote, 0);
}
NSFNoteClose(hIconNote);
}
/* if there was no ICON note, do nothing. */
printf("\nSet the title of \"%s\" to \"%s\"", output_path, output_title);
fflush(stdout);
/* Close the databases. */
if (error = NSFDbClose (input_handle))
{
NSFDbClose (output_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
if (error = NSFDbClose (output_handle))
{
PrintAPIError (error);
NotesTerm();
return (1);
}
printf("\n Done.\n");
fflush(stdout);
/* End of program. */
printf("\nProgram completed successfully.\n");
NotesTerm();
return (0);
}
/************************************************************************
FUNCTION: ProcessArgs
INPUTS: argc, argv - directly from the command line
OUTPUTS: input_path, output_path, output_title get data
from the command line or from what the user types
at a prompt
*************************************************************************/
void LNPUBLIC ProcessArgs (int argc, char *argv[],
char *server_name,
char *file_name,
char *output_path,
char *output_title)
{
if (argc != 5)
{
printf("Enter name of input Server: ");
fflush(stdout);
gets(server_name);
printf("Enter name of input database: ");
fflush(stdout);
gets(server_name);
printf("\n");
printf("Enter name of output database: ");
fflush(stdout);
gets(output_path);
printf("\n");
printf("Enter title of output database: ");
fflush(stdout);
gets(output_title);
}
else
{
strcpy(server_name, argv[1]);
strcpy(file_name, argv[2]);
strcpy(output_path, argv[3]);
strcpy(output_title, argv[4]);
} /* end if */
} /* ProcessArgs */
/*************************************************************************
FUNCTION: PrintAPIError
PURPOSE: This function prints the Lotus C API for Domino and Notes
error message associated with an error code.
**************************************************************************/
void PrintAPIError (STATUS api_error)
{
STATUS string_id = ERR(api_error);
char error_text[200];
WORD text_len;
/* Get the message for this Lotus C API for Domino and Notes error code
from the resource string table. */
text_len = OSLoadString (NULLHANDLE,
string_id,
error_text,
sizeof(error_text));
/* Print it. */
fprintf (stderr, "\n%s\n", error_text);
}
--- Ende Code ---
eknori:
Die Dokumemente haben Leser- und Autorenfelder?
Dann läuft das NSFDBCopyNote auf einen fehler, da idtable_p vermutlich ALLE ids der Dokumente enthält; auch die, auf die der User keine Berechtigung hat.
Bin jetzt nicht jede Zeile durchgegangen; aber warum kopierst du denn alle Dokumente aus der source DB ins target?
Es reicht doch den repl. Stumpf anzulegen.
Um genau zu sehen, wo das Problem liegt, baue mehr errorhandling ein, so dass der Fehler mit NoteID etc geloggt wird.
LisaS:
Hallo Ulrich,
danke für die fixe Antwort.
Ja die Dokumente haben Authors und Reader Felder.
Ich habe den Teil an dem Die Dokumente Kopiert werden rausgenommen.
Die Exe läuft jetzt durch und erstellt die DB. Leider kann ich sie im Notes Client nicht öffnen.
Fehlermeldung:
Sie sind nicht zum Zugriff auf diese Datenbank berechtigt.
Wenn ich per NotesPeek die DB anschaue sieht aber alles ganz ok aus. die ACL wurde kopiert.
Ich muss auch, bevor ich die DB in Peek anschauen kann, mein Notes Passwort eingeben.
Also hat die Encryption Medium hat geklappt.
Im übrigen ist es egal ob ich die Db mit NSFDbCreate oder NSFDbCreateExtended anlege, es kommt immer die Fehlermeldung.
Noch eine Idee?
Grüße
Lisa
LisaS:
Ok, ich glaube ich habs gefunden.
Der Teil mit der ACL kopieren ist dran schuld gewesen, das die DB nicht geöffnet werden konnte.
--- Code: ---if (error = NSFDbCopyACL (input_handle, output_handle))
{
NSFDbClose (input_handle);
NSFDbClose (output_handle);
PrintAPIError (error);
NotesTerm();
return (1);
}
--- Ende Code ---
Ich werde es so machen, wie Ulrich dass schon empfohlen hat und zwar die DB leer anlegen. und dann ausserhalb der exe replizieren.
Evtl. wäre es ja auch möglich über eine dll per LS die NSFDbCreateExtended zu nutzen, mir ist aber noch nicht ganz klar wie das funktioniert.
Wenn dazu jemand ein Paar Tips hätte....
Grüße
Lisa
pram:
hmm, also ich versuchs mal:
hier erst mal eine Doku:
http://www-12.lotus.com/ldd/doc/tools/c/6.0.2/api60ref.nsf/0/0CBDF63F19413F37852562A700582642?OpenDocument
aus
--- Code: ---STATUS LNPUBLIC NSFDbCreateExtended(
const char far *PathName,
WORD DbClass,
BOOL ForceCreation,
WORD Options,
BYTE EncryptStrength,
DWORD MaxFileSize);
--- Ende Code ---
müsste folgendes werden:
--- Code: ---Option Public
Option Declare
Declare Function W32_NSFDbCreateExtended Lib "NNOTES.DLL" Alias "NSFDbCreateExtended" (_
ByVal PathName As LMBCS String, _
ByVal DbClass As Integer, _
ByVal ForceCreation As Integer, _
ByVal Opts As Integer, _
ByVal EncryptStrength As Byte, _
ByVal MaxFileSize As Long) As Integer
' Konstanten (aus der nsfdb.h)
Const DBCLASS_NOTEFILE = &Hff01
Const DBCREATE_LOCALSECURITY = 1
Const DBCREATE_ENCRYPT_STRONG = 3
Sub initialize()
Dim ret%
ret = W32_NSFDbCreateExtended("myTestDb.nsf", DBCLASS_NOTEFILE, True, DBCREATE_LOCALSECURITY, DBCREATE_ENCRYPT_STRONG, 0)
If ret = 0 Then MsgBox "DB angelegt"
End Sub
--- Ende Code ---
hab das auch mal schnell getestet, scheint zu funktionieren ;)
Für das Setzen der ACL, erzeugen der DefaultViev etc.pp kann man dann LS verwenden
Gruß
Roland
Navigation
[0] Themen-Index
[#] Nächste Seite
Zur normalen Ansicht wechseln