예제 #1
0
static NTSTATUS cmd_stat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
{
	int ret;
	const char *user;
	const char *group;
	struct passwd *pwd = NULL;
	struct group *grp = NULL;
	SMB_STRUCT_STAT st;

	if (argc != 2) {
		printf("Usage: stat <fname>\n");
		return NT_STATUS_OK;
	}

	ret = SMB_VFS_STAT(vfs->conn, argv[1], &st);
	if (ret == -1) {
		printf("stat: error=%d (%s)\n", errno, strerror(errno));
		return NT_STATUS_UNSUCCESSFUL;
	}

	pwd = sys_getpwuid(st.st_uid);
	if (pwd != NULL) user = pwd->pw_name;
	else user = null_string;
	grp = sys_getgrgid(st.st_gid);
	if (grp != NULL) group = grp->gr_name;
	else group = null_string;

	printf("stat: ok\n");
	printf("  File: %s", argv[1]);
	if (S_ISREG(st.st_mode)) printf("  Regular File\n");
	else if (S_ISDIR(st.st_mode)) printf("  Directory\n");
	else if (S_ISCHR(st.st_mode)) printf("  Character Device\n");
	else if (S_ISBLK(st.st_mode)) printf("  Block Device\n");
	else if (S_ISFIFO(st.st_mode)) printf("  Fifo\n");
	else if (S_ISLNK(st.st_mode)) printf("  Symbolic Link\n");
	else if (S_ISSOCK(st.st_mode)) printf("  Socket\n");
	printf("  Size: %10u", (unsigned int)st.st_size);
#ifdef HAVE_STAT_ST_BLOCKS
	printf(" Blocks: %9u", (unsigned int)st.st_blocks);
#endif
#ifdef HAVE_STAT_ST_BLKSIZE
	printf(" IO Block: %u\n", (unsigned int)st.st_blksize);
#endif
	printf("  Device: 0x%10x", (unsigned int)st.st_dev);
	printf(" Inode: %10u", (unsigned int)st.st_ino);
	printf(" Links: %10u\n", (unsigned int)st.st_nlink);
	printf("  Access: %05o", (st.st_mode) & 007777);
	printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st.st_uid, user, 
	       (unsigned long)st.st_gid, group);
	printf("  Access: %s", ctime(&(st.st_atime)));
	printf("  Modify: %s", ctime(&(st.st_mtime)));
	printf("  Change: %s", ctime(&(st.st_ctime)));

	SAFE_FREE(pwd);
	SAFE_FREE(grp);
	return NT_STATUS_OK;
}
예제 #2
0
struct passwd *getpwuid_alloc(uid_t uid) 
{
	struct passwd *temp;

	temp = sys_getpwuid(uid);
	
	if (!temp) {
#if 0
		if (errno == ENOMEM) {
			/* what now? */
		}
#endif
		return NULL;
	}

	return alloc_copy_passwd(temp);
}
예제 #3
0
struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid) 
{
	struct passwd *temp;

	temp = sys_getpwuid(uid);
	
	if (!temp) {
#if 0
		if (errno == ENOMEM) {
			/* what now? */
		}
#endif
		return NULL;
	}

	return tcopy_passwd(mem_ctx, temp);
}
예제 #4
0
SMB_STRUCT_WPASSWD *wsys_getpwuid(uid_t uid)
{
	static SMB_STRUCT_WPASSWD retval;
	struct passwd *pwret = sys_getpwuid(uid);

	if(!pwret)
		return NULL;

	unix_to_unicode(retval.pw_name, pwret->pw_name, sizeof(retval.pw_name));
	retval.pw_passwd = pwret->pw_passwd;
	retval.pw_uid = pwret->pw_uid;
	retval.pw_gid = pwret->pw_gid;
	unix_to_unicode(retval.pw_gecos, pwret->pw_gecos, sizeof(retval.pw_gecos));
	unix_to_unicode(retval.pw_dir, pwret->pw_dir, sizeof(retval.pw_dir));
	unix_to_unicode(retval.pw_shell, pwret->pw_shell, sizeof(retval.pw_shell));

	return &retval;
}
예제 #5
0
파일: vlp.c 프로젝트: GunioRobot/rtn56u
static int print_command(int argc, char **argv)
{
	char *printer;
	fstring keystr;
	struct passwd *pw;
	TDB_DATA value;
	struct vlp_job job;
	int i;

	if (argc < 3) {
		printf("Usage: print <printername> <jobname>\n");
		return 1;
	}

	printer = argv[1];

	ZERO_STRUCT(job);

	/* Create a job record */

	for (i = 2; i < argc; i++) {
		fstrcat(job.jobname, argv[i]);
		if (i < argc - 1) {
			fstrcat(job.jobname, " ");
		}
	}

	if (!(pw = sys_getpwuid(getuid()))) {
		return 1;
	}

	fstrcpy(job.owner, pw->pw_name);

	job.jobid = next_jobnum(printer);
	job.size = 666;
	job.submit_time = time(NULL);

	/* Store job entry in queue */

	slprintf(keystr, sizeof(keystr) - 1, "LPQ/%s", printer);
	
	value = tdb_fetch_by_string(tdb, keystr);

	if (value.dptr) {

		/* Add job to end of queue */

		value.dptr = realloc(value.dptr, value.dsize + 
				     sizeof(struct vlp_job));
		if (!value.dptr) return 1;

		memcpy(value.dptr + value.dsize, &job, sizeof(struct vlp_job));

		tdb_store_by_string(tdb, keystr, value.dptr, value.dsize +
				    sizeof(struct vlp_job));

		free(value.dptr);

	} else {
		
		/* Create new queue */

		tdb_store_by_string(tdb, keystr, &job, sizeof(struct vlp_job));
	}		

	return 0;
}
예제 #6
0
enum winbindd_result winbindd_uid_to_sid(struct winbindd_cli_state *state)
{
	DOM_SID sid;

	DEBUG(3, ("[%5lu]: uid to sid %lu\n", (unsigned long)state->pid, 
		  (unsigned long)state->request.data.uid));

	if ( (state->request.data.uid < server_state.uid_low ) 
		|| (state->request.data.uid > server_state.uid_high) )
	{
		struct passwd *pw = NULL;
		enum SID_NAME_USE type;
		unid_t id;
		struct winbindd_domain *domain;

		/* SPECIAL CASE FOR MEMBERS OF SAMBA DOMAINS */
		
		/* if we don't trust /etc/password then when can't know 
		   anything about this uid */
		   
		if ( !lp_winbind_trusted_domains_only() )
			return WINBINDD_ERROR;


		/* look for an idmap entry first */
			
		if ( NT_STATUS_IS_OK(idmap_uid_to_sid(&sid, state->request.data.uid)) ) 
			goto done;
		
		/* if users exist in /etc/passwd, we should try to 
		   use that uid. Get the username and the lookup the SID */

		if ( !(pw = sys_getpwuid(state->request.data.uid)) )
			return WINBINDD_ERROR;

		if ( !(domain = find_our_domain()) ) {
			DEBUG(0,("winbindd_uid_to_sid: can't find my own domain!\n"));
			return WINBINDD_ERROR;
		}

		if ( !winbindd_lookup_sid_by_name(domain, pw->pw_name, &sid, &type) )
			return WINBINDD_ERROR;
		
		if ( type != SID_NAME_USER )
			return WINBINDD_ERROR;
		
		/* don't fail if we can't store it */

		id.uid = pw->pw_uid;
		idmap_set_mapping( &sid, id, ID_USERID );
		
		goto done;
	}

	/* Lookup rid for this uid */
	
	if (!NT_STATUS_IS_OK(idmap_uid_to_sid(&sid, state->request.data.uid))) {
		DEBUG(1, ("Could not convert uid %lu to rid\n",
			  (unsigned long)state->request.data.uid));
		return WINBINDD_ERROR;
	}

done:
	sid_to_string(state->response.data.sid.sid, &sid);
	state->response.data.sid.type = SID_NAME_USER;

	return WINBINDD_OK;
}