]> git.sur5r.net Git - openldap/blobdiff - clients/ud/edit.c
Don't depend error handling on exact resultCode.
[openldap] / clients / ud / edit.c
index 88fe0b613a54c463b18bbee5c3d155d3537a3cc4..30a2fb76a7363ff8184c964c7b059dd2439f5048 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Copyright (c) 1994  Regents of the University of Michigan.
  * All rights reserved.
@@ -13,7 +18,9 @@
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
+#include <sys/stat.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/signal.h>
 #include <ac/string.h>
 #include <ac/wait.h>
 #include <ac/unistd.h>
 
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
 #ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
 #endif
 #include <process.h>
 #endif
 
+#ifdef HAVE_IO_H
+#include <io.h>
+#endif
+
 #include <lber.h>
 #include <ldap.h>
-#include <ldapconfig.h>
+
+#include "ldap_defaults.h"
 #include "ud.h"
 
 static int  load_editor( void );
@@ -40,7 +58,7 @@ static int  print_attrs_and_values( FILE *fp, struct attribute *attrs, short fla
 static int  ovalues( char *attr );
 static void write_entry( void );
 
-static char *entry_temp_file;
+static char entry_temp_file[L_tmpnam];
 
 
 void
@@ -93,7 +111,7 @@ edit( char *who )
        }
        dn = ldap_get_dn(ld, ldap_first_entry(ld, mp));
        rdns = ldap_explode_dn(dn, TRUE);
-       Free(dn);
+       ldap_memfree(dn);
        if (verbose) {
                printf("\n  Editing directory entry \"%s\"...\n", *rdns);
        }
@@ -113,7 +131,7 @@ load_editor( void )
 {
        FILE *fp;
        char *cp, *editor = UD_DEFAULT_EDITOR;
-       static char template[MED_BUF_SIZE];
+       int tmpfd;
 #ifndef HAVE_SPAWNLP
        int pid;
        int status;
@@ -126,13 +144,16 @@ load_editor( void )
 #endif
 
        /* write the entry into a temp file */
-       (void) strcpy(template, "/tmp/udEdit.XXXXXX");
-       if ((entry_temp_file = mktemp(template)) == NULL) {
-               perror("mktemp");
-               return(-1);
+       if (tmpnam(entry_temp_file) == NULL) {
+               perror("tmpnam");
+               return -1;
        }
-       if ((fp = fopen(entry_temp_file, "w")) == NULL) {
-               perror("fopen");
+       if ((tmpfd = open(entry_temp_file, O_WRONLY|O_CREAT|O_EXCL, 0600)) == -1) {
+               perror(entry_temp_file);
+               return -1;
+       }
+       if ((fp = fdopen(tmpfd, "w")) == NULL) {
+               perror("fdopen");
                return(-1);
        }
        fprintf(fp, "## Directory entry of %s\n", Entry.name);
@@ -187,7 +208,7 @@ load_editor( void )
        }
        else if (pid > 0) {
                /* parent - wait until the child proc is done editing */
-               void (*handler)();
+               RETSIGTYPE (*handler)();
                handler = SIGNAL(SIGINT, SIG_IGN);
                (void) wait(&status);
                (void) SIGNAL(SIGINT, handler);
@@ -265,8 +286,8 @@ write_entry( void )
                cp = line;
                if (*cp == '#')
                        continue;
-               if (isspace(*cp)) {     /* value */
-                       while (isspace(*cp))
+               if (isspace((unsigned char)*cp)) {      /* value */
+                       while (isspace((unsigned char)*cp))
                                cp++;
                        values[number_of_values++] = strdup(cp);
                        if ( number_of_values >= MAX_VALUES ) {
@@ -276,7 +297,7 @@ write_entry( void )
                        continue;
                }
                /* attribute */
-               while (isspace(*cp))
+               while (isspace((unsigned char)*cp))
                        cp++;
                /*
                 *  If the number of values is greater than zero, then we