I don't have the knowledge to comment on your problem directly, but you might consider using the password tools and processes that come with Samaba. It looks like once you add the LINUX box to the NT domain, everything happens automagically. Generally it is easier to figure out how to use an existing tool than it is to create a new one.
Apologies if you have already examined these tools and found them lacking for your purposes.