Novell Home

A simple sample of NWChangeObjectPassword()

From Developer Community

This sample demonstrates how to change a password with NWChangeObjectPassword(). It can be build as a Win32 program or as an NLM.

Sample Code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef __MWERKS__
#pragma ANSI_strict off
#endif
#include <nwcalls.h>
#include <nwclxcon.h>
#ifdef __MWERKS__
#pragma ANSI_strict reset
#endif

#if defined( __MWERKS__) && !defined( N_PLAT_NLM)
#define strupr(s) (_strupr(s),s)
#endif

int main( int argc, char* argv[]) {
  char const*   server_name;
  char const*   login_user_name;
  char const*   password;
  char const*   new_password;
  NWRCODE       rcode;
  NWCCODE       ccode;
  NWCONN_HANDLE conn_handle;
  if ( argc != 5) {
    printf( "Usage: %s <servername> <username> <password> <new password>\n", *argv);
    return EXIT_FAILURE;
  }
  ccode = NWCallsInit( NULL, NULL);
  if ( ccode != 0) {
    printf( "NWCallsInit failed, ccode = %x", ccode);
    return EXIT_FAILURE;
  }
  server_name     = strupr( *++argv);
  login_user_name = strupr( *++argv);
  password        = strupr( *++argv);
  new_password    = strupr( *++argv);
  rcode = NWCCOpenConnByName( 0,
                              server_name,
                              NWCC_NAME_FORMAT_BIND,
                              NWCC_OPEN_LICENSED,
                              NWCC_TRAN_TYPE_WILD,
                              &conn_handle);
  if ( rcode != 0) {
    printf( "NWCCOpenConnByName failed, rcode = %x", rcode);
    return EXIT_FAILURE;
  }
#ifdef N_PLAT_NLM
  ccode = NWLoginToFileServer( conn_handle, login_user_name, OT_USER, password);
  if ( ccode != 0) {
    printf( "NWLoginToFileServer failed, ccode = %x", ccode);
    NWCCCloseConn( conn_handle);
    return EXIT_FAILURE;
  }
#endif
  ccode = NWChangeObjectPassword( conn_handle, login_user_name, OT_USER, password, new_password);
  if ( ccode != 0) {
    printf( "NWChangeObjectPassword failed, ccode = %x", ccode);
    NWCCCloseConn( conn_handle);
    return EXIT_FAILURE;
  }
  NWCCCloseConn( conn_handle);
  NWCallsTerm( NULL);
  return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.