Groups > Novell > NDS Client > Re: What is wrong read of login script




What is wrong read of login script

What is wrong read of login script
Sun, 27 Feb 2005 12:12:18 GMT
Hi,

getting nuts over this piece of code, why does it not work:

/****************************************************************************
*/

/*************************************************************************
** Macro Definitions
*/
#define BUFFER_SIZE 0x1000	/* 4k */

#define N_PLAT_WNT
/*************************************************************************
** Include header files
*/

/*---------------------------------------------------------------------
	** NLMSDK includes
	*/
	#include <stdlib.h>
	#include <stdio.h>
	#include <string.h>
	#include <conio.h>
	#include <nwdsapi.h>
	#include <nwdsmisc.h>
	#include <nwdsdc.h>
	#include <nwalias.h>
	#include <nwdsdsa.h>
	#include <nwmisc.h>
	#include <io.h>
	#include <errno.h>

/*************************************************************************
** DisplayUsage
*/
void DisplayUsage(void)
	{
	printf("Syntax:  start stream <object>\n");
	printf("Example: start stream .testuser.company\n");
	exit(0);
	}


/*************************************************************************
** main
*/
void main(int argc, char *argv[])
	{
	NWDSContextHandle	cx;
	NWDSCCODE	ccode;
	nuint32				flags;
	int	fp;
	LONG	length;
	char *buffer;

	if(argc!=2)
		{
		DisplayUsage();			/*display usage and
exit nlm*/
		}

/*------------------------------------------------------------------
	** Note that beginning with release 8 of the Novell SDK the
call to 
	** NWCallsInit() loads the unicode tables for you.
	*/	
	ccode = NWCallsInit(NULL, NULL);
	if (ccode)
		{
		printf("\nCall to NWCallsInit returned: %04X", ccode);
		exit(1);
		}

	ccode = NWDSCreateContextHandle(&cx);
	if (ccode)
		{
		printf("NWDSCreateContext returned: %04X\n", ccode);
		exit(ccode);
		}


/*-------------------------------------------------------------------
	** Get the current directory context flags so we can modify
them.
	*/

	ccode = NWDSGetContext(
				/* Contxt Handle    */ cx,
				/* Key              */ DCK_FLAGS,
				/* Context Flags    */ &flags
				);

	if (ccode < 0)
	{
		printf("NWDSGetContext returned: %04X\n", ccode);
      NWDSFreeContext(cx);
      exit(1);
   }


/*-------------------------------------------------------------------
	**   Turn typeless naming on.
	**   Turn canonicalize names off.  This means we will get full
names.
	*/

	flags |= DCV_TYPELESS_NAMES;
	flags &= ~DCV_CANONICALIZE_NAMES;


/*-------------------------------------------------------------------
	** Set the directory context flags so they take effect.
	*/

	ccode = NWDSSetContext(
				/* Context Handle */ cx,
				/* Key            */ DCK_FLAGS,
				/* Set Flag Value */ &flags
				);

	if (ccode < 0)
	{
		printf("NWDSSetContext returned: %04X\n", ccode);
		NWDSFreeContext(cx);
      exit(2);
	}


	ccode=NWDSOpenStream(
	/*NWDSContextHandle		context,	*/ cx,
	/*char		NWFAR *objectName,	*/	argv[1],
	/*char		NWFAR *attrName,		*/	"Login
Script",
	/*uint32	flags,
*/	DS_READ_STREAM,
	/*int		NWFAR *fileHandle			*/
(NWFILE_HANDLE *)&fp		);

	if(ccode)
		{
		printf("Error: NWDSOpenStream() %ld",ccode);
		goto Exit2;
		}

	buffer=malloc(BUFFER_SIZE+1);
	if(NULL==buffer)
		{
		printf("Error malloc of buffer.\n");
		goto Exit3;
		}
	/* read the login script and dump to screen */
	do{
		length=read(
      	/*int __handle,	*/	fp,
      	/*void *__buf,		*/	buffer,
      	/*LONG __len );	*/	BUFFER_SIZE	);
		if(-1 != length)
			*(buffer+length)='\0';
			printf("%s",buffer);
		}while(length==BUFFER_SIZE);
	if(-1 == length)	/* error has occured */
		{
		printf("Errno: during read() %ld\n",errno);
		}

	free(buffer);
Exit3:
	close(fp);
Exit2:
//	NWDSLogout(cx);
Exit1:
	NWDSFreeContext(cx);
	exit(0);
	}

Post Reply
Re: What is wrong read of login script
Sun, 27 Feb 2005 21:45:43 GMT
D.d. Sun, 27 Feb 2005 12:12:18 GMT, Alex Warmerdam
<alex.warmerdam@ngn.nl> schreef het volgende:

Hi,

Been looking around again, it seams that borlandc does not handle it
very well with read function, need to work it out with readfile
function.

Post Reply
Re: What is wrong read of login script - 1 attachment
Mon, 28 Feb 2005 14:28:38 GMT
Hi Alex,

Alex Warmerdam <alex.warmerdam@ngn.nl> wrote in 
news:fz8iQupQ=xsHx16NnGD94XoW3gmn@4ax.com:

> D.d. Sun, 27 Feb 2005 12:12:18 GMT, Alex Warmerdam
> <alex.warmerdam@ngn.nl> schreef het volgende:
> 
> Hi,
> 
> Been looking around again, it seams that borlandc does not handle it
> very well with read function, need to work it out with readfile
> function.
I'd suggest you take MingW32 instead; I have a couple of client32 apps 
successfully compiled with it; 
attached your sample compiled with MingW32 gcc, but I've not tested...

Guenter.


begin 644 readlscr.zip
M4$L#!!0````(``)[7#)PY6.#UP,``'T)```1````<F5A9&QS8W(O36%K969I
M;&6M5E%OHT80?HXE_X>YV"<%-;:)DWLXZQH%8^QRP6`9)U:DJM46%GN594&`

MCZ3_J/^RLPOAG,2GY*J^V,/WS3<[S,SNT@'K@<0IIQ"3>QHQ-*(D`Y<6:Y)1
M,#FCH@`C3=NMCF)V.862%5O8B)W2`!$AS)F8K<^'"MP$@73V:0'NY'IL^!84
M"3PFNPQ(FF9)FC%24$A)L?W0;K5;+!(AC9Y\VZTGT:\0C@8B^48Y;[>H"%DD
MO5?&<F:MD,PH"7D>9!*\M99SXRN">F7;+MIGREY:MQ4^G5B^N42[>
U+%T"!(
MXABSYTQ0V!6,L^*QW5JOUS=+!_VV19&.!H.R+/N;>U'VT7L@2G2^S_O;(L:D
M'--;W,F0_\!0US_!;(?%HAE<"[*+X`L347*EI"&];+=,;[XPW#MTGUW+`O]=
MTNR^H,%6L'OY$OC>?RX];Z52K(N@#42(I/^"4@_(E;ED;==T;B:6(OV&9"+@
MNY#*R.;4,68^\CUO"+TUX1Q_1=*+"1.5M1/8UQ`ZZ@';').BD?V".KM[4J^B
MX6LWX7)4Q"4385+FB-OCA;'Z31+.?B:<_35`I_/A(,Z#;X%RG-J.I4+P@'!%
M2I,_/)F"%I79Z7&>!,J6K]*Q34\V5Y1%DO`^"Y+O6-/8"O;&7_UG*
&)+RY\^
MP[)`1D78->;6<X;B*XUM]Q5!'ZJBFHBJ67<F3U:[A;4=H6^MTR3T_4DR,BL-
M_^LET>.H>^),)%3558->`MTKZ/XAH:JD6F6JHJ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M4^E1S&3_^\0Z+8@D"-_[A-UJF@<_+FA#\!V#5IWB)P+L@29`4>@BB$"ASJS
.
M2K.FS6T4*T7A/X15V*:"*@'\1?\M6B#JXX<E9QW-^MD*'!#KL,2+F&3:B9JZ
M:8G0[Z5;,2^W#W4`(Q8_,E<G5IH>JXPKUZ=#U(?E7%$%\IB8Q[R*NO%8+G+)
MK5&8Q=0\5E(1;#=.[%M0[/9DU0KC,')<@CG;Q1\//@TJXE]-]^#O$?%7D;?/
M1N3W",Z(>Q^\58AY'63<K'7BVHBU(M<YI833R+\$-T#K$=4.`.?7JTCZL.!_
MA3[?\4]02P,$"@``````-'A<,@````````````````D```!R96%D;'-C<B]0
M2P$"%``4````"``">UPR<.5C@]<#``!]"0``$0`````````!`&
quot;``````````
M<F5A9&QS8W(O36%K969I;&502P$"%``4````"`#<>EPR,AS;XP0%
``"@#@``
M$P`````````!`"`````&!```<F5A9&QS8W(O<F5A9&QS8W(N8U!+`0(4
`!0`
M```(``1[7#+@=0JB50L````<```5````````````(````#L)``!R96%D;'-C
M<B]R96%D;'-C<BYE>&502P$"%``*```````T>%PR````````````````&q
uot;0``
M`````````!````##%```<F5A9&QS8W(O4$L%!@`````$``0`^@```.H4````
!````
`
end
Post Reply
Re: What is wrong read of login script
Mon, 28 Feb 2005 19:03:33 GMT
Alex,

There may be a subtle difference between platform and RTL file handles. 
Several compilers even provide APIs for converting between them, like 
_open_osfhandle() in Watcom C/C++. I'd suggest you to try to use fp returned 
by NWDSOpenStream() not with read() but with ReadFile().

-- 
Dmitry Mityugov, Developer Services SysOp 8

Search these newsgroups for answers to similar questions:
http://developer.novell.com/ndk/devforums.htm
Search DevSup Samples and TIDs:
http://developer.novell.com/support/sample.htm
Search KnowledgeBase and manuals:
http://support.novell.com/search/kb_index.jsp
Search YES, Tested and Approved Products:
http://developer.novell.com/yessearch/Search.jsp
Search Samples and Projects at Novell Forge:
http://forge.novell.com


Alex Warmerdam wrote:
> Hi,
>
> getting nuts over this piece of code, why does it not work:
>
>
/****************************************************************************
> */
>
> /*************************************************************************
> ** Macro Definitions
> */
> #define BUFFER_SIZE 0x1000 /* 4k */
>
> #define N_PLAT_WNT
> /*************************************************************************
> ** Include header files
> */
>
> /*---------------------------------------------------------------------
> ** NLMSDK includes
> */
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> #include <conio.h>
> #include <nwdsapi.h>
> #include <nwdsmisc.h>
> #include <nwdsdc.h>
> #include <nwalias.h>
> #include <nwdsdsa.h>
> #include <nwmisc.h>
> #include <io.h>
> #include <errno.h>
>
> /*************************************************************************
> ** DisplayUsage
> */
> void DisplayUsage(void)
> {
> printf("Syntax:  start stream <object>\n");
> printf("Example: start stream .testuser.company\n");
> exit(0);
> }
>
>
> /*************************************************************************
> ** main
> */
> void main(int argc, char *argv[])
> {
> NWDSContextHandle cx;
> NWDSCCODE ccode;
> nuint32 flags;
> int fp;
> LONG length;
> char *buffer;
>
> if(argc!=2)
> {
> DisplayUsage(); /*display usage and
> exit nlm*/
> }
>
> /*------------------------------------------------------------------
> ** Note that beginning with release 8 of the Novell SDK the
> call to
> ** NWCallsInit() loads the unicode tables for you.
> */
> ccode = NWCallsInit(NULL, NULL);
> if (ccode)
> {
> printf("\nCall to NWCallsInit returned: %04X", ccode);
> exit(1);
> }
>
> ccode = NWDSCreateContextHandle(&cx);
> if (ccode)
> {
> printf("NWDSCreateContext returned: %04X\n", ccode);
> exit(ccode);
> }
>
>
> /*-------------------------------------------------------------------
> ** Get the current directory context flags so we can modify
> them.
> */
>
> ccode = NWDSGetContext(
> /* Contxt Handle    */ cx,
> /* Key              */ DCK_FLAGS,
> /* Context Flags    */ &flags
> );
>
> if (ccode < 0)
> {
> printf("NWDSGetContext returned: %04X\n", ccode);
>      NWDSFreeContext(cx);
>      exit(1);
>   }
>
>
> /*-------------------------------------------------------------------
> **   Turn typeless naming on.
> **   Turn canonicalize names off.  This means we will get full
> names.
> */
>
> flags |= DCV_TYPELESS_NAMES;
> flags &= ~DCV_CANONICALIZE_NAMES;
>
>
> /*-------------------------------------------------------------------
> ** Set the directory context flags so they take effect.
> */
>
> ccode = NWDSSetContext(
> /* Context Handle */ cx,
> /* Key            */ DCK_FLAGS,
> /* Set Flag Value */ &flags
> );
>
> if (ccode < 0)
> {
> printf("NWDSSetContext returned: %04X\n", ccode);
> NWDSFreeContext(cx);
>      exit(2);
> }
>
>
> ccode=NWDSOpenStream(
> /*NWDSContextHandle context, */ cx,
> /*char NWFAR *objectName, */ argv[1],
> /*char NWFAR *attrName, */ "Login
> Script",
> /*uint32 flags,
> */ DS_READ_STREAM,
> /*int NWFAR *fileHandle */
> (NWFILE_HANDLE *)&fp );
>
> if(ccode)
> {
> printf("Error: NWDSOpenStream() %ld",ccode);
> goto Exit2;
> }
>
> buffer=malloc(BUFFER_SIZE+1);
> if(NULL==buffer)
> {
> printf("Error malloc of buffer.\n");
> goto Exit3;
> }
> /* read the login script and dump to screen */
> do{
> length=read(
>      /*int __handle, */ fp,
>      /*void *__buf, */ buffer,
>      /*LONG __len ); */ BUFFER_SIZE );
> if(-1 != length)
> *(buffer+length)='\0';
> printf("%s",buffer);
> }while(length==BUFFER_SIZE);
> if(-1 == length) /* error has occured */
> {
> printf("Errno: during read() %ld\n",errno);
> }
>
> free(buffer);
> Exit3:
> close(fp);
> Exit2:
> // NWDSLogout(cx);
> Exit1:
> NWDSFreeContext(cx);
> exit(0);
> }
>
> 

Post Reply
Re: What is wrong read of login script
Mon, 28 Feb 2005 22:57:46 GMT
D.d. Mon, 28 Feb 2005 19:03:33 GMT, "Dmitry Mityugov, Developer
Services SysOp 8" <devforums@novell.com> schreef het volgende:

Hi,

>There may be a subtle difference between platform and RTL file handles. 
>Several compilers even provide APIs for converting between them, like 
>_open_osfhandle() in Watcom C/C++. I'd suggest you to try to use fp returned

>by NWDSOpenStream() not with read() but with ReadFile().

Little update, it does now work with the read function.

Just transfert the file into a gui version and then it all works fine
(BorlandC 4.52 was used). If compiled as a console win32 app it does
not work.

While with openwatcom a console app with read function works as well.

[code]
ccode=NWDSOpenStream(
/*NWDSContextHandle             context,        */ cx,
/*char          NWFAR *objectName,      */      argv2,
/*char          NWFAR *attrName,    */      "Login Script",
/*uint32        flags,          */      DS_READ_STREAM,
/*int           NWFAR *fileHandle   */      &fp);

 if(ccode)
{
        printf("Error: NWDSOpenStream() %ld",ccode);
        goto Exit2;
}

fh = _open_osfhandle((long)fp,O_TEXT) ;
if (fh == -1)
{
     printf("Error handle");
     goto Exit3;
}
 /* read the login script */
ccode = 0;
do
{
    for(length=0;length<DEFAULT_MESSAGE_LEN+1; length++)
    buf[length] = NULL;
    ccode=read(
               (int) fh,
               &buf,
               DEFAULT_MESSAGE_LEN);
    buf[ccode] = NULL;
    sprintf(str, "%s", buf);
[/code]

But thanks for the thought :)



Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact