From: larimer@zeus.cdc.com (Mark D. Larimer)
Newsgroups: comp.sys.mac.programmer
Subject: Re: Help: mounting appleshare volumes
Date: 27 Sep 92 05:42:34 GMT
Organization: Control Data Systems, Inc.
X-UserAgent: Nuntius v1.1.1d7
X-XXDate: Sun, 27 Sep 92 06:42:09 GMT

In article <1992Sep23.162826.9004@vax.oxford.ac.uk> ,
perrins@vax.oxford.ac.uk writes:

>Does anyone out there know how to mount an AppleShare volume from within
an
>application (written in pascal or C). There is a hypercard XCMD which
does what
>I want (gets the username,password,zonename,servername etc all lined up
and
>then mounts the volume if it exists).
>I need this 'cos I have an application which runs at startup to force a
login
>to a server, and set the chooser name to the appleshare username, as a
way of
>validating users on a large network. This relies on the fact that
appleshare
>offers a login automatically at boot up time if so desired, on our
system this
>is followed by the startup application. However if the user
>logs out by throwing away the server icon another user logging in in the
>standard way does not have his chooser name fixed.
>Any ideas most welcome...

I've got pascal code that does this.  System 6 users are required to have
version 3.0 
of the AppleShare rdev (Chooser device) in their System Folder for this
to work, but 
according to Apple itself, without AppleShare 3.0, there is no other way
to do it 
under System 6 other than the XCMD you mentioned above.  System 7 users
will have no 
problem.  Note that the server being mounted doesn't have to be running
AppleShare 3.0; 
only the Mac mounting the server needs to have the AppleShare 3.0
resource.

Good luck and let me know how it goes...

Mark D. Larimer
(Control Data Systems, Inc.) && (University of Minnesota)
Mark.D.Larimer@zeus.cdc.com

{-------------------------------------------------------------------}
	Function Pack (s1,s2,s3,s4,s5,s6 : Str255) : packedType; FORWARD;
{-------------------------------------------------------------------}

	{ The guts of the proc that mounts a server in either }
	{   System 7 or System 6 with AppleShare 3.0 rdev.    }
	Procedure MountIt;
	
	var	err					: OSErr;
			errStr			: Str255;
			myBuffer		: AFPVolMountInfo;
			myParamBlock: ParamBlockRec;

		begin
			with myBuffer do begin
				media:='afpm';          { type of volume; four-character code; afpm =
AppleShareMediaType	}
				flags:=0;               { reserved; must be set to 0	}
				nbpInterval:=8;         { Name-Binding Protocol (NBP) retry interval	}
				nbpCount:=3;            { NBP retry count	}
				uamType:=2;             { user authentication method; 2 = kPassword =
8-byte password }
				zoneNameOffset:=24;     { offset from start of record to zone name	}
				serverNameOffset:=57;   {                             to server name	}
				volNameOffset:=89;      {                             to volume name 
}
				userNameOffset:=117;    {															to user name	}
				userPassWordOffset:=149;{                             to user
password	}
				volPassWordOffset:=158; {                             to volume
password	}
				
				{                                                              user  
    volume  }
				{              zone name   server        volume     username   pw    
    pw      }
				afpData:=Pack('ZONE NAME','Cool Server','Volume
I','username','password','password');
				length:=sizeof(myBuffer);	{ length of mounting information	}
			end;
			
			myParamBlock.ioCompletion:=nil;		{ proc pointer to execute upon
completion	}
			myParamBlock.ioBuffer:=@myBuffer; { pointer to mounting information
record	}

			err:=PBVolumeMount(@myParamBlock);	{ mount the volume	}
			if err<>0 then begin
				NumToString(err,errStr);
				ParamText('Error during PBVolumeMount',errStr,'','');
				itemHit:=Alert(idAlert,nil);
			end
			else
				serverVRefNum:=myParamBlock.ioVRefNum;	{ if successful, vol ref num
returned	}
		end;

{----------------------------------------------------------------------
------}

	{ Lay the mounting information into the buffer at the proper offset
locations }
	Function Pack(s1,s2,s3,s4,s5,s6:Str255):packedType;
	
	var	i,j		: integer;
			Data	: packedType;
			
		begin
			j:=2;
			Data[1]:=chr(length(s1));
			for i:=1 to length(s1) do begin
				Data[j]:=s1[i];
				j:=j+1;
			end;
			
			j:=35;
			Data[34]:=chr(length(s2));
			for i:=1 to length(s2) do begin
				Data[j]:=s2[i];
				j:=j+1;
			end;
			
			j:=67;
			Data[66]:=chr(length(s3));
			for i:=1 to length(s3) do begin
				Data[j]:=s3[i];
				j:=j+1;
			end;
			
			j:=95;
			Data[94]:=chr(length(s4));
			for i:=1 to length(s4) do begin
				Data[j]:=s4[i];
				j:=j+1;
			end;
			
			j:=127;
			Data[126]:=chr(length(s5));
			for i:=1 to length(s5) do begin
				Data[j]:=s5[i];
				j:=j+1;
			end;
			
			j:=136;
			Data[135]:=chr(length(s6));
			for i:=1 to length(s6) do begin
				Data[j]:=s6[i];
				j:=j+1;
			end;
			
		Pack:=Data;
	end;

{--------------------------------------------------------------}