summaryrefslogtreecommitdiffstats
path: root/ldap/admin/src/namegen.c
diff options
context:
space:
mode:
authorcvsadm <cvsadm>2005-01-21 00:44:34 +0000
committercvsadm <cvsadm>2005-01-21 00:44:34 +0000
commitb2093e3016027d6b5cf06b3f91f30769bfc099e2 (patch)
treecf58939393a9032182c4fbc4441164a9456e82f8 /ldap/admin/src/namegen.c
downloadds-ldapserver7x.tar.gz
ds-ldapserver7x.tar.xz
ds-ldapserver7x.zip
Moving NSCP Directory Server from DirectoryBranch to TRUNK, initial drop. (foxworth)ldapserver7x
Diffstat (limited to 'ldap/admin/src/namegen.c')
-rw-r--r--ldap/admin/src/namegen.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/ldap/admin/src/namegen.c b/ldap/admin/src/namegen.c
new file mode 100644
index 00000000..6fc6d22f
--- /dev/null
+++ b/ldap/admin/src/namegen.c
@@ -0,0 +1,107 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/* namegen.c - utility program to generate name *
+ * of backup files in the format YYYY_MM_DD_HMS *
+ * and set it up as an environment variable to *
+ * be used by batch files on NT *
+ * *
+ * to use it do the following in your batch file*
+ * namegen *
+ * call bstart *
+ * ....... *
+ * call bend *
+ * rm end.bat *
+ * *
+ * start and end are batch files generated by *
+ * name gen. *
+ * Example: ldif2db.bat */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <string.h>
+
+#define STARTFILE "bstart.bat"
+#define ENDFILE "bend.bat"
+#define CMD "set DATESTR=%0\n"
+
+
+int main (int argc, char **argv)
+{
+ char szDate [64];
+ char szDateFile [64];
+ char szCmd [256];
+ struct tm *sCurTime;
+ long lCurTime;
+ int rt;
+ FILE *fBatch;
+
+ time( &lCurTime );
+
+ sCurTime = localtime( &lCurTime );
+
+ strftime(szDate, sizeof (szDateFile), "%Y_%m_%d_%H%M%S",
+ sCurTime);
+
+ sprintf (szDateFile, "%s.bat", szDate);
+
+ /* create date batch file */
+ fBatch = fopen (szDateFile, "w");
+ if (fBatch == NULL)
+ {
+ perror ("Unable to create date file!");
+ exit (1);
+ }
+
+ rt = fwrite (CMD, strlen (CMD), 1, fBatch);
+ if (rt != 1)
+ {
+ perror ("Unable to write date file\n");
+ exit (1);
+ }
+
+ fclose (fBatch);
+
+ /* create bstart.bat that executest date batch file */
+ fBatch = fopen (STARTFILE, "w");
+ if (fBatch == NULL)
+ {
+ perror ("Unable to bstart file!");
+ exit (1);
+ }
+
+ sprintf (szCmd, "call %s", szDate);
+
+ rt = fwrite (szCmd, strlen (szCmd), 1, fBatch);
+ if (rt != 1)
+ {
+ perror ("Unable to write bstart file\n");
+ exit (1);
+ }
+
+ fclose (fBatch);
+
+ /* create bstart.bat that executest date batch file */
+ fBatch = fopen (ENDFILE, "w");
+ if (fBatch == NULL)
+ {
+ perror ("Unable to bend file!");
+ exit (1);
+ }
+
+ sprintf (szCmd, "del %s\ndel bstart.bat\nset DATESTR=", szDateFile);
+
+ rt = fwrite (szCmd, strlen(szCmd), 1, fBatch);
+ if (rt != 1)
+ {
+ perror ("Unable to write bend file\n");
+ exit (1);
+ }
+
+ fclose (fBatch);
+
+ return 0;
+}