[IRCServices Coding] Migrating Modules to 5.1...
Andrew Church
achurch at achurch.org
Wed Aug 20 11:20:26 PDT 2008
To extract from a Password structure (assuming the source password buffer
is declared as "Password source_password"):
char password_buffer[PASSMAX];
char *cipher;
memcpy(password_buffer, source_password.password, PASSMAX);
cipher = strdup(source_password.cipher);
To copy into a Password structure (assuming the target password buffer is
declared as "Password target_password" and the data to be copied is in
"password_buffer" and "cipher" variables as above):
Password temp_password;
init_password(&temp_password);
memcpy(temp_password.password, password_buffer, PASSMAX);
temp_password.cipher = cipher;
copy_password(&target_password, &temp_password);
// Don't leave a copy of the password in memory
memset(&temp_password, 0, sizeof(temp_password));
memset(password_buffer, 0, PASSMAX);
I actually think I'll add a set_password() function to simplify this, so
the above would then become simply:
set_password(&target_password, password_buffer, cipher);
// Don't leave a copy of the password in memory
memset(password_buffer, 0, PASSMAX);
See the "encrypt.h" header file and section 2-9-1 of the technical manual
for further details.
--Andrew Church
achurch at achurch.org
http://achurch.org/
>Hy,
>
>Would that be the right way?:
>
>copy_password(&ngi->pass, &passbuf);
>strncpy(&passbuf, row[field(MYSQL_FIELD_USERINFO_PASSWORD) ...
>
>Are there sample codes to use copy_password in the right way?
>
>Regards.
>
>
>Andrew Church schrieb:
>> Passwords are no longer stored as simple strings, since each password
>> can be encrypted with a different method (cipher). To save data from
>> a Password structure, you need to save both the contents of
>> Password.password (as a binary buffer, not a string) and the string
>> pointed to by Password.cipher (which may be NULL). To restore a
>> Password structure, fill in the password and cipher fields in a
>> temporary variable, then use copy_password() to copy the data to the
>> destination Password structure.
>>
>> --Andrew Church
>> achurch at achurch.org
>> http://achurch.org/
>>
>>
>>> Hy,
>>>
>>> I'm migrating my old modules for ircservices-5.1.11, but I've seen that
>>> there were many changes in the nickgroupinfo_ struct.
>>> "char pass[PASSMAX];" were replaced by "Password pass;", so my module
>>> won't compile anymore:
>>>
>>> modules/nickserv/dbsynch.c: In function `copy_data':
>>> modules/nickserv/dbsynch.c:83: error: incompatible type for argument 1
>>> of `__builtin_strncpy'
>>>
>>>
>>> Line of this code:
>>>
>>> static void copy_data(MYSQL_ROW row, unsigned long *lengths, NickInfo
>>> *ni, NickGroupInfo *ngi) {
>>> char temp[100];
>>> strncpy(ngi->pass, row[field(MYSQL_FIELD_USERINFO_PASSWORD)], PASSMAX <
>>> lengths[field(MYSQL_FIELD_USERINFO_PASSWORD)] ? PASSMAX :
>>> lengths[field(MYSQL_FIELD_USERINFO_PASSWORD)] + 1);
>>> ....
>>>
>>> When I replace "ngi->pass" by "&ngi->pass" there's only a warning left,
>>> but by running this function copy_data my services crashes.
>>>
>>> Any Ideas?
>>> Regards.
>>> ------------------------------------------------------------------
>>> To unsubscribe or change your subscription options, visit:
>>> http://lists.ircservices.za.net/mailman/listinfo/ircservices-coding
>>>
>>> ------------------------------------------------------------------------
>>>
>>> ------------------------------------------------------------------
>>> To unsubscribe or change your subscription options, visit:
>>> http://lists.ircservices.za.net/mailman/listinfo/ircservices-coding
>