char *dos_getwd(char *unix_path) { char *wd; wd = sys_getwd(unix_path); if (wd) unix_to_dos(wd, True); return wd; }
char *vfswrap_getwd(vfs_handle_struct *handle, connection_struct *conn, char *path) { char *result; START_PROFILE(syscall_getwd); result = sys_getwd(path); END_PROFILE(syscall_getwd); return result; }
smb_ucs2_t *wsys_getwd(smb_ucs2_t *s) { pstring fname; char *p = sys_getwd(fname); if(!p) return NULL; return unix_to_unicode(s, p, sizeof(wpstring)); }
static int generic_job_submit(int snum, struct printjob *pjob) { int ret; pstring current_directory; pstring print_directory; char *wd, *p; pstring jobname; fstring job_page_count, job_size; /* we print from the directory path to give the best chance of parsing the lpq output */ wd = sys_getwd(current_directory); if (!wd) return 0; pstrcpy(print_directory, pjob->filename); p = strrchr_m(print_directory,'/'); if (!p) return 0; *p++ = 0; if (chdir(print_directory) != 0) return 0; pstrcpy(jobname, pjob->jobname); pstring_sub(jobname, "'", "_"); slprintf(job_page_count, sizeof(job_page_count)-1, "%d", pjob->page_count); slprintf(job_size, sizeof(job_size)-1, "%lu", (unsigned long)pjob->size); /* send it to the system spooler */ ret = print_run_command(snum, PRINTERNAME(snum), True, lp_printcommand(snum), NULL, "%s", p, "%J", jobname, "%f", p, "%z", job_size, "%c", job_page_count, NULL); chdir(wd); return ret; }
/* * This is command is invoked by the user with the following * syntax: * pushd <dir> * * It is intended to help maintain some amount of consistency with * the Tcl interface, this function is not a part of the api because * the particualr implementation may vary based upon OS and interface * details. */ int interface_pushd( int argc, const char **argv, soarResult *res ) { cons *c; char *cdir; if ( argc < 1 ) { return SOAR_ERROR; } c = (cons *) malloc( sizeof( cons ) ); cdir = (char *) malloc( 1024 * sizeof( char ) ); sys_getwd( cdir, 1024 ); c->first = cdir; c->rest = gDirectoryStack; gDirectoryStack = c; sys_chdir( argv[1] ); print( "Changing Directory to '%s'\n", argv[1] ); return SOAR_OK; }
static int generic_job_submit(int snum, struct printjob *pjob, enum printing_types printing_type, char *lpq_cmd) { int ret = -1; char *current_directory = NULL; char *print_directory = NULL; char *wd = NULL; char *p = NULL; char *jobname = NULL; TALLOC_CTX *ctx = talloc_tos(); fstring job_page_count, job_size; print_queue_struct *q; print_status_struct status; /* we print from the directory path to give the best chance of parsing the lpq output */ wd = sys_getwd(); if (!wd) { return -1; } current_directory = talloc_strdup(ctx, wd); SAFE_FREE(wd); if (!current_directory) { return -1; } print_directory = talloc_strdup(ctx, pjob->filename); if (!print_directory) { return -1; } p = strrchr_m(print_directory,'/'); if (!p) { return -1; } *p++ = 0; if (chdir(print_directory) != 0) { return -1; } jobname = talloc_strdup(ctx, pjob->jobname); if (!jobname) { ret = -1; goto out; } jobname = talloc_string_sub(ctx, jobname, "'", "_"); if (!jobname) { ret = -1; goto out; } slprintf(job_page_count, sizeof(job_page_count)-1, "%d", pjob->page_count); slprintf(job_size, sizeof(job_size)-1, "%lu", (unsigned long)pjob->size); /* send it to the system spooler */ ret = print_run_command(snum, lp_printername(talloc_tos(), snum), True, lp_print_command(talloc_tos(), snum), NULL, "%s", p, "%J", jobname, "%f", p, "%z", job_size, "%c", job_page_count, NULL); if (ret != 0) { ret = -1; goto out; } /* * check the queue for the newly submitted job, this allows us to * determine the backend job identifier (sysjob). */ pjob->sysjob = -1; ret = generic_queue_get(lp_printername(talloc_tos(), snum), printing_type, lpq_cmd, &q, &status); if (ret > 0) { int i; for (i = 0; i < ret; i++) { if (strcmp(q[i].fs_file, p) == 0) { pjob->sysjob = q[i].sysjob; DEBUG(5, ("new job %u (%s) matches sysjob %d\n", pjob->jobid, jobname, pjob->sysjob)); break; } } SAFE_FREE(q); ret = 0; } if (pjob->sysjob == -1) { DEBUG(2, ("failed to get sysjob for job %u (%s), tracking as " "Unix job\n", pjob->jobid, jobname)); } out: if (chdir(current_directory) == -1) { smb_panic("chdir failed in generic_job_submit"); } TALLOC_FREE(current_directory); return ret; }
static int generic_job_submit(int snum, struct printjob *pjob) { int ret = -1; char *current_directory = NULL; char *print_directory = NULL; char *wd = NULL; char *p = NULL; char *jobname = NULL; TALLOC_CTX *ctx = talloc_tos(); fstring job_page_count, job_size; /* we print from the directory path to give the best chance of parsing the lpq output */ wd = sys_getwd(); if (!wd) { return -1; } current_directory = talloc_strdup(ctx, wd); SAFE_FREE(wd); if (!current_directory) { return -1; } print_directory = talloc_strdup(ctx, pjob->filename); if (!print_directory) { return -1; } p = strrchr_m(print_directory,'/'); if (!p) { return -1; } *p++ = 0; if (chdir(print_directory) != 0) { return -1; } jobname = talloc_strdup(ctx, pjob->jobname); if (!jobname) { ret = -1; goto out; } jobname = talloc_string_sub(ctx, jobname, "'", "_"); if (!jobname) { ret = -1; goto out; } slprintf(job_page_count, sizeof(job_page_count)-1, "%d", pjob->page_count); slprintf(job_size, sizeof(job_size)-1, "%lu", (unsigned long)pjob->size); /* send it to the system spooler */ ret = print_run_command(snum, lp_printername(snum), True, lp_printcommand(snum), NULL, "%s", p, "%J", jobname, "%f", p, "%z", job_size, "%c", job_page_count, NULL); out: if (chdir(current_directory) == -1) { smb_panic("chdir failed in generic_job_submit"); } TALLOC_FREE(current_directory); return ret; }
int main(int argc, char *argv[]) { char *p, *u; const char *libd = dyn_LIBDIR; pstring line, wd; int opt; extern char *optarg; extern int optind; dbf = x_stdout; smbw_setup_shared(); while ((opt = getopt(argc, argv, "W:U:R:d:P:l:hL:")) != EOF) { switch (opt) { case 'L': libd = optarg; break; case 'W': smbw_setshared("WORKGROUP", optarg); break; case 'l': smbw_setshared("LOGFILE", optarg); break; case 'P': smbw_setshared("PREFIX", optarg); break; case 'd': smbw_setshared("DEBUG", optarg); break; case 'U': p = strchr_m(optarg,'%'); if (p) { *p=0; smbw_setshared("PASSWORD",p+1); } smbw_setshared("USER", optarg); break; case 'R': smbw_setshared("RESOLVE_ORDER",optarg); break; case 'h': default: smbsh_usage(); } } if (!smbw_getshared("USER")) { printf("Username: "******"USER", u); } if (!smbw_getshared("PASSWORD")) { p = getpass("Password: "******"PASSWORD", p); } setenv("PS1", "smbsh$ ", 1); sys_getwd(wd); slprintf(line,sizeof(line)-1,"PWD_%d", (int)getpid()); smbw_setshared(line, wd); slprintf(line,sizeof(line)-1,"%s/smbwrapper.so", libd); setenv("LD_PRELOAD", line, 1); slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd); if (file_exist(line, NULL)) { slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so:DEFAULT", libd); setenv("_RLD_LIST", line, 1); slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); setenv("_RLDN32_LIST", line, 1); } else { slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); setenv("_RLD_LIST", line, 1); } { char *shellpath = getenv("SHELL"); if(shellpath) execl(shellpath,"smbsh",NULL); else execl("/bin/sh","smbsh",NULL); } printf("launch failed!\n"); return 1; }
/***************************************************** initialise structures *******************************************************/ void smbw_init(void) { extern BOOL in_client; static int initialised; static pstring servicesf = CONFIGFILE; extern FILE *dbf; char *p; int eno; pstring line; if (initialised) return; initialised = 1; eno = errno; smbw_busy++; DEBUGLEVEL = 0; AllowDebugChange = False; setup_logging("smbsh",True); dbf = stderr; if ((p=smbw_getshared("LOGFILE"))) { dbf = sys_fopen(p, "a"); } smbw_file_bmap = bitmap_allocate(SMBW_MAX_OPEN); if (!smbw_file_bmap) { exit(1); } charset_initialise(); in_client = True; load_interfaces(); if ((p=smbw_getshared("SERVICESF"))) { pstrcpy(servicesf, p); } lp_load(servicesf,True,False,False); codepage_initialise(lp_client_code_page()); get_myname(global_myname); if ((p=smbw_getshared("DEBUG"))) { DEBUGLEVEL = atoi(p); } if ((p=smbw_getshared("RESOLVE_ORDER"))) { lp_set_name_resolve_order(p); } if ((p=smbw_getshared("PREFIX"))) { slprintf(smbw_prefix,sizeof(fstring)-1, "/%s/", p); all_string_sub(smbw_prefix,"//", "/", 0); DEBUG(2,("SMBW_PREFIX is %s\n", smbw_prefix)); } slprintf(line,sizeof(line)-1,"PWD_%d", (int)getpid()); p = smbw_getshared(line); if (!p) { sys_getwd(smbw_cwd); } pstrcpy(smbw_cwd, p); DEBUG(4,("Initial cwd is %s\n", smbw_cwd)); smbw_busy--; set_maxfiles(SMBW_MAX_OPEN); BlockSignals(True,SIGPIPE); errno = eno; }