Hi Brad,
The attached patch fix ticket 29:
- check whether the profile database already exists and return a
descriptive message.
- check whether the profile we attempt to create already exists
and return a descriptive message.
- catch CTRL-C signal and makes sure the profile is deleted if
the user press CTRL-C during the profile creation.
If it sounds good, I'll apply the patch later in the afternoon (~2-3
hours or late tonight).
Cheers,
Julien.
--
Julien Kerihuel
[EMAIL PROTECTED]
OpenChange Project Manager
GPG Fingerprint: 0B55 783D A781 6329 108A B609 7EF6 FE11 A35F 1F79
Index: utils/mapiprofile.c
===================================================================
--- utils/mapiprofile.c (revision 350)
+++ utils/mapiprofile.c (working copy)
@@ -22,6 +22,7 @@
#include <libmapi/libmapi.h>
#include <samba/popt.h>
+#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -31,6 +32,11 @@
static void mapiprofile_createdb(const char *profdb, const char *ldif_path)
{
enum MAPISTATUS retval;
+
+ if (access(profdb, F_OK) == 0) {
+ fprintf(stderr, "[ERROR] mapiprofile: %s already exists\n", profdb);
+ exit (1);
+ }
retval = CreateProfileStore(profdb, ldif_path);
if (retval != MAPI_E_SUCCESS) {
@@ -70,6 +76,21 @@
return (index);
}
+const char *g_profname;
+
+static void signal_delete_profile(const char *profname)
+{
+ enum MAPISTATUS retval;
+
+ fprintf(stderr, "CTRL-C catched ... Deleting profile\n");
+ if ((retval = DeleteProfile(g_profname)) != MAPI_E_SUCCESS) {
+ mapi_errstr("DeleteProfile", GetLastError());
+ }
+
+ (void) signal(SIGINT, SIG_DFL);
+ exit (1);
+}
+
static void mapiprofile_create(const char *profdb, const char *profname,
const char *pattern, const char *username,
const char *password, const char *address,
@@ -78,7 +99,12 @@
{
enum MAPISTATUS retval;
struct mapi_session *session = NULL;
+ struct mapi_profile profile;
+ /* catch CTRL-C */
+ g_profname = profname;
+ (void) signal(SIGINT, (sighandler_t) signal_delete_profile);
+
retval = MAPIInitialize(profdb);
if (retval != MAPI_E_SUCCESS) {
mapi_errstr("MAPIInitialize", GetLastError());
@@ -90,6 +116,13 @@
global_mapi_ctx->dumpdata = true;
}
+ /* Sanity check */
+ retval = OpenProfile(&profile, profname, NULL);
+ if (retval == MAPI_E_SUCCESS) {
+ fprintf(stderr, "[ERROR] mapiprofile: profile \"%s\" already exists\n", profname);
+ exit (1);
+ }
+
retval = CreateProfile(profname, username, password, flags);
if (retval != MAPI_E_SUCCESS) {
mapi_errstr("CreateProfile", GetLastError());
signature.asc
Description: This is a digitally signed message part
_______________________________________________ devel mailing list [email protected] http://mailman.openchange.org/listinfo/devel
