/* chgpwd.c - NWDSChangeObjectPasswor() API demo Copyright (C) 2000 Petr Vandrovec This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Revision history: 1.00 2000, April 25 Petr Vandrovec Initial revision. 1.01 2001, February 23 Petr Vandrovec Added '-r' option. Feature request from Patrick Pollet. 1.02 2001, March 14 Patrick Pollet Added -T' option. Added errors code specific to password changing 1.03 2001, December 16 Petr Vandrovec const <-> non-const pointers cleanup Moved error codes to libncp. 1.04 2002 March 14 , Patrick Pollet try to fix absent context problem by retrieving Default context if it exists */ #ifdef N_PLAT_MSW4 #include #include #include #include #include #include #include #include "getopt.h" #define _(X) X typedef unsigned int u_int32_t; typedef unsigned long NWObjectID; typedef u_int32_t Time_T; #else #include #include #include #include #include #include #include #include #include "private/libintl.h" #define _(X) gettext(X) #endif static char *progname; static void usage(void) { fprintf(stderr, _("usage: %s [options]\n"), progname); } static void help(void) { printf(_("\n" "usage: %s [options]\n"), progname); printf(_("\n" "-h Print this help text\n" "-v value Context DCK_FLAGS value (default 0)\n" "-o object_name Name of object (default [Root])\n" "-c context_name Name of current context (default [Root])\n" "-C confidence DCK_CONFIDENCE value (default 0)\n" "-S server Server to start with (no default)\n" "-T tree NDS tree (no default)\n" "-P password Old password (default TEST)\n" "-n newpassword New password (default T2)\n" "-r Raw, do not uppercase passwords\n" "\n")); } #ifdef N_PLAT_MSW4 char* strnwerror(int dserr) { static char errc[200]; sprintf(errc, "error %u / %d / 0x%X", dserr, dserr, dserr); return errc; } #endif static const char* strnwerror2(int err) { return strnwerror(err); } /* Uppercase string. Do NOT write to string if all characters are uppercase, const uppercased strings (TEST, T2) may be passed to this function! */ static void safe_strupr(char* p) { while (*p) { if (islower(*p)) *p = toupper(*p); p++; } } int main(int argc, char *argv[]) { NWDSCCODE dserr; NWDSContextHandle ctx; NWCONN_HANDLE conn=NULL; const char* objectname = "[Root]"; char context[MAX_TREE_NAME_CHARS +1]=""; const char* server = NULL; const char* pwd = "TEST"; const char* newpwd = "T2"; char treeName[MAX_TREE_NAME_CHARS +1]=""; int opt; int raw = 0; u_int32_t ctxflag = 0; u_int32_t confidence = 0; #ifndef N_PLAT_MSW4 setlocale(LC_ALL, ""); bindtextdomain(NCPFS_PACKAGE, LOCALEDIR); textdomain(NCPFS_PACKAGE); #endif progname = argv[0]; NWCallsInit(NULL, NULL); #ifndef N_PLAT_MSW4 NWDSInitRequester(); #endif while ((opt = getopt(argc, argv, "h?o:c:v:S:C:P:n:T:r")) != EOF) { switch (opt) { case 'C': confidence = strtoul(optarg, NULL, 0); break; case 'o': objectname = optarg; break; //case 'c': // context = optarg; // break; case 'c': if (strlen(optarg)