void refresh_command_line(t_char **list) { t_char *temp; t_char **activechar; int i; char *tempstr; cursor_move_left(*(getcurpos())); tputs(tgetstr("cd", NULL), 1, t_write); activechar = getactivechar(); ft_putstr_fd("$> ", *(gettty())); if (*list) { tempstr = char_to_str((*list)->next); *(getcurpos()) = 3 + ft_strlen(tempstr); ft_putstr_fd(tempstr, *(gettty())); ft_memdel((void **)&tempstr); temp = (*list)->next; i = 3; while (temp && temp != *activechar) { i++; temp = temp->next; } cursor_move_left(*(getcurpos()) - i); } }
int main(int argc, char **argv, char **envp) { t_char *list; t_env **env; (void)argc; (void)argv; list = NULL; char_add(&list, char_new('-')); *(getactivelist()) = &list; env = ft_getenv(); *env = ft_load_env(envp); (ft_saved_env())->home = ft_strdup(get_env_value("HOME")); term_initiate(); ft_putstr_fd("$> ", *(gettty())); *(getcurpos()) = 3; show_prompt(&list, envp); return (0); }
static uLong editpwrec (OZ_Handle h_pwdfile, OZ_IO_fs_readrec *fs_readrec, int oldlen, char *oldstr, int newlen, char *newstr) { char *oldbuf, recbuf2[RECORD_MAX]; OZ_IO_fs_readrec fs_readrec2; OZ_IO_fs_writerec fs_writerec; uLong oldsiz, sts; memset (&fs_writerec, 0, sizeof fs_writerec); /* If lengths are the same, we can do an in-place update */ /* This will be a common case for changing passwords, as the hash string is always the same length */ oldsiz = *(fs_readrec -> rlen); oldbuf = fs_readrec -> buff; #if 00 oz_knl_printk ("oz_sys_password*: old at %u.%u\n", fs_readrec -> atblock, fs_readrec -> atbyte); oz_knl_dumpmem (oldsiz, oldbuf); oz_knl_printk ("oz_sys_password*: oldstr\n"); oz_knl_dumpmem (oldlen, oldstr); oz_knl_printk ("oz_sys_password*: newstr\n"); oz_knl_dumpmem (newlen, newstr); #endif if (newlen == oldlen) { memcpy (oldstr, newstr, oldlen); fs_writerec.size = oldsiz; fs_writerec.buff = oldbuf; fs_writerec.trmsize = fs_readrec -> trmsize; fs_writerec.trmbuff = fs_readrec -> trmbuff; fs_writerec.atblock = fs_readrec -> atblock; fs_writerec.atbyte = fs_readrec -> atbyte; sts = oz_sys_io (OZ_PROCMODE_KNL, h_pwdfile, 0, OZ_IO_FS_WRITEREC, sizeof fs_writerec, &fs_writerec); return (sts); } /* Different lengths, make sure new length not too long */ if (oldsiz - oldlen + newlen > RECORD_MAX) return (OZ_BUFFEROVF); /* Copy rest of records over the old one */ memset (&fs_readrec2, 0, sizeof fs_readrec2); fs_readrec2.size = sizeof recbuf2; fs_readrec2.buff = recbuf2; fs_readrec2.rlen = &fs_writerec.size; fs_readrec2.trmsize = fs_readrec -> trmsize; fs_readrec2.trmbuff = fs_readrec -> trmbuff; fs_writerec.buff = recbuf2; fs_writerec.trmsize = fs_readrec -> trmsize; fs_writerec.trmbuff = fs_readrec -> trmbuff; fs_writerec.atblock = fs_readrec -> atblock; fs_writerec.atbyte = fs_readrec -> atbyte; while (1) { sts = oz_sys_io (OZ_PROCMODE_KNL, h_pwdfile, 0, OZ_IO_FS_READREC, sizeof fs_readrec2, &fs_readrec2); if (sts == OZ_ENDOFFILE) break; if (sts != OZ_SUCCESS) return (sts); sts = getcurpos (h_pwdfile, &fs_readrec2.atblock, &fs_readrec2.atbyte); if (sts != OZ_SUCCESS) return (sts); #if 00 oz_knl_printk ("oz_sys_password*: cpy at %u.%u\n", fs_writerec.atblock, fs_writerec.atbyte); oz_knl_dumpmem (fs_writerec.size, fs_writerec.buff); #endif sts = oz_sys_io (OZ_PROCMODE_KNL, h_pwdfile, 0, OZ_IO_FS_WRITEREC, sizeof fs_writerec, &fs_writerec); if (sts != OZ_SUCCESS) return (sts); sts = getcurpos (h_pwdfile, &fs_writerec.atblock, &fs_writerec.atbyte); if (sts != OZ_SUCCESS) return (sts); } /* Write the modified record to the end of the file */ memmove (oldstr + newlen, oldstr + oldlen, oldbuf + oldsiz - oldstr - oldlen); memcpy (oldstr, newstr, newlen); fs_writerec.size = oldsiz - oldlen + newlen; fs_writerec.buff = oldbuf; fs_writerec.truncate = 1; #if 00 oz_knl_printk ("oz_sys_password*: end at %u.%u\n", fs_writerec.atblock, fs_writerec.atbyte); oz_knl_dumpmem (fs_writerec.size, fs_writerec.buff); #endif sts = oz_sys_io (OZ_PROCMODE_KNL, h_pwdfile, 0, OZ_IO_FS_WRITEREC, sizeof fs_writerec, &fs_writerec); if (sts != OZ_SUCCESS) return (sts); /* Close file */ sts = oz_sys_io (OZ_PROCMODE_KNL, h_pwdfile, 0, OZ_IO_FS_CLOSE, 0, NULL); return (sts); }
OZ_HW_SYSCALL_DEF_2 (password_change, const char *, oldpw, const char *, newpw) { char newpwhashstr[OZ_SYS_HASH_STRSIZE], *oldstr, *p, pwdrec[RECORD_MAX], sepc; const char *username; int oldlen, si, username_l; OZ_Handle h_pwdfile; OZ_IO_fs_getinfo1 fs_getinfo1; OZ_IO_fs_readrec fs_readrec; uByte hashbin1[OZ_SYS_HASH_BINSIZE], hashbin2[OZ_SYS_HASH_BINSIZE]; uLong pwdrec_l, sts; h_pwdfile = 0; si = oz_hw_cpu_setsoftint (0); /* Open the password file - given by kernel mode logical OZ_PASSWORD_FILE */ sts = oz_sys_io_fs_parse3 ("OZ_PASSWORD_FILE", 0, NULL, OZ_PROCMODE_KNL, openpwfile, &h_pwdfile); if (sts != OZ_SUCCESS) goto rtnsts; /* Scan password file for the username */ memset (&fs_getinfo1, 0, sizeof fs_getinfo1); memset (&fs_readrec, 0, sizeof fs_readrec); fs_readrec.size = sizeof pwdrec - 1; fs_readrec.buff = pwdrec; fs_readrec.rlen = &pwdrec_l; fs_readrec.trmsize = 1; fs_readrec.trmbuff = "\n"; username = oz_knl_user_getname (NULL); username_l = strlen (username); while (1) { sts = getcurpos (h_pwdfile, &fs_readrec.atblock, &fs_readrec.atbyte); if (sts != OZ_SUCCESS) goto rtnsts; sts = oz_sys_io (OZ_PROCMODE_KNL, h_pwdfile, 0, OZ_IO_FS_READREC, sizeof fs_readrec, &fs_readrec); if (sts != OZ_SUCCESS) goto rtnsts; if (pwdrec_l == 0) continue; pwdrec[pwdrec_l] = 0; sepc = pwdrec[0]; if (pwdrec[username_l+1] != sepc) continue; if (memcmp (pwdrec + 1, username, username_l) == 0) break; } /* Get what's in password record to hashbin2 */ sts = OZ_BADPWRECORD; oldstr = pwdrec + username_l + 2; p = memchr (oldstr, sepc, pwdrec_l - username_l - 2); if (p == NULL) goto rtnsts; oldlen = p - oldstr; if ((oldlen != OZ_SYS_HASH_STRSIZE - 1) || !oz_sys_hash_str2bin (oldstr, hashbin2)) oz_sys_hash (oldlen, oldstr, hashbin2); /* Get what caller gave us for old password to hashbin1 */ oz_sys_hash (strlen (oldpw), oldpw, hashbin1); /* See if they match */ sts = OZ_BADPASSWORD; if (memcmp (hashbin1, hashbin2, OZ_SYS_HASH_BINSIZE) != 0) goto rtnsts; /* Make new password hash string */ oz_sys_hash (strlen (newpw), newpw, hashbin1); oz_sys_hash_bin2str (hashbin1, newpwhashstr); /* Edit password record replacing the old password with new one */ sts = editpwrec (h_pwdfile, &fs_readrec, oldlen, oldstr, OZ_SYS_HASH_STRSIZE - 1, newpwhashstr); /* Close password file and return final status */ rtnsts: oz_sys_handle_release (OZ_PROCMODE_KNL, h_pwdfile); oz_hw_cpu_setsoftint (si); return (sts); }