int ncp_change_obj_passwd(NWCONN_HANDLE connid, const struct ncp_bindery_object *object, const u_char *key, const u_char *oldpasswd, const u_char *newpasswd) { long id = htonl(object->object_id); u_char cryptkey[8]; u_char newpwd[16]; /* new passwd as stored by server */ u_char oldpwd[16]; /* old passwd as stored by server */ u_char len; DECLARE_RQ; memcpy(cryptkey, key, 8); nw_keyhash((u_char *)&id, oldpasswd, strlen(oldpasswd), oldpwd); nw_keyhash((u_char *)&id, newpasswd, strlen(newpasswd), newpwd); nw_encrypt(cryptkey, oldpwd, cryptkey); nw_passencrypt(oldpwd, newpwd, newpwd); nw_passencrypt(oldpwd + 8, newpwd + 8, newpwd + 8); if ((len = strlen(newpasswd)) > 63) { len = 63; } len = ((len ^ oldpwd[0] ^ oldpwd[1]) & 0x7f) | 0x40; ncp_init_request_s(conn, 75); ncp_add_mem(conn, cryptkey, 8); ncp_add_word_hl(conn, object->object_type); ncp_add_pstring(conn, object->object_name); ncp_add_byte(conn, len); ncp_add_mem(conn, newpwd, 16); return ncp_request(connid, 23, conn); }
/* * Create an 8-bytes pattern from an 8-bytes key and 16-bytes of data */ void nw_encrypt(const u_char *fra, const u_char *buf, u_char *target) { buf32 k; int s; nw_keyhash(fra, buf, 16, k); nw_keyhash(fra + 4, buf, 16, k + 16); for (s = 0; s < 16; s++) k[s] ^= k[31 - s]; for (s = 0; s < 8; s++) *target++ = k[s] ^ k[15 - s]; }
int ncp_keyed_verify_password(NWCONN_HANDLE cH, char *key, char *passwd, struct ncp_bindery_object *objinfo) { u_long id = htonl(objinfo->object_id); u_char cryptkey[8]; u_char buf[128]; DECLARE_RQ; nw_keyhash((u_char *)&id, passwd, strlen(passwd), buf); nw_encrypt(key, buf, cryptkey); ncp_init_request_s(conn, 74); ncp_add_mem(conn, cryptkey, sizeof(cryptkey)); ncp_add_word_hl(conn, objinfo->object_type); ncp_add_pstring(conn, objinfo->object_name); return ncp_request(cH, 23, conn); }