Exemple #1
0
func changeUser(username string) error {
	currentUser, err := user.Current()
	if err != nil {
		return util.Errorf("Could not determine current user: %s", err)
	}

	uid, gid, err := p2_user.IDs(username)
	if err != nil {
		return util.Errorf("Could not retrieve uid/gid for %q: %s", username, err)
	}

	if strconv.Itoa(uid) == currentUser.Uid && strconv.Itoa(gid) == currentUser.Gid {
		return nil
	}

	userCstring := C.CString(username)
	defer C.free(unsafe.Pointer(userCstring))

	ret, err := C.initgroups(userCstring, C.__gid_t(gid))
	if ret != 0 && err != nil {
		return util.Errorf("Could not initgroups for %q (primary gid %v): %s", username, gid, err)
	}
	ret, err = C.setgid(C.__gid_t(gid))
	if ret != 0 && err != nil {
		return util.Errorf("Could not setgid %v: %s", gid, err)
	}
	ret, err = C.setuid(C.__uid_t(uid))
	if ret != 0 && err != nil {
		return util.Errorf("Could not setuid %v: %s", uid, err)
	}
	return nil
}
Exemple #2
0
//Setuid set the uid to uid
func Setuid(uid int) error {
	ret, err := C.setuid(C.__uid_t(uid))
	if ret == C.int(0) {
		return nil
	}

	return err
}
Exemple #3
0
// Set updates parameters of the shared memory segment.
func (shm *SharedMem) Set(info *SHMInfo) error {
	shmds := &C.struct_shmid_ds{
		shm_perm: C.struct_ipc_perm{
			uid:  C.__uid_t(info.Perms.OwnerUID),
			gid:  C.__gid_t(info.Perms.OwnerGID),
			mode: C.ushort(info.Perms.Mode & 0x1FF),
		},
	}

	rc, err := C.shmctl(C.int(shm.id), C.IPC_SET, shmds)
	if rc == -1 {
		return err
	}
	return nil
}
Exemple #4
0
// Set updates parameters of the semaphore set.
func (ss *SemaphoreSet) Set(ssi *SemSetInfo) error {
	sds := &C.struct_semid_ds{
		sem_perm: C.struct_ipc_perm{
			uid:  C.__uid_t(ssi.Perms.OwnerUID),
			gid:  C.__gid_t(ssi.Perms.OwnerGID),
			mode: C.ushort(ssi.Perms.Mode & 0x1FF),
		},
	}

	rc, err := C.semctl_buf(C.int(ss.id), C.IPC_SET, sds)
	if rc == -1 {
		return err
	}
	return nil
}
Exemple #5
0
// Set updates parameters of the queue.
func (mq MessageQueue) Set(mqi *MQInfo) error {
	mqds := &C.struct_msqid_ds{
		msg_perm: C.struct_ipc_perm{
			uid:  C.__uid_t(mqi.Perms.OwnerUID),
			gid:  C.__gid_t(mqi.Perms.OwnerGID),
			mode: C.ushort(mqi.Perms.Mode & 0x1FF),
		},
		msg_qbytes: C.msglen_t(mqi.MaxBytes),
	}

	rc, err := C.msgctl(C.int(mq), C.IPC_SET, mqds)
	if rc == -1 {
		return err
	}
	return nil
}
func (a *InoAttr) toCStat(o *C.struct_stat, timeout *C.double) {
	o.st_ino = C.__ino_t(a.Ino)
	o.st_mode = C.__mode_t(a.Mode)
	o.st_nlink = C.__nlink_t(a.Nlink)
	o.st_size = C.__off_t(a.Size)
	if a.Uid != nil {
		o.st_uid = C.__uid_t(*a.Uid)
	}
	if a.Gid != nil {
		o.st_gid = C.__gid_t(*a.Gid)
	}
	toCTime(&o.st_ctim, a.Ctim)
	toCTime(&o.st_mtim, a.Mtim)
	toCTime(&o.st_atim, a.Atim)
	if timeout != nil {
		(*timeout) = C.double(a.Timeout)
	}
}
Exemple #7
0
func changeUser(username string) error {
	uid, gid, err := user.IDs(username)
	if err != nil {
		return util.Errorf("Could not retrieve uid/gid for %q: %s", username, err)
	}

	userCstring := C.CString(username)
	defer C.free(unsafe.Pointer(userCstring))

	ret, err := C.initgroups(userCstring, C.__gid_t(gid))
	if ret != 0 && err != nil {
		return util.Errorf("Could not initgroups for %q (primary gid %v): %s", username, gid, err)
	}
	ret, err = C.setgid(C.__gid_t(gid))
	if ret != 0 && err != nil {
		return util.Errorf("Could not setgid %v: %s", gid, err)
	}
	ret, err = C.setuid(C.__uid_t(uid))
	if ret != 0 && err != nil {
		return util.Errorf("Could not setuid %v: %s", uid, err)
	}
	return nil
}