]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/shell-backends/passwd-shell.c
Merge remote branch 'origin/mdb.master'
[openldap] / servers / slapd / shell-backends / passwd-shell.c
index 1f035ca11eebcb0db4f57789d45b4adefb219998..803b1a0c459781cfd469b50e6d5d8f20d165ced5 100644 (file)
@@ -1,32 +1,49 @@
-/*
- passwd-shell.c - /etc/passwd shell-based backend for standalone ldap server
-
- Copyright (c) 1995 Regents of the University of Michigan.
- All rights reserved.
-
- Redistribution and use in source and binary forms are permitted
- provided that this notice is preserved and that due credit is given
- to the University of Michigan at Ann Arbor. The name of the University
- may not be used to endorse or promote products derived from this
- software without specific prior written permission. This software
- is provided ``as is'' without express or implied warranty.
-*/
+/* passwd-shell.c - passwd(5) shell-based backend for slapd(8) */
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2011 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* Portions Copyright (c) 1995 Regents of the University of Michigan.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of Michigan at Ann Arbor. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was originally developed by the University of Michigan
+ * (as part of U-MICH LDAP).
+ */
 
 
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <pwd.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/string.h>
+#include <ac/unistd.h>
+
+#include <pwd.h>
 
 #include <lber.h>
 #include <ldap.h>
 
 #include "shellutil.h"
-#include "passwd-shell.h"
-
 
 static void pwdfile_search LDAP_P(( struct ldop *op, FILE *ofp ));
 static struct ldentry *pw2entry LDAP_P(( struct ldop *op, struct passwd *pw ));
@@ -39,8 +56,6 @@ main( int argc, char **argv )
 {
     int                        c, errflg;
     struct ldop                op;
-    extern int         optind;
-    extern char                *optarg;
 
     if (( progname = strrchr( argv[ 0 ], '/' )) == NULL ) {
        progname = estrdup( argv[ 0 ] );
@@ -67,7 +82,7 @@ main( int argc, char **argv )
 
     if ( errflg || optind < argc ) {
        fprintf( stderr, "usage: %s [-d]\n", progname );
-       exit( 1 );
+       exit( EXIT_FAILURE );
     }
 
     debug_printf( "started\n" );
@@ -75,13 +90,13 @@ main( int argc, char **argv )
     (void) memset( (char *)&op, '\0', sizeof( op ));
 
     if ( parse_input( stdin, stdout, &op ) < 0 ) {
-       exit( 0 );
+       exit( EXIT_SUCCESS );
     }
 
     if ( op.ldop_op != LDOP_SEARCH ) {
        write_result( stdout, LDAP_UNWILLING_TO_PERFORM, NULL,
                "Command Not Implemented" );
-       exit( 0 );
+       exit( EXIT_SUCCESS );
     }
 
 #ifdef LDAP_DEBUG
@@ -90,7 +105,7 @@ main( int argc, char **argv )
 
     pwdfile_search( &op, stdout );
 
-    exit( 0 );
+    exit( EXIT_SUCCESS );
 }
 
 
@@ -110,8 +125,8 @@ pwdfile_search( struct ldop *op, FILE *ofp )
                    write_entry( op, entry, ofp );
                    break;
                }
-           } else if ( test_filter( op, entry )) {
-               write_entry( op, entry, ofp );
+           } else if ( test_filter( op, entry ) == LDAP_COMPARE_TRUE ) {
+                       write_entry( op, entry, ofp );
            }
            free_entry( entry );
        }
@@ -129,8 +144,6 @@ pw2entry( struct ldop *op, struct passwd *pw )
     struct ldattr      *attr;
     int                        i;
 
-    entry = (struct ldentry *) ecalloc( 1, sizeof( struct ldentry ));
-
     /* 
      * construct the DN from pw_name
      */
@@ -138,13 +151,19 @@ pw2entry( struct ldop *op, struct passwd *pw )
        /*
         * X.500 style DN
         */
-       sprintf( tmpbuf, "cn=%s, %s", pw->pw_name, op->ldop_suffixes[ 0 ] );
+       i = snprintf( tmpbuf, sizeof( tmpbuf ), "cn=%s, %s", pw->pw_name, op->ldop_suffixes[ 0 ] );
     } else {
        /*
         * RFC-822 style DN
         */
-       sprintf( tmpbuf, "%s@%s", pw->pw_name, op->ldop_suffixes[ 0 ] );
+       i = snprintf( tmpbuf, sizeof( tmpbuf ), "%s@%s", pw->pw_name, op->ldop_suffixes[ 0 ] );
+    }
+
+    if ( i < 0 || i >= sizeof( tmpbuf ) ) {
+        return NULL;
     }
+
+    entry = (struct ldentry *) ecalloc( 1, sizeof( struct ldentry ));
     entry->lde_dn = estrdup( tmpbuf );
 
     /*