static int /* O - 0 = success, non-0 = failure */ smb_print(struct cli_state *cli, /* I - SMB connection */ char *title, /* I - Title/job name */ FILE *fp) /* I - File to print */ { int fnum; /* File number */ int nbytes, /* Number of bytes read */ tbytes; /* Total bytes read */ char buffer[8192], /* Buffer for copy */ *ptr; /* Pointer into tile */ /* * Sanitize the title... */ for (ptr = title; *ptr; ptr ++) if (!isalnum((int)*ptr) && !isspace((int)*ptr)) *ptr = '_'; /* * Open the printer device... */ if ((fnum = cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE)) == -1) { fprintf(stderr, "ERROR: %s opening remote spool %s\n", cli_errstr(cli), title); return (1); } /* * Copy the file to the printer... */ if (fp != stdin) rewind(fp); tbytes = 0; while ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) { if (cli_write(cli, fnum, 0, buffer, tbytes, nbytes) != nbytes) { fprintf(stderr, "ERROR: Error writing spool: %s\n", cli_errstr(cli)); break; } tbytes += nbytes; } if (!cli_close(cli, fnum)) { fprintf(stderr, "ERROR: %s closing remote spool %s\n", cli_errstr(cli), title); return (1); } else return (0); }
NTSTATUS gpo_copy_file(TALLOC_CTX *mem_ctx, struct cli_state *cli, const char *nt_path, const char *unix_path) { NTSTATUS result; int fnum; int fd = 0; char *data = NULL; static int io_bufsize = 64512; int read_size = io_bufsize; off_t start = 0; off_t nread = 0; if ((fnum = cli_open(cli, nt_path, O_RDONLY, DENY_NONE)) == -1) { result = NT_STATUS_NO_SUCH_FILE; goto out; } if ((fd = sys_open(unix_path, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) { result = map_nt_error_from_unix(errno); goto out; } if ((data = (char *)SMB_MALLOC(read_size)) == NULL) { result = NT_STATUS_NO_MEMORY; goto out; } while (1) { int n = cli_read(cli, fnum, data, nread + start, read_size); if (n <= 0) break; if (write(fd, data, n) != n) { break; } nread += n; } result = NT_STATUS_OK; out: SAFE_FREE(data); if (fnum) { cli_close(cli, fnum); } if (fd) { close(fd); } return result; }
static void testpair(struct cli_state *cli1, struct cli_state *cli2, char *mask, char *file) { int fnum; fstring res1, res2; char *res3; static int count; count++; fstrcpy(res1, "---"); fstrcpy(res2, "---"); fnum = cli_open(cli1, file, O_CREAT|O_TRUNC|O_RDWR, 0); if (fnum == -1) { DEBUG(0,("Can't create %s on cli1\n", file)); return; } cli_close(cli1, fnum); fnum = cli_open(cli2, file, O_CREAT|O_TRUNC|O_RDWR, 0); if (fnum == -1) { DEBUG(0,("Can't create %s on cli2\n", file)); return; } cli_close(cli2, fnum); resultp = res1; cli_list(cli1, mask, aHIDDEN | aDIR, listfn); res3 = reg_test(mask, file); resultp = res2; cli_list(cli2, mask, aHIDDEN | aDIR, listfn); if (showall || strcmp(res1, res2)) { DEBUG(0,("%s %s %s %d mask=[%s] file=[%s]\n", res1, res2, res3, count, mask, file)); } cli_unlink(cli1, file); cli_unlink(cli2, file); }
bool torture_trans2_scan(int dummy) { static struct cli_state *cli; int op, level; const char *fname = "\\scanner.dat"; uint16_t fnum, dnum; printf("starting trans2 scan test\n"); if (!torture_open_connection(&cli, 0)) { return False; } if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) { printf("open of %s failed\n", fname); return false; } if (!NT_STATUS_IS_OK(cli_open(cli, "\\", O_RDONLY, DENY_NONE, &dnum))) { printf("open of \\ failed\n"); return false; } for (op=OP_MIN; op<=OP_MAX; op++) { printf("Scanning op=%d\n", op); for (level = 0; level <= 50; level++) { scan_trans2(cli, op, level, fnum, dnum, fname); } for (level = 0x100; level <= 0x130; level++) { scan_trans2(cli, op, level, fnum, dnum, fname); } for (level = 1000; level < 1050; level++) { scan_trans2(cli, op, level, fnum, dnum, fname); } } torture_close_connection(cli); printf("trans2 scan finished\n"); return True; }
bool torture_nttrans_scan(int dummy) { static struct cli_state *cli; int op, level; const char *fname = "\\scanner.dat"; int fnum, dnum; printf("starting nttrans scan test\n"); if (!torture_open_connection(&cli, 0)) { return False; } fnum = cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); dnum = cli_open(cli, "\\", O_RDONLY, DENY_NONE); for (op=OP_MIN; op<=OP_MAX; op++) { printf("Scanning op=%d\n", op); for (level = 0; level <= 50; level++) { scan_nttrans(cli, op, level, fnum, dnum, fname); } for (level = 0x100; level <= 0x130; level++) { scan_nttrans(cli, op, level, fnum, dnum, fname); } for (level = 1000; level < 1050; level++) { scan_nttrans(cli, op, level, fnum, dnum, fname); } } torture_close_connection(cli); printf("nttrans scan finished\n"); return True; }
static void open_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], int fnum[NSERVERS][NCONNECTIONS][NFILES]) { int server, conn, f; for (server=0;server<NSERVERS;server++) for (conn=0;conn<NCONNECTIONS;conn++) for (f=0;f<NFILES;f++) { fnum[server][conn][f] = cli_open(cli[server][conn], FILENAME, O_RDWR|O_CREAT, DENY_NONE); if (fnum[server][conn][f] == -1) { fprintf(stderr,"Failed to open fnum[%u][%u][%u]\n", server, conn, f); exit(1); } } }
void nb_open(char *fname, int handle, int size) { int fd, i; int flags = O_RDWR|O_CREAT; size_t st_size; static int count; strupper(fname); if (size == 0) flags |= O_TRUNC; fd = cli_open(c, fname, flags, DENY_NONE); if (fd == -1) { #if NBDEBUG printf("(%d) open %s failed for handle %d (%s)\n", line_count, fname, handle, cli_errstr(c)); #endif return; } cli_getattrE(c, fd, NULL, &st_size, NULL, NULL, NULL); if (size > st_size) { #if NBDEBUG printf("(%d) needs expanding %s to %d from %d\n", line_count, fname, size, (int)st_size); #endif } else if (size < st_size) { #if NBDEBUG printf("(%d) needs truncating %s to %d from %d\n", line_count, fname, size, (int)st_size); #endif } for (i=0;i<MAX_FILES;i++) { if (ftable[i].handle == 0) break; } if (i == MAX_FILES) { printf("file table full for %s\n", fname); exit(1); } ftable[i].handle = handle; ftable[i].fd = fd; if (count++ % 100 == 0) { printf("."); } }
/***************************************************** a wrapper for open() *******************************************************/ int smbw_open(const char *fname, int flags, mode_t mode) { fstring server, share; pstring path; struct smbw_server *srv=NULL; int eno=0, fd = -1; struct smbw_file *file=NULL; smbw_init(); if (!fname) { errno = EINVAL; return -1; } smbw_busy++; /* work out what server they are after */ smbw_parse_path(fname, server, share, path); /* get a connection to the server */ srv = smbw_server(server, share); if (!srv) { /* smbw_server sets errno */ goto failed; } if (path[strlen(path)-1] == '\\') { fd = -1; } else { fd = cli_open(&srv->cli, path, flags, DENY_NONE); } if (fd == -1) { /* it might be a directory. Maybe we should use chkpath? */ eno = smbw_errno(&srv->cli); fd = smbw_dir_open(fname); if (fd == -1) errno = eno; smbw_busy--; return fd; } file = (struct smbw_file *)malloc(sizeof(*file)); if (!file) { errno = ENOMEM; goto failed; } ZERO_STRUCTP(file); file->f = (struct smbw_filedes *)malloc(sizeof(*(file->f))); if (!file->f) { errno = ENOMEM; goto failed; } ZERO_STRUCTP(file->f); file->f->cli_fd = fd; file->f->fname = strdup(path); if (!file->f->fname) { errno = ENOMEM; goto failed; } file->srv = srv; file->fd = open(SMBW_DUMMY, O_WRONLY); if (file->fd == -1) { errno = EMFILE; goto failed; } if (bitmap_query(smbw_file_bmap, file->fd)) { DEBUG(0,("ERROR: fd used in smbw_open\n")); errno = EIO; goto failed; } file->f->ref_count=1; bitmap_set(smbw_file_bmap, file->fd); DLIST_ADD(smbw_files, file); DEBUG(4,("opened %s\n", fname)); smbw_busy--; return file->fd; failed: if (fd != -1) { cli_close(&srv->cli, fd); } if (file) { if (file->f) { SAFE_FREE(file->f->fname); SAFE_FREE(file->f); } SAFE_FREE(file); } smbw_busy--; return -1; }
static bool test_one(struct cli_state *cli[NSERVERS][NCONNECTIONS], uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES], struct record *rec) { unsigned conn = rec->conn; unsigned f = rec->f; uint64_t start = rec->start; uint64_t len = rec->len; enum brl_type op = rec->lock_type; int server; NTSTATUS status[NSERVERS]; switch (rec->lock_op) { case OP_LOCK: /* set a lock */ for (server=0;server<NSERVERS;server++) { status[server] = cli_lock64(cli[server][conn], fnum[server][conn][f], start, len, LOCK_TIMEOUT, op); if (!exact_error_codes && NT_STATUS_EQUAL(status[server], NT_STATUS_FILE_LOCK_CONFLICT)) { status[server] = NT_STATUS_LOCK_NOT_GRANTED; } } if (showall || !NT_STATUS_EQUAL(status[0],status[1])) { printf("lock conn=%u f=%u range=%.0f(%.0f) op=%s -> %s:%s\n", conn, f, (double)start, (double)len, op==READ_LOCK?"READ_LOCK":"WRITE_LOCK", nt_errstr(status[0]), nt_errstr(status[1])); } if (showall || !NT_STATUS_EQUAL(status[0],status[1])) show_locks(); if (!NT_STATUS_EQUAL(status[0],status[1])) return False; break; case OP_UNLOCK: /* unset a lock */ for (server=0;server<NSERVERS;server++) { status[server] = cli_unlock64(cli[server][conn], fnum[server][conn][f], start, len); } if (showall || (!hide_unlock_fails && !NT_STATUS_EQUAL(status[0],status[1]))) { printf("unlock conn=%u f=%u range=%.0f(%.0f) -> %s:%s\n", conn, f, (double)start, (double)len, nt_errstr(status[0]), nt_errstr(status[1])); } if (showall || !NT_STATUS_EQUAL(status[0],status[1])) show_locks(); if (!hide_unlock_fails && !NT_STATUS_EQUAL(status[0],status[1])) return False; break; case OP_REOPEN: /* reopen the file */ for (server=0;server<NSERVERS;server++) { cli_close(cli[server][conn], fnum[server][conn][f]); fnum[server][conn][f] = (uint16_t)-1; } for (server=0;server<NSERVERS;server++) { fnum[server][conn][f] = (uint16_t)-1; if (!NT_STATUS_IS_OK(cli_open(cli[server][conn], FILENAME, O_RDWR|O_CREAT, DENY_NONE, &fnum[server][conn][f]))) { printf("failed to reopen on share%d\n", server); return False; } } if (showall) { printf("reopen conn=%u f=%u\n", conn, f); show_locks(); } break; } return True; }
bool torture_utable(int dummy) { struct cli_state *cli; fstring fname, alt_name; uint16_t fnum; smb_ucs2_t c2; int c, len, fd; int chars_allowed=0, alt_allowed=0; uint8 valid[0x10000]; printf("starting utable\n"); if (!torture_open_connection(&cli, 0)) { return False; } memset(valid, 0, sizeof(valid)); cli_mkdir(cli, "\\utable"); cli_unlink(cli, "\\utable\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); for (c=1; c < 0x10000; c++) { size_t size = 0; char *p; SSVAL(&c2, 0, c); fstrcpy(fname, "\\utable\\x"); p = fname+strlen(fname); if (!convert_string(CH_UTF16LE, CH_UNIX, &c2, 2, p, sizeof(fname)-strlen(fname),&size)) { d_printf("convert_string %s failed !\n", fname); continue; } len = size; p[len] = 0; fstrcat(fname,"_a_long_extension"); if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) { continue; } chars_allowed++; cli_qpathinfo_alt_name(cli, fname, alt_name); if (strncmp(alt_name, "X_A_L", 5) != 0) { alt_allowed++; valid[c] = 1; d_printf("fname=[%s] alt_name=[%s]\n", fname, alt_name); } cli_close(cli, fnum); cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); if (c % 100 == 0) { printf("%d (%d/%d)\r", c, chars_allowed, alt_allowed); } } printf("%d (%d/%d)\n", c, chars_allowed, alt_allowed); cli_rmdir(cli, "\\utable"); d_printf("%d chars allowed %d alt chars allowed\n", chars_allowed, alt_allowed); fd = open("valid.dat", O_WRONLY|O_CREAT|O_TRUNC, 0644); if (fd == -1) { d_printf("Failed to create valid.dat - %s", strerror(errno)); return False; } if (write(fd, valid, 0x10000) != 0x10000) { d_printf("Failed to create valid.dat - %s", strerror(errno)); close(fd); return false; } close(fd); d_printf("wrote valid.dat\n"); return True; }
/** * @brief Runs the input command. * * @param keynum The index of the keybind. * @param value The value of the keypress (defined above). * @param kabs The absolute value. */ static void input_key( int keynum, double value, double kabs, int repeat ) { unsigned int t; HookParam hparam[3]; /* Repetition stuff. */ if (conf.repeat_delay != 0) { if ((value == KEY_PRESS) && !repeat) { repeat_key = keynum; repeat_keyTimer = SDL_GetTicks(); repeat_keyCounter = 0; } else if (value == KEY_RELEASE) { repeat_key = -1; repeat_keyTimer = 0; repeat_keyCounter = 0; } } /* * movement */ /* accelerating */ if (KEY("accel") && !repeat) { if (kabs >= 0.) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_accel(kabs); input_accelButton = 1; } else { /* prevent it from getting stuck */ if (value==KEY_PRESS) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_ACCEL); player_accel(1.); input_accelButton = 1; } else if (value==KEY_RELEASE) { player_accelOver(); player_rmFlag(PLAYER_ACCEL); input_accelButton = 0; } /* double tap accel = afterburn! */ t = SDL_GetTicks(); if ((conf.afterburn_sens != 0) && (value==KEY_PRESS) && INGAME() && NOHYP() && NODEAD() && (t-input_accelLast <= conf.afterburn_sens)) pilot_afterburn( player.p ); else if (value==KEY_RELEASE) pilot_afterburnOver( player.p ); if (value==KEY_PRESS) input_accelLast = t; } /* turning left */ } else if (KEY("left") && !repeat) { if (kabs >= 0.) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_TURN_LEFT); player_left = kabs; } else { /* set flags for facing correction */ if (value==KEY_PRESS) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_TURN_LEFT); player_left = 1.; } else if (value==KEY_RELEASE) { player_rmFlag(PLAYER_TURN_LEFT); player_left = 0.; } } /* turning right */ } else if (KEY("right") && !repeat) { if (kabs >= 0.) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_TURN_RIGHT); player_right = kabs; } else { /* set flags for facing correction */ if (value==KEY_PRESS) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_TURN_RIGHT); player_right = 1.; } else if (value==KEY_RELEASE) { player_rmFlag(PLAYER_TURN_RIGHT); player_right = 0.; } } /* turn around to face vel */ } else if (KEY("reverse") && !repeat) { if (value==KEY_PRESS) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_REVERSE); } else if ((value==KEY_RELEASE) && player_isFlag(PLAYER_REVERSE)) { player_rmFlag(PLAYER_REVERSE); if (!player_isFlag(PLAYER_ACCEL)) player_accelOver(); } /* * combat */ /* shooting primary weapon */ } else if (KEY("primary") && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_setFlag(PLAYER_PRIMARY); } else if (value==KEY_RELEASE) player_rmFlag(PLAYER_PRIMARY); /* targeting */ } else if (INGAME() && NODEAD() && KEY("target_next")) { if (value==KEY_PRESS) player_targetNext(0); } else if (INGAME() && NODEAD() && KEY("target_prev")) { if (value==KEY_PRESS) player_targetPrev(0); } else if (INGAME() && NODEAD() && KEY("target_nearest")) { if (value==KEY_PRESS) player_targetNearest(); } else if (INGAME() && NODEAD() && KEY("target_nextHostile")) { if (value==KEY_PRESS) player_targetNext(1); } else if (INGAME() && NODEAD() && KEY("target_prevHostile")) { if (value==KEY_PRESS) player_targetPrev(1); } else if (INGAME() && NODEAD() && KEY("target_hostile")) { if (value==KEY_PRESS) player_targetHostile(); } else if (INGAME() && NODEAD() && KEY("target_clear")) { if (value==KEY_PRESS) player_targetClear(); /* face the target */ } else if (INGAME() && NODEAD() && KEY("face") && !repeat) { if (value==KEY_PRESS) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_FACE); } else if ((value==KEY_RELEASE) && player_isFlag(PLAYER_FACE)) player_rmFlag(PLAYER_FACE); /* board them ships */ } else if (KEY("board") && INGAME() && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_restoreControl( 0, NULL ); player_board(); } /* * Escorts. */ } else if (INGAME() && NODEAD() && KEY("e_targetNext") && !repeat) { if (value==KEY_PRESS) player_targetEscort(0); } else if (INGAME() && NODEAD() && KEY("e_targetPrev") && !repeat) { if (value==KEY_PRESS) player_targetEscort(1); } else if (INGAME() && NODEAD() && KEY("e_attack") && !repeat) { if (value==KEY_PRESS) escorts_attack(player.p); } else if (INGAME() && NODEAD() && KEY("e_hold") && !repeat) { if (value==KEY_PRESS) escorts_hold(player.p); } else if (INGAME() && NODEAD() && KEY("e_return") && !repeat) { if (value==KEY_PRESS) escorts_return(player.p); } else if (INGAME() && NODEAD() && KEY("e_clear") && !repeat) { if (value==KEY_PRESS) escorts_clear(player.p); /* * secondary weapons */ /* shooting secondary weapon */ } else if (KEY("secondary") && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_setFlag(PLAYER_SECONDARY); } else if (value==KEY_RELEASE) player_rmFlag(PLAYER_SECONDARY); /* Weapon sets. */ } else if (KEY("weapset1")) { player_weapSetPress( 0, value, repeat ); } else if (KEY("weapset2")) { player_weapSetPress( 1, value, repeat ); } else if (KEY("weapset3")) { player_weapSetPress( 2, value, repeat ); } else if (KEY("weapset4")) { player_weapSetPress( 3, value, repeat ); } else if (KEY("weapset5")) { player_weapSetPress( 4, value, repeat ); } else if (KEY("weapset6")) { player_weapSetPress( 5, value, repeat ); } else if (KEY("weapset7")) { player_weapSetPress( 6, value, repeat ); } else if (KEY("weapset8")) { player_weapSetPress( 7, value, repeat ); } else if (KEY("weapset9")) { player_weapSetPress( 8, value, repeat ); } else if (KEY("weapset0")) { player_weapSetPress( 9, value, repeat ); /* * space */ } else if (KEY("autonav") && INGAME() && NOHYP() && NODEAD()) { if (value==KEY_PRESS) player_autonavStart(); /* target planet (cycles like target) */ } else if (KEY("target_planet") && INGAME() && NOHYP() && NOLAND() && NODEAD()) { if (value==KEY_PRESS) player_targetPlanet(); /* target nearest planet or attempt to land */ } else if (KEY("land") && INGAME() && NOHYP() && NOLAND() && NODEAD()) { if (value==KEY_PRESS) player_land(); } else if (KEY("thyperspace") && NOHYP() && NOLAND() && NODEAD()) { if (value==KEY_PRESS) player_targetHyperspace(); } else if (KEY("starmap") && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) map_open(); } else if (KEY("jump") && INGAME() && !repeat) { if (value==KEY_PRESS) { player_restoreControl( 0, NULL ); player_jump(); } } else if (KEY("overlay") && NODEAD() && INGAME() && !repeat) { ovr_key( value ); } else if (KEY("mousefly") && NODEAD() && !repeat) { if (value==KEY_PRESS) player_toggleMouseFly(); } else if (KEY("autobrake") && NOHYP() && NOLAND() && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_restoreControl( PINPUT_BRAKING, NULL ); player_brake(); } /* * Communication. */ } else if (KEY("log_up") && INGAME() && NODEAD()) { if (value==KEY_PRESS) { gui_messageScrollUp(5); } } else if (KEY("log_down") && INGAME() && NODEAD()) { if (value==KEY_PRESS) { gui_messageScrollDown(5); } } else if (KEY("hail") && INGAME() && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_hail(); } } else if (KEY("autohail") && INGAME() && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_autohail(); } /* * misc */ /* zooming in */ } else if (KEY("mapzoomin") && INGAME() && NODEAD()) { if (value==KEY_PRESS) gui_setRadarRel(-1); /* zooming out */ } else if (KEY("mapzoomout") && INGAME() && NODEAD()) { if (value==KEY_PRESS) gui_setRadarRel(1); /* take a screenshot */ } else if (KEY("screenshot")) { if (value==KEY_PRESS) player_screenshot(); #if SDL_VERSION_ATLEAST(2,0,0) /* toggle fullscreen */ } else if (KEY("togglefullscreen") && !repeat) { if (value==KEY_PRESS) naev_toggleFullscreen(); #endif /* SDL_VERSION_ATLEAST(2,0,0) */ /* pause the games */ } else if (KEY("pause") && !repeat) { if (value==KEY_PRESS) { if (!toolkit_isOpen()) { if (paused) unpause_game(); else pause_player(); } } /* toggle speed mode */ } else if (KEY("speed") && !repeat) { if ((value==KEY_PRESS) && (!player_isFlag( PLAYER_CINEMATICS_2X ))) { if (player_isFlag(PLAYER_DOUBLESPEED)) { if (!player_isFlag(PLAYER_AUTONAV)) pause_setSpeed(1.); player_rmFlag(PLAYER_DOUBLESPEED); } else { if (!player_isFlag(PLAYER_AUTONAV)) pause_setSpeed(2.); player_setFlag(PLAYER_DOUBLESPEED); } } /* opens a small menu */ } else if (KEY("menu") && NODEAD() && !repeat) { if (value==KEY_PRESS) menu_small(); /* shows pilot information */ } else if (KEY("info") && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) menu_info( INFO_MAIN ); /* Opens the Lua console. */ } else if (KEY("console") && NODEAD() && !repeat) { if (value==KEY_PRESS) cli_open(); } /* Key press not used. */ else { return; } /* Run the hook. */ hparam[0].type = HOOK_PARAM_STRING; hparam[0].u.str = input_keybinds[keynum].name; hparam[1].type = HOOK_PARAM_BOOL; hparam[1].u.b = (value > 0.); hparam[2].type = HOOK_PARAM_SENTINEL; hooks_runParam( "input", hparam ); }
/* * Set file info on an SMB server. Use setpathinfo call first. If that * fails, use setattrE.. * * Access and modification time parameters are always used and must be * provided. Create time, if zero, will be determined from the actual create * time of the file. If non-zero, the create time will be set as well. * * "mode" (attributes) parameter may be set to -1 if it is not to be set. */ bool SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path, time_t create_time, time_t access_time, time_t write_time, time_t change_time, uint16_t mode) { uint16_t fd; int ret; TALLOC_CTX *frame = talloc_stackframe(); /* * First, try setpathinfo (if qpathinfo succeeded), for it is the * modern function for "new code" to be using, and it works given a * filename rather than requiring that the file be opened to have its * attributes manipulated. */ if (srv->no_pathinfo || !NT_STATUS_IS_OK(cli_setpathinfo_basic(srv->cli, path, create_time, access_time, write_time, change_time, mode))) { /* * setpathinfo is not supported; go to plan B. * * cli_setatr() does not work on win98, and it also doesn't * support setting the access time (only the modification * time), so in all cases, we open the specified file and use * cli_setattrE() which should work on all OS versions, and * supports both times. */ /* Don't try {q,set}pathinfo() again, with this server */ srv->no_pathinfo = True; /* Open the file */ if (!NT_STATUS_IS_OK(cli_open(srv->cli, path, O_RDWR, DENY_NONE, &fd))) { errno = SMBC_errno(context, srv->cli); TALLOC_FREE(frame); return -1; } /* Set the new attributes */ ret = NT_STATUS_IS_OK(cli_setattrE(srv->cli, fd, change_time, access_time, write_time)); /* Close the file */ cli_close(srv->cli, fd); /* * Unfortunately, setattrE() doesn't have a provision for * setting the access mode (attributes). We'll have to try * cli_setatr() for that, and with only this parameter, it * seems to work on win98. */ if (ret && mode != (uint16_t) -1) { ret = NT_STATUS_IS_OK(cli_setatr(srv->cli, path, mode, 0)); } if (! ret) { errno = SMBC_errno(context, srv->cli); TALLOC_FREE(frame); return False; } } TALLOC_FREE(frame); return True; }
static int /* O - 0 = success, non-0 = failure */ smb_print(struct cli_state * cli, /* I - SMB connection */ char *title, /* I - Title/job name */ FILE * fp) { /* I - File to print */ uint16_t fnum; /* File number */ int nbytes, /* Number of bytes read */ tbytes; /* Total bytes read */ char buffer[8192], /* Buffer for copy */ *ptr; /* Pointer into title */ NTSTATUS nt_status; /* * Sanitize the title... */ for (ptr = title; *ptr; ptr++) { if (!isalnum((int) *ptr) && !isspace((int) *ptr)) { *ptr = '_'; } } /* * Open the printer device... */ nt_status = cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum); if (!NT_STATUS_IS_OK(nt_status)) { fprintf(stderr, "ERROR: %s opening remote spool %s\n", nt_errstr(nt_status), title); return get_exit_code(cli, nt_status); } /* * Copy the file to the printer... */ if (fp != stdin) rewind(fp); tbytes = 0; while ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) { NTSTATUS status; status = cli_writeall(cli, fnum, 0, (uint8_t *)buffer, tbytes, nbytes, NULL); if (!NT_STATUS_IS_OK(status)) { int ret = get_exit_code(cli, status); fprintf(stderr, "ERROR: Error writing spool: %s\n", nt_errstr(status)); fprintf(stderr, "DEBUG: Returning status %d...\n", ret); cli_close(cli, fnum); return (ret); } tbytes += nbytes; } nt_status = cli_close(cli, fnum); if (!NT_STATUS_IS_OK(nt_status)) { fprintf(stderr, "ERROR: %s closing remote spool %s\n", nt_errstr(nt_status), title); return get_exit_code(cli, nt_status); } else { return (0); } }
SMBCFILE * SMBC_open_ctx(SMBCCTX *context, const char *fname, int flags, mode_t mode) { char *server = NULL; char *share = NULL; char *user = NULL; char *password = NULL; char *workgroup = NULL; char *path = NULL; char *targetpath = NULL; struct cli_state *targetcli = NULL; SMBCSRV *srv = NULL; SMBCFILE *file = NULL; uint16_t fd; uint16_t port = 0; NTSTATUS status = NT_STATUS_OBJECT_PATH_INVALID; TALLOC_CTX *frame = talloc_stackframe(); if (!context || !context->internal->initialized) { errno = EINVAL; /* Best I can think of ... */ TALLOC_FREE(frame); return NULL; } if (!fname) { errno = EINVAL; TALLOC_FREE(frame); return NULL; } if (SMBC_parse_path(frame, context, fname, &workgroup, &server, &port, &share, &path, &user, &password, NULL)) { errno = EINVAL; TALLOC_FREE(frame); return NULL; } if (!user || user[0] == (char)0) { user = talloc_strdup(frame, smbc_getUser(context)); if (!user) { errno = ENOMEM; TALLOC_FREE(frame); return NULL; } } srv = SMBC_server(frame, context, True, server, port, share, &workgroup, &user, &password); if (!srv) { if (errno == EPERM) errno = EACCES; TALLOC_FREE(frame); return NULL; /* SMBC_server sets errno */ } /* Hmmm, the test for a directory is suspect here ... FIXME */ if (strlen(path) > 0 && path[strlen(path) - 1] == '\\') { status = NT_STATUS_OBJECT_PATH_INVALID; } else { file = SMB_MALLOC_P(SMBCFILE); if (!file) { errno = ENOMEM; TALLOC_FREE(frame); return NULL; } ZERO_STRUCTP(file); /*d_printf(">>>open: resolving %s\n", path);*/ status = cli_resolve_path( frame, "", context->internal->auth_info, srv->cli, path, &targetcli, &targetpath); if (!NT_STATUS_IS_OK(status)) { d_printf("Could not resolve %s\n", path); errno = ENOENT; SAFE_FREE(file); TALLOC_FREE(frame); return NULL; } /*d_printf(">>>open: resolved %s as %s\n", path, targetpath);*/ status = cli_open(targetcli, targetpath, flags, context->internal->share_mode, &fd); if (!NT_STATUS_IS_OK(status)) { /* Handle the error ... */ SAFE_FREE(file); errno = SMBC_errno(context, targetcli); TALLOC_FREE(frame); return NULL; } /* Fill in file struct */ file->cli_fd = fd; file->fname = SMB_STRDUP(fname); file->srv = srv; file->offset = 0; file->file = True; /* * targetcli is either equal to srv->cli or * is a subsidiary DFS connection. Either way * file->cli_fd belongs to it so we must cache * it for read/write/close, not re-resolve each time. * Re-resolving is both slow and incorrect. */ file->targetcli = targetcli; DLIST_ADD(context->internal->files, file); /* * If the file was opened in O_APPEND mode, all write * operations should be appended to the file. To do that, * though, using this protocol, would require a getattrE() * call for each and every write, to determine where the end * of the file is. (There does not appear to be an append flag * in the protocol.) Rather than add all of that overhead of * retrieving the current end-of-file offset prior to each * write operation, we'll assume that most append operations * will continuously write, so we'll just set the offset to * the end of the file now and hope that's adequate. * * Note to self: If this proves inadequate, and O_APPEND * should, in some cases, be forced for each write, add a * field in the context options structure, for * "strict_append_mode" which would select between the current * behavior (if FALSE) or issuing a getattrE() prior to each * write and forcing the write to the end of the file (if * TRUE). Adding that capability will likely require adding * an "append" flag into the _SMBCFILE structure to track * whether a file was opened in O_APPEND mode. -- djl */ if (flags & O_APPEND) { if (SMBC_lseek_ctx(context, file, 0, SEEK_END) < 0) { (void) SMBC_close_ctx(context, file); errno = ENXIO; TALLOC_FREE(frame); return NULL; } } TALLOC_FREE(frame); return file; } /* Check if opendir needed ... */ if (!NT_STATUS_IS_OK(status)) { int eno = 0; eno = SMBC_errno(context, srv->cli); file = smbc_getFunctionOpendir(context)(context, fname); if (!file) errno = eno; TALLOC_FREE(frame); return file; } errno = EINVAL; /* FIXME, correct errno ? */ TALLOC_FREE(frame); return NULL; }
static void do_atar(char *rname,char *lname,file_info *finfo1) { int fnum; SMB_BIG_UINT nread=0; char ftype; file_info2 finfo; BOOL close_done = False; BOOL shallitime=True; char data[65520]; int read_size = 65520; int datalen=0; struct timeval tp_start; GetTimeOfDay(&tp_start); ftype = '0'; /* An ordinary file ... */ if (finfo1) { finfo.size = finfo1 -> size; finfo.mode = finfo1 -> mode; finfo.uid = finfo1 -> uid; finfo.gid = finfo1 -> gid; finfo.mtime = finfo1 -> mtime; finfo.atime = finfo1 -> atime; finfo.ctime = finfo1 -> ctime; finfo.name = finfo1 -> name; } else { finfo.size = def_finfo.size; finfo.mode = def_finfo.mode; finfo.uid = def_finfo.uid; finfo.gid = def_finfo.gid; finfo.mtime = def_finfo.mtime; finfo.atime = def_finfo.atime; finfo.ctime = def_finfo.ctime; finfo.name = def_finfo.name; } if (dry_run) { DEBUG(3,("skipping file %s of size %12.0f bytes\n", finfo.name, (double)finfo.size)); shallitime=0; ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); ntarf++; return; } fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE); dos_clean_name(rname); if (fnum == -1) { DEBUG(0,("%s opening remote file %s (%s)\n", cli_errstr(cli),rname, cur_dir)); return; } finfo.name = string_create_s(strlen(rname)); if (finfo.name == NULL) { DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n")); return; } safe_strcpy(finfo.name,rname, strlen(rname)); if (!finfo1) { if (!cli_getattrE(cli, fnum, &finfo.mode, &finfo.size, NULL, &finfo.atime, &finfo.mtime)) { DEBUG(0, ("getattrE: %s\n", cli_errstr(cli))); return; } finfo.ctime = finfo.mtime; } DEBUG(3,("file %s attrib 0x%X\n",finfo.name,finfo.mode)); if (tar_inc && !(finfo.mode & aARCH)) { DEBUG(4, ("skipping %s - archive bit not set\n", finfo.name)); shallitime=0; } else if (!tar_system && (finfo.mode & aSYSTEM)) { DEBUG(4, ("skipping %s - system bit is set\n", finfo.name)); shallitime=0; } else if (!tar_hidden && (finfo.mode & aHIDDEN)) { DEBUG(4, ("skipping %s - hidden bit is set\n", finfo.name)); shallitime=0; } else { DEBUG(3,("getting file %s of size %.0f bytes as a tar file %s", finfo.name, (double)finfo.size, lname)); /* write a tar header, don't bother with mode - just set to 100644 */ writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype); while (nread < finfo.size && !close_done) { DEBUG(3,("nread=%.0f\n",(double)nread)); datalen = cli_read(cli, fnum, data, nread, read_size); if (datalen == -1) { DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli))); break; } nread += datalen; /* if file size has increased since we made file size query, truncate read so tar header for this file will be correct. */ if (nread > finfo.size) { datalen -= nread - finfo.size; DEBUG(0,("File size change - truncating %s to %.0f bytes\n", finfo.name, (double)finfo.size)); } /* add received bits of file to buffer - dotarbuf will * write out in 512 byte intervals */ if (dotarbuf(tarhandle,data,datalen) != datalen) { DEBUG(0,("Error writing to tar file - %s\n", strerror(errno))); break; } if (datalen == 0) { DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname)); break; } datalen=0; } /* pad tar file with zero's if we couldn't get entire file */ if (nread < finfo.size) { DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n", (double)finfo.size, (int)nread)); if (padit(data, sizeof(data), finfo.size - nread)) DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); } /* round tar file to nearest block */ if (finfo.size % TBLOCK) dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK)); ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK); ntarf++; } cli_close(cli, fnum); if (shallitime) { struct timeval tp_end; int this_time; /* if shallitime is true then we didn't skip */ if (tar_reset && !dry_run) (void) do_setrattr(finfo.name, aARCH, ATTRRESET); GetTimeOfDay(&tp_end); this_time = (tp_end.tv_sec - tp_start.tv_sec)*1000 + (tp_end.tv_usec - tp_start.tv_usec)/1000; get_total_time_ms += this_time; get_total_size += finfo.size; if (tar_noisy) { DEBUG(0, ("%12.0f (%7.1f kb/s) %s\n", (double)finfo.size, finfo.size / MAX(0.001, (1.024*this_time)), finfo.name)); } /* Thanks to Carel-Jan Engel ([email protected]) for this one */ DEBUG(3,("(%g kb/s) (average %g kb/s)\n", finfo.size / MAX(0.001, (1.024*this_time)), get_total_size / MAX(0.001, (1.024*get_total_time_ms)))); } }
int main(int argc, char *argv[]) { int res; while (1) { int option_index = 0; int c; static struct option long_options[] = { {"irda", no_argument, NULL, 'i'}, {"bluetooth", required_argument, NULL, 'b'}, {"channel", required_argument, NULL, 'B'}, {"hci", required_argument, NULL, 'd'}, {"usb", required_argument, NULL, 'u'}, {"tty", required_argument, NULL, 't'}, {"network", required_argument, NULL, 'n'}, {"nonblock", no_argument, NULL, 'N'}, {"help", no_argument, NULL, 'h'}, {"usage", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; c = getopt_long (argc, argv, "+ib:B:d:u:t:n:Nh", long_options, &option_index); if (c == -1) break; switch (c) { case 'i': transport = OBEX_TRANS_IRDA; device = NULL; channel = 0; break; case 'b': transport = OBEX_TRANS_BLUETOOTH; device = optarg; channel = -1; break; case 'B': channel = atoi(optarg); break; case 'd': source = optarg; break; case 'u': if (geteuid() != 0) fprintf(stderr, "If USB doesn't work setup permissions in udev or run as superuser.\n"); transport = OBEX_TRANS_USB; device = NULL; channel = atoi(optarg); break; case 't': transport = OBEX_TRANS_CUSTOM; device = optarg; channel = 0; break; case 'n': transport = OBEX_TRANS_INET; device = optarg; channel = 650; { int n; if (sscanf(optarg, "%d.%d.%d.%d", &n, &n, &n, &n) != 4) fprintf(stderr, "Please use dotted quad notation.\n"); } break; case 'N': nonblock = 1; break; case 'h': /* printf("ObexFS %s\n", VERSION); */ printf("Usage: %s [-i | -b <dev> [-B <chan>] [-d <hci>] | -u <dev> | -t <dev> | -n <dev>] [-- <fuse options>]\n" "Transfer files from/to Mobile Equipment.\n" "Copyright (c) 2002-2005 Christian W. Zuckschwerdt\n" "\n" " -i, --irda connect using IrDA transport\n" " -b, --bluetooth <device> connect to this bluetooth device\n" " -B, --channel <number> use this bluetooth channel when connecting\n" " -d, --hci <no/address> use source device with this address or number\n" " -u, --usb <interface> connect to this usb interface number\n" " -t, --tty <device> connect to this tty using a custom transport\n" " -n, --network <device> connect to this network host\n\n" " -N, --nonblock nonblocking mode\n\n" " -h, --help, --usage this help text\n\n" "Options to fusermount need to be preceeded by two dashes (--).\n" "\n", argv[0]); exit(0); break; default: printf("Try `%s --help' for more information.\n", argv[0]); exit(0); } } if (transport == 0) { fprintf(stderr, "No device selected. Use --help for help.\n"); exit(0); } argv[optind-1] = argv[0]; /* Open connection */ res = cli_open(); if(res < 0) return res; /* errno */ /* loop */ fuse_main(argc-optind+1, &argv[optind-1], &ofs_oper); /* Close connection */ cli_close(); return 0; }
NTSTATUS cli_nt_establish_netlogon(struct cli_state *cli, int sec_chan, const uchar trust_password[16]) { NTSTATUS result; uint32 neg_flags = NETLOGON_NEG_AUTH2_FLAGS; int fnum; cli_nt_netlogon_netsec_session_close(cli); if (lp_client_schannel() != False) neg_flags |= NETLOGON_NEG_SCHANNEL; result = cli_nt_setup_creds(cli, sec_chan, trust_password, &neg_flags, 2); if (!NT_STATUS_IS_OK(result)) { cli_nt_session_close(cli); return result; } if ((lp_client_schannel() == True) && ((neg_flags & NETLOGON_NEG_SCHANNEL) == 0)) { DEBUG(3, ("Server did not offer schannel\n")); cli_nt_session_close(cli); return NT_STATUS_UNSUCCESSFUL; } if ((lp_client_schannel() == False) || ((neg_flags & NETLOGON_NEG_SCHANNEL) == 0)) { return NT_STATUS_OK; /* keep the existing connection to NETLOGON open */ } /* Server offered schannel, so try it. */ memcpy(cli->auth_info.sess_key, cli->sess_key, sizeof(cli->auth_info.sess_key)); cli->saved_netlogon_pipe_fnum = cli->nt_pipe_fnum; cli->pipe_auth_flags = AUTH_PIPE_NETSEC; cli->pipe_auth_flags |= AUTH_PIPE_SIGN; cli->pipe_auth_flags |= AUTH_PIPE_SEAL; if (cli->capabilities & CAP_NT_SMBS) { /* The secure channel connection must be opened on the same session (TCP connection) as the one the challenge was requested from. */ if ((fnum = cli_nt_create(cli, PIPE_NETLOGON_PLAIN, DESIRED_ACCESS_PIPE)) == -1) { DEBUG(0,("cli_nt_create failed to %s machine %s. " "Error was %s\n", PIPE_NETLOGON, cli->desthost, cli_errstr(cli))); return NT_STATUS_UNSUCCESSFUL; } cli->nt_pipe_fnum = (uint16)fnum; } else { if ((fnum = cli_open(cli, PIPE_NETLOGON, O_CREAT|O_RDWR, DENY_NONE)) == -1) { DEBUG(0,("cli_open failed on pipe %s to machine %s. " "Error was %s\n", PIPE_NETLOGON, cli->desthost, cli_errstr(cli))); return NT_STATUS_UNSUCCESSFUL; } cli->nt_pipe_fnum = (uint16)fnum; /**************** Set Named Pipe State ***************/ if (!rpc_pipe_set_hnd_state(cli, PIPE_NETLOGON, 0x4300)) { DEBUG(0,("Pipe hnd state failed. Error was %s\n", cli_errstr(cli))); cli_close(cli, cli->nt_pipe_fnum); return NT_STATUS_UNSUCCESSFUL; } } if (!rpc_pipe_bind(cli, PI_NETLOGON, global_myname())) { DEBUG(2,("rpc bind to %s failed\n", PIPE_NETLOGON)); cli_close(cli, cli->nt_pipe_fnum); return NT_STATUS_UNSUCCESSFUL; } return NT_STATUS_OK; }
BOOL cli_nt_session_open(struct cli_state *cli, const int pipe_idx) { int fnum; /* At the moment we can't have more than one pipe open over a cli connection. )-: */ SMB_ASSERT(cli->nt_pipe_fnum == 0); /* The pipe index must fall within our array */ SMB_ASSERT((pipe_idx >= 0) && (pipe_idx < PI_MAX_PIPES)); if (cli->capabilities & CAP_NT_SMBS) { if ((fnum = cli_nt_create(cli, &pipe_names[pipe_idx].client_pipe[5], DESIRED_ACCESS_PIPE)) == -1) { DEBUG(0,("cli_nt_session_open: cli_nt_create failed on pipe %s to machine %s. Error was %s\n", &pipe_names[pipe_idx].client_pipe[5], cli->desthost, cli_errstr(cli))); return False; } cli->nt_pipe_fnum = (uint16)fnum; } else { if ((fnum = cli_open(cli, pipe_names[pipe_idx].client_pipe, O_CREAT|O_RDWR, DENY_NONE)) == -1) { DEBUG(1,("cli_nt_session_open: cli_open failed on pipe %s to machine %s. Error was %s\n", pipe_names[pipe_idx].client_pipe, cli->desthost, cli_errstr(cli))); return False; } cli->nt_pipe_fnum = (uint16)fnum; /**************** Set Named Pipe State ***************/ if (!rpc_pipe_set_hnd_state(cli, pipe_names[pipe_idx].client_pipe, 0x4300)) { DEBUG(0,("cli_nt_session_open: pipe hnd state failed. Error was %s\n", cli_errstr(cli))); cli_close(cli, cli->nt_pipe_fnum); cli->nt_pipe_fnum = 0; return False; } } /******************* bind request on pipe *****************/ if (!rpc_pipe_bind(cli, pipe_idx, global_myname())) { DEBUG(2,("cli_nt_session_open: rpc bind to %s failed\n", get_pipe_name_from_index(pipe_idx))); cli_close(cli, cli->nt_pipe_fnum); cli->nt_pipe_fnum = 0; return False; } cli->pipe_idx = pipe_idx; /* * Setup the remote server name prefixed by \ and the machine account name. */ fstrcpy(cli->srv_name_slash, "\\\\"); fstrcat(cli->srv_name_slash, cli->desthost); strupper_m(cli->srv_name_slash); fstrcpy(cli->clnt_name_slash, "\\\\"); fstrcat(cli->clnt_name_slash, global_myname()); strupper_m(cli->clnt_name_slash); fstrcpy(cli->mach_acct, global_myname()); fstrcat(cli->mach_acct, "$"); strupper_m(cli->mach_acct); /* Remember which pipe we're talking to */ fstrcpy(cli->pipe_name, pipe_names[pipe_idx].client_pipe); return True; }