void main(void) { blf_ctx c; char key[] = "AAAAA"; char key2[] = "abcdefghijklmnopqrstuvwxyz"; u_int32_t data[10]; u_int32_t data2[] = {0x424c4f57l, 0x46495348l}; u_int16_t i; /* First test */ for (i = 0; i < 10; i++) data[i] = i; blf_key(&c, (u_int8_t *) key, 5); blf_enc(&c, data, 5); blf_dec(&c, data, 1); blf_dec(&c, data + 2, 4); printf("Should read as 0 - 9.\n"); report(data, 10); /* Second test */ blf_key(&c, (u_int8_t *) key2, strlen(key2)); blf_enc(&c, data2, 1); printf("\nShould read as: 0x324ed0fe 0xf413a203.\n"); report(data2, 2); blf_dec(&c, data2, 1); report(data2, 2); }
enum cryptoerr blf_init(struct keystate *ks, u_int8_t *key, u_int16_t len) { blf_key(&ks->ks_blf, key, len); return EOKAY; }
static int bf_init(PX_Cipher * c, const uint8 *key, unsigned klen, const uint8 *iv) { struct int_ctx *cx = (struct int_ctx *) c->ptr; blf_key(&cx->ctx.bf, key, klen); if (iv) memcpy(cx->iv, iv, 8); return 0; }
void createSharedPrinter(char *host, char *printer, int type) { blf_ctx ctx; hostent *ent; char msg[512], user[MAX_USERNAME_LENGTH + 1], password[BT_AUTH_TOKEN_LENGTH * 2 + 1]; int length; // Abort if the printer type is not valid. if (type < 0 || type > 0) return; BRect frame = Frame(); frame.top += 75; frame.left += 75; frame.bottom = frame.top + 135; frame.right = frame.left + 350; InstallPrinterPanel *prtPanel = new InstallPrinterPanel(frame, host, printer); status_t loginExit; wait_for_thread(prtPanel->Thread(), &loginExit); if (prtPanel->IsCancelled()) return; // Get the IP address of the server. ent = gethostbyname(host); if (ent == NULL) { sprintf(msg, "The server %s, which hosts printer %s, cannot be found on the network.", host, printer); BAlert *alert = new BAlert("", msg, "OK"); alert->Go(); return; } unsigned int serverIP = ntohl(*((unsigned int *) ent->h_addr)); if (getAuthentication(serverIP, printer)) { BRect frame = Frame(); frame.top += 75; frame.left += 75; frame.bottom = frame.top + 140; frame.right = frame.left + 250; LoginPanel *login = new LoginPanel(frame); status_t loginExit; wait_for_thread(login->Thread(), &loginExit); if (login->IsCancelled()) return; // Copy the user name. strcpy(user, login->user); // Copy the user name and password supplied in the authentication dialog. sprintf(password, "%-*s%-*s", B_FILE_NAME_LENGTH, printer, MAX_USERNAME_LENGTH, login->user); length = strlen(password); assert(length == BT_AUTH_TOKEN_LENGTH); password[length] = 0; blf_key(&ctx, (unsigned char *) login->md5passwd, strlen(login->md5passwd)); blf_enc(&ctx, (unsigned long *) password, length / 4); } else user[0] = password[0] = 0; prtPanel->CreatePrinter(printer, host, type, user, password); if (prtPanel->isDefault()) prtPanel->SetDefaultPrinter(printer); if (prtPanel->printTestPage()) prtPanel->TestPrinter(printer); }
bool mountFileShare(uint32 address, char *share, const char *path) { blf_ctx ctx; mount_bt_params params; char hostname[256], msg[512], *folder; int length; port_id port; folder = strrchr(path, '/'); if (folder) folder++; else folder = (char *) path; unsigned int serverIP = ntohl(address); #ifndef BONE_VERSION if (!be_roster->IsRunning(KSOCKETD_SIGNATURE)) if (be_roster->Launch(KSOCKETD_SIGNATURE) < B_NO_ERROR) { printf("Network communications could not be started. The shared volume cannot be mounted.\n"); BAlert *alert = new BAlert("", msg, "OK"); alert->Go(); return false; } for (int32 i = 0; i < 10; i++) { port = find_port(KSOCKET_DAEMON_NAME); if (port < B_NO_ERROR) snooze(1000000LL); else break; } if (port < B_NO_ERROR) { sprintf(msg, "Network communications are not responding. The shared volume cannot be mounted.\n"); BAlert *alert = new BAlert("", msg, "OK"); alert->Go(); return false; } #endif // Handle user authentication // strcpy(user, crypt(user, "u0")); // strcpy(password, crypt(password, "p1")); if (getAuthentication(serverIP, share)) { BRect frame = Frame(); frame.top += 75; frame.left += 75; frame.bottom = frame.top + 140; frame.right = frame.left + 250; LoginPanel *login = new LoginPanel(frame); status_t loginExit; wait_for_thread(login->Thread(), &loginExit); if (login->IsCancelled()) return false; // Copy the user name. strcpy(params.user, login->user); // Copy the user name and password supplied in the authentication dialog. sprintf(params.password, "%-*s%-*s", B_FILE_NAME_LENGTH, share, MAX_USERNAME_LENGTH, login->user); //crypt(password, "p1")); length = strlen(params.password); assert(length == BT_AUTH_TOKEN_LENGTH); params.password[length] = 0; blf_key(&ctx, (unsigned char *) login->md5passwd, strlen(login->md5passwd)); blf_enc(&ctx, (unsigned long *) params.password, length / 4); } else params.user[0] = params.password[0] = 0; params.serverIP = serverIP; params.server = host; params._export = share; params.folder = folder; params.uid = 0; params.gid = 0; gethostname(hostname, 256); params.hostname = hostname; int result = mount("beserved_client", path, NULL, 0, ¶ms, sizeof(params)); if (result < B_NO_ERROR) { sprintf(msg, "The shared volume could not be mounted (%s).\n", strerror(errno)); BAlert *alert = new BAlert("", msg, "OK"); alert->Go(); return false; } return true; }
/* ARGSUSED */ int vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) { int unit = DISKUNIT(dev); struct disklabel *lp; struct vnd_softc *sc; struct vnd_ioctl *vio; struct vnd_user *vnu; struct vattr vattr; struct nameidata nd; int error, part, pmask; DNPRINTF(VDB_FOLLOW, "vndioctl(%x, %lx, %p, %x, %p): unit %d\n", dev, cmd, addr, flag, p, unit); error = suser(p, 0); if (error) return (error); if (unit >= numvnd) return (ENXIO); sc = &vnd_softc[unit]; vio = (struct vnd_ioctl *)addr; switch (cmd) { case VNDIOCSET: if (sc->sc_flags & VNF_INITED) return (EBUSY); /* Geometry eventually has to fit into label fields */ if (vio->vnd_secsize > UINT_MAX || vio->vnd_ntracks > UINT_MAX || vio->vnd_nsectors > UINT_MAX) return (EINVAL); if ((error = disk_lock(&sc->sc_dk)) != 0) return (error); if ((error = copyinstr(vio->vnd_file, sc->sc_file, sizeof(sc->sc_file), NULL))) { disk_unlock(&sc->sc_dk); return (error); } /* Set geometry for device. */ sc->sc_secsize = vio->vnd_secsize; sc->sc_ntracks = vio->vnd_ntracks; sc->sc_nsectors = vio->vnd_nsectors; /* * Open for read and write first. This lets vn_open() weed out * directories, sockets, etc. so we don't have to worry about * them. */ NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, vio->vnd_file, p); sc->sc_flags &= ~VNF_READONLY; error = vn_open(&nd, FREAD|FWRITE, 0); if (error == EROFS) { sc->sc_flags |= VNF_READONLY; error = vn_open(&nd, FREAD, 0); } if (error) { disk_unlock(&sc->sc_dk); return (error); } if (nd.ni_vp->v_type == VBLK) sc->sc_size = vndbdevsize(nd.ni_vp, p); else { error = VOP_GETATTR(nd.ni_vp, &vattr, p->p_ucred, p); if (error) { VOP_UNLOCK(nd.ni_vp, 0, p); vn_close(nd.ni_vp, VNDRW(sc), p->p_ucred, p); disk_unlock(&sc->sc_dk); return (error); } sc->sc_size = vattr.va_size / sc->sc_secsize; } VOP_UNLOCK(nd.ni_vp, 0, p); sc->sc_vp = nd.ni_vp; if ((error = vndsetcred(sc, p->p_ucred)) != 0) { (void) vn_close(nd.ni_vp, VNDRW(sc), p->p_ucred, p); disk_unlock(&sc->sc_dk); return (error); } if (vio->vnd_keylen > 0) { char key[BLF_MAXUTILIZED]; if (vio->vnd_keylen > sizeof(key)) vio->vnd_keylen = sizeof(key); if ((error = copyin(vio->vnd_key, key, vio->vnd_keylen)) != 0) { (void) vn_close(nd.ni_vp, VNDRW(sc), p->p_ucred, p); disk_unlock(&sc->sc_dk); return (error); } sc->sc_keyctx = malloc(sizeof(*sc->sc_keyctx), M_DEVBUF, M_WAITOK); blf_key(sc->sc_keyctx, key, vio->vnd_keylen); explicit_bzero(key, vio->vnd_keylen); } else sc->sc_keyctx = NULL; vio->vnd_size = sc->sc_size * sc->sc_secsize; sc->sc_flags |= VNF_INITED; DNPRINTF(VDB_INIT, "vndioctl: SET vp %p size %llx\n", sc->sc_vp, (unsigned long long)sc->sc_size); /* Attach the disk. */ sc->sc_dk.dk_name = sc->sc_dev.dv_xname; disk_attach(&sc->sc_dev, &sc->sc_dk); disk_unlock(&sc->sc_dk); break; case VNDIOCCLR: if ((sc->sc_flags & VNF_INITED) == 0) return (ENXIO); if ((error = disk_lock(&sc->sc_dk)) != 0) return (error); /* * Don't unconfigure if any other partitions are open * or if both the character and block flavors of this * partition are open. */ part = DISKPART(dev); pmask = (1 << part); if ((sc->sc_dk.dk_openmask & ~pmask) || ((sc->sc_dk.dk_bopenmask & pmask) && (sc->sc_dk.dk_copenmask & pmask))) { disk_unlock(&sc->sc_dk); return (EBUSY); } vndclear(sc); DNPRINTF(VDB_INIT, "vndioctl: CLRed\n"); /* Free crypto key */ if (sc->sc_keyctx) { explicit_bzero(sc->sc_keyctx, sizeof(*sc->sc_keyctx)); free(sc->sc_keyctx, M_DEVBUF, sizeof(*sc->sc_keyctx)); } /* Detach the disk. */ disk_detach(&sc->sc_dk); disk_unlock(&sc->sc_dk); break; case VNDIOCGET: vnu = (struct vnd_user *)addr; if (vnu->vnu_unit == -1) vnu->vnu_unit = unit; if (vnu->vnu_unit >= numvnd) return (ENXIO); if (vnu->vnu_unit < 0) return (EINVAL); sc = &vnd_softc[vnu->vnu_unit]; if (sc->sc_flags & VNF_INITED) { error = VOP_GETATTR(sc->sc_vp, &vattr, p->p_ucred, p); if (error) return (error); strlcpy(vnu->vnu_file, sc->sc_file, sizeof(vnu->vnu_file)); vnu->vnu_dev = vattr.va_fsid; vnu->vnu_ino = vattr.va_fileid; } else { vnu->vnu_dev = 0; vnu->vnu_ino = 0; } break; case DIOCRLDINFO: if ((sc->sc_flags & VNF_HAVELABEL) == 0) return (ENOTTY); lp = malloc(sizeof(*lp), M_TEMP, M_WAITOK); vndgetdisklabel(dev, sc, lp, 0); *(sc->sc_dk.dk_label) = *lp; free(lp, M_TEMP, sizeof(*lp)); return (0); case DIOCGPDINFO: if ((sc->sc_flags & VNF_HAVELABEL) == 0) return (ENOTTY); vndgetdisklabel(dev, sc, (struct disklabel *)addr, 1); return (0); case DIOCGDINFO: if ((sc->sc_flags & VNF_HAVELABEL) == 0) return (ENOTTY); *(struct disklabel *)addr = *(sc->sc_dk.dk_label); return (0); case DIOCGPART: if ((sc->sc_flags & VNF_HAVELABEL) == 0) return (ENOTTY); ((struct partinfo *)addr)->disklab = sc->sc_dk.dk_label; ((struct partinfo *)addr)->part = &sc->sc_dk.dk_label->d_partitions[DISKPART(dev)]; return (0); case DIOCWDINFO: case DIOCSDINFO: if ((sc->sc_flags & VNF_HAVELABEL) == 0) return (ENOTTY); if ((flag & FWRITE) == 0) return (EBADF); if ((error = disk_lock(&sc->sc_dk)) != 0) return (error); error = setdisklabel(sc->sc_dk.dk_label, (struct disklabel *)addr, /* sc->sc_dk.dk_openmask */ 0); if (error == 0) { if (cmd == DIOCWDINFO) error = writedisklabel(DISKLABELDEV(dev), vndstrategy, sc->sc_dk.dk_label); } disk_unlock(&sc->sc_dk); return (error); default: return (ENOTTY); } return (0); }