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

Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more

Jobs Board

Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple 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.