TweetFollow Us on Twitter

AShare UserName
Volume Number:7
Issue Number:6
Column Tag:Programmer's Forum

AppleShare Username to Chooser Name INIT

By Mark Gavin, Darby, PA

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

[ Mark Gavin is a consultant in the Philadelphia area who specializes in Macintosh software development using MacApp, Object Pascal and 68000 Assembly. He can be reached via AppleLink GAVIN.MARK. ]

INIT’s in General

It used to be that an INIT had to be loaded into the system file using ResEdit or some other resource installer. Only 32 INIT’s were allowed in the system file and you had to be aware of possible resource ID conflicts during the installation process. A while back Apple enhanced the INIT system by placing INIT 31 within the system file. The job of INIT 31 is to look in the system folder for any files of type ‘INIT’ who happen to have one or more ‘INIT’ resources. The search is in alphabetical order by filename. When INIT 31 locates an INIT resource it is called and executed as if it were a procedure (Inside Macintosh Volume IV, pp. 255-257) . INIT 31 can also allocate memory in the system heap for the INIT if you use the ‘sysz’ resource (Inside Macintosh Volume V, pg. 352). As is, INIT 31 gives you at least a 16K block within the system heap.

An INIT in it’s basic form is a stand alone code module which normally has no access to global data or anything that uses A5 relative addressing like QuickDraw. This minor inconvenience can be easily circumvented by creating your own A5 world. There is a very good explanation, and examples, of setting up your own A5 world in Apple’s Macintosh Technical Note #256, Stand-Alone Code, ad nauseam.

Network Administration and Responder

One of my clients has implemented a wide area EtherNet network which covers 15 sites with 76 zones and 56 networks throughout the United States. Network support is via Timbuktu which uses the Chooser name to identify each Mac. They also use Inter•Poll and NetMinder for network diagnostics. These, also, use the Chooser name, broadcast by the Responder.

Responder is an INIT supplied by Apple on the Macintosh System software disks. Its function is to register the Macintosh Chooser name on the AppleShare network. The Responder and the other utilities described above, play an important role in network administration by allowing us to easily locate an individual Macintosh and it’s owner on the network. The Chooser name, however, can be easily modified or deleted by the user. For example, the network administrator, located in Pennsylvania, would have trouble determining who owns a Macintosh named ‘Wizard’ located in California or Connecticut. In addition, there is no guarantee the Macintosh will have the same name tomorrow or the next day.

Placing the AppleShare username into the Chooser name appears to be the most straight forward solution to the problem of system identification and offers us several advantages:

1. Avoid burdening the user with yet one more administrative task.

2. Automatic update of Chooser name with new user.

3. The Chooser name can not be permanently modified by the user.

The AShareNameINIT

The function of the AShareNameINIT is to extract the AppleShare username from the ‘AppleShare Prep’ file and place the username in the Chooser. I have chosen not to display an ICON at startup because this INIT is a network administration tool that should not be disabled by the user. Therefore, the less obtrusive the better.

The AppleShare Prep File

Apple hasn’t released any information on the AppleShare Prep file, so this is what I have figured out thus far.

The AppleShare Prep file is created by selecting the AppleShare device within the Chooser. When the file is created it contains 4 bytes, all nil, within a single resource ‘BMLS’ 2447. The AppleShare logon name is only placed into the BMLS resource if the user chooses to have an AppleShare volume auto-logon at startup. As a side note; If you elect to have AppleShare automatically logon to a server with your name and password, the password is also placed in the AppleShare Prep file but it is not encrypted in any way. By looking at the resource with ResEdit you can read any stored password.

The AppleShare Prep file saves a username and server history when the server name changes. There does not appear to be any way of deleting information that is no longer being used by AppleShare. This history is stored in a linked list of entries. The number of entries in the file is stored in the first word of the BMLS resource. The second word of the resource contains the size of the block to follow. It is also used as an offset to the next entry in the list. Logical block size within the resource is variable according to how many server disks are mounted. The username is a 32 byte Pascal string located 20 bytes after the blocksize. Currently, the INIT uses the last name in the list of AppleShare usernames located within the BMLS resource.

The Chooser Name

The Chooser Name is located in a ‘STR ‘ resource within the System file whose ID is -16096. This is a Pascal string which is exactly 32 bytes. Any more or less may cause problems because all of the applications that use the Chooser name expect 32 bytes. Even-thought it is technically a STR resource, it would not be wise to try to fill it with a Str255.

The Code

The TYPE intPtr is used to coerce the Mac into returning a word instead of a byte as it would normally.

There is bug in the 128K and later versions of the ROM which will cause _OpenRFPerm not to pass trap discipline under TMON. When you hard code a string into the code resource, like I am doing with the ‘AppleShare Prep’ filename, _OpenRFPerm calls _RecoverHandle with a bad Master Pointer. This is the reason for calling StripAddress on the address of the filename. For a more complete explanation please refer to Technical Note #232 Strip with _OpenResFile and _OpenRFPerm.

The ENTRYPOINT Procedure and the forward declaration of the AShareNameINIT procedure are needed because of the CloseAndExit nested procedure. If the forward declaration is not used the CloseAndExit procedure will be the first procedure executed within the INIT code segment and cause all kinds of nasty things to happen; i.e., trample on the stack.

The CloseAndExit procedure could have been avoided just by using a GOTO to jump to the CloseResFile statement at the end of the procedure. However, I think the nested procedure results in cleaner looking code even-though using a GOTO is a more efficient solution in this particular case.

I like to place the About information and the compilation date directly into the executable code. MPW Pascal, however, is an optimizing compiler which will strip out all string constants or code that are not referenced. The IF statement containing the deadStrip boolean is a quick and dirty way of bypassing the MPW Pascal compiler optimization and forcing an About string and the compilation date into the executable code segment. The deadStrip boolean is needed because simply setting the IF statement to false will cause the entire IF statement to be striped from the code.

When the user sets AppleShare to autologon to a server as a Guest, the AppleShare Prep file contains a null string. If this is the case, we do not want to copy a null string into the Chooser because Responder will ask the user to name the Macintosh after each restart. This would be rather annoying to the user.

Program Flow

1. Get the vRefNum of the startup volume.

2. Open the resource fork of the AppleShare Prep file.

3. Get a handle to BMLS 2447.

4. Get a handle to STR -16096.

5. Check for data in BMLS 2447.

6. How many entries are in the linked list.

7. Offset to the last entry in the linked list.

8. Check for a nil name.

9. Copy the name to STR -16096.

10. Cleanup.

That’s all there is to it. INIT’s, in general, are relatively straight forward to write. Just be careful and test using heap scramble, purge and trap discipline.

Bibliography

Macintosh Technical Notes:

#129 _SysEnvirons: System 6.0 and Beyond.

#232 Strip with _OpenResFile and _OpenRFPerm.

#247 Giving the (Desk)Hook to INIT’s.

#256 Stand-Alone Code, ad nauseam.

Listing: ASharINIT.p

{ --------------------------
  AShareNameINIT
  
 Type   INIT
 ID16056
 Version1.5
 Wednesday, December 5, 1990 9:53:37 AM
 ©1990 by Mark Gavin
 All Rights Reserved
-------------------------- }
{$Z+} { Identify all routines to the Linker as
 external.  If this is not used then
 ENTRYPOINT must be placed in the
 INTERFACE section }
    
  UNIT _AShareNameINIT;

INTERFACE
 USES
 Types, Memory, ToolUtils,
 OSUtils, Resources, PaslibIntf, Packages;

 TYPE
 intPtr = ^integer;
 {used to retrieve an integer from the resource}
 

{$R-}   { Turn Off Range Checking }
{$OV-}  { Ignore Arithmetic Overflows }

IMPLEMENTATION

 PROCEDURE AShareNameINIT;FORWARD;


 PROCEDURE ENTRYPOINT;

 BEGIN
 AShareNameINIT;
 END;

{ ---------------------------------- }
  PROCEDURE AShareNameINIT;
 
    VAR
 str    : Str255;
 
 volNamePtr : StringPtr;
 
 theStringPtr,
 theNamePtr : Ptr;
 
 { AppleShare Prep resHdl }
 ASPResHandle,
 chooserStringHdl: Handle;
 
 ASPHandleSize   : longint;
 
 index,
 blocksize,
 resOffset,
 offsetMultiplier,
 stringLength,
 refNum,
 vRefNum,
 oldResFileRef   : integer;
 
 anError: OSErr;
 
 deadStrip: Boolean;

 { ------------------------------------ }
 PROCEDURE CloseAndExit;
 
 BEGIN  
 CloseResFile(refNum);
 UseResFile(oldResFileRef);
 EXIT(AShareNameINIT);    
 END;
 
 { ------------------------------------ }
 BEGIN  
 oldResFileRef := CurResFile;
 
 deadStrip := False;
 IF deadStrip THEN BEGIN
 str := ‘AShareNameINIT 1.5 by Mark Gavin’;
 str := compdate;
 END;

 { GetVol returns the name of the
 default volume in volNamePtr and
 its volume reference number in vRefNum. }
 
 volNamePtr := StringPtr(NewPtr(256));
 IF MemError <> noErr THEN
 EXIT(AShareNameINIT);

 anError := GetVol(volNamePtr, vRefNum);
 IF anError <> noErr THEN
 EXIT(AShareNameINIT);

 DisposPtr(Ptr(volNamePtr));
 { Ptr only needed for GetVol }

 str := ‘AppleShare Prep’;
 { StripAddress used per Tech Note 232
 - bug in OpenRFPerm }
 refNum := OpenRFPerm(StringPtr(StripAddress(@str))^, vRefNum, fsRdPerm);
 IF ResError <> noErr THEN
 EXIT(AShareNameINIT);  
 
 ASPResHandle := GetResource(‘BMLS’, 2447);
 IF ResError <> noErr THEN
 CloseAndExit; 
 HNoPurge(ASPResHandle);
 
 chooserStringHdl := GetResource(‘STR ‘, -16096);
 IF ResError <> noErr THEN
 CloseAndExit; 
 HNoPurge(chooserStringHdl);
 
 ASPHandleSize := GetHandleSize(ASPResHandle);
 IF MemError <> noErr THEN
 CloseAndExit;
 
 { Make sure there is data in the handle }
 IF ASPHandleSize < 55 THEN
 CloseAndExit; 
 
 offsetMultiplier := intPtr(ASPResHandle^)^;
 IF offsetMultiplier < 1 THEN
 CloseAndExit; 

 blockSize := intPtr(ORD4(ASPResHandle^) + 2)^;
 IF blockSize < 1 THEN
 CloseAndExit; 
 
 resOffset := 2;
 
 FOR index := 1 TO (offsetMultiplier - 1) DO
 BEGIN
 resOffset := resOffset + blockSize;
 blockSize := intPtr(ORD4(ASPResHandle^) + resOffset)^;
 IF blockSize < 1 THEN
 CloseAndExit;
 END;

 resOffset :=  resOffset + 20;
 { offset to string within block }

 theNamePtr := Ptr(ORD4(ASPResHandle^) + resOffset);
 
 IF theNamePtr^ = 0 THEN
 CloseAndExit;{ exit on nil name }
 
 theStringPtr := chooserStringHdl^;

 BlockMove(theNamePtr, theStringPtr, 32);
 
 ChangedResource(chooserStringHdl);
 WriteResource(chooserStringHdl);

 HPurge(chooserStringHdl);
 HPurge(ASPResHandle);
 
 CloseResFile(refNum);
 
 UseResFile(oldResFileRef);

   END;
 END.
Listing:  AShareINIT.make

{ -------------------------- }
#   File:       AShareNameINIT.make
#   Target:     AShareNameINIT
#   Sources:    AShareNameINIT.p
#   Created:    Monday, November 26, 1990 4:39:50 PM
#©1990 by Mark Gavin

AShareNameINIT.p.o ƒ AShareNameINIT.make AShareNameINIT.p
  Pascal  AShareNameINIT.p

SOURCES = AShareNameINIT.p
OBJECTS = AShareNameINIT.p.o

AShareNameINIT ƒƒ AShareNameINIT.make AShareNameINIT.p.o
 Link -t INIT -c ‘ASN?’ -rt INIT=16056 -ra =resLocked -sg AShareNameINIT 
-m ENTRYPOINT 
 {OBJECTS} 
 “{Libraries}”Interface.o 
 -o AShareNameINIT

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.