ret = (uint64_t)(in*bsize);
- if (ret < in) {
- /* we overflow */
- ret = SMB_NTQUOTAS_NO_LIMIT;
- }
-
- if (in == SMB_QUOTAS_NO_LIMIT)
- ret = SMB_NTQUOTAS_NO_LIMIT;
-
return ret;
}
return ret;
}
-int vfs_get_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype, struct dom_sid *psid, SMB_NTQUOTA_STRUCT *qt)
+NTSTATUS vfs_get_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype,
+ struct dom_sid *psid, SMB_NTQUOTA_STRUCT *qt)
{
int ret;
SMB_DISK_QUOTA D;
ZERO_STRUCT(D);
- if (!fsp||!fsp->conn||!qt)
- return (-1);
+ if (!fsp || !fsp->conn || !qt) {
+ return NT_STATUS_INTERNAL_ERROR;
+ }
ZERO_STRUCT(*qt);
if (psid && !sid_to_uid(psid, &id.uid)) {
DEBUG(0,("sid_to_uid: failed, SID[%s]\n",
sid_string_dbg(psid)));
+ return NT_STATUS_NO_SUCH_USER;
}
- ret = SMB_VFS_GET_QUOTA(fsp->conn, qtype, id, &D);
+ ret = SMB_VFS_GET_QUOTA(fsp->conn, ".", qtype, id, &D);
if (psid)
qt->sid = *psid;
if (ret!=0) {
- return ret;
+ return map_nt_error_from_unix(errno);
}
qt->usedspace = (uint64_t)D.curblocks*D.bsize;
qt->hardlim = limit_unix2nt(D.hardlimit, D.bsize);
qt->qflags = D.qflags;
-
- return 0;
+ return NT_STATUS_OK;
}
int vfs_set_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype, struct dom_sid *psid, SMB_NTQUOTA_STRUCT *qt)
return ret;
}
-static bool allready_in_quota_list(SMB_NTQUOTA_LIST *qt_list, uid_t uid)
+static bool already_in_quota_list(SMB_NTQUOTA_LIST *qt_list, uid_t uid)
{
SMB_NTQUOTA_LIST *tmp_list = NULL;
return (-1);
}
- sys_setpwent();
- while ((usr = sys_getpwent()) != NULL) {
+ setpwent();
+ while ((usr = getpwent()) != NULL) {
SMB_NTQUOTA_STRUCT tmp_qt;
SMB_NTQUOTA_LIST *tmp_list_ent;
struct dom_sid sid;
+ NTSTATUS status;
ZERO_STRUCT(tmp_qt);
- if (allready_in_quota_list((*qt_list),usr->pw_uid)) {
- DEBUG(5,("record for uid[%ld] allready in the list\n",(long)usr->pw_uid));
+ if (already_in_quota_list((*qt_list),usr->pw_uid)) {
+ DEBUG(5,("record for uid[%ld] already in the list\n",(long)usr->pw_uid));
continue;
}
uid_to_sid(&sid, usr->pw_uid);
- if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &tmp_qt)!=0) {
+ status =
+ vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &tmp_qt);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(5, ("failed getting quota for uid[%ld] - %s\n",
+ (long)usr->pw_uid, nt_errstr(status)));
+ continue;
+ }
+ if (tmp_qt.softlim == 0 && tmp_qt.hardlim == 0) {
DEBUG(5,("no quota entry for sid[%s] path[%s]\n",
sid_string_dbg(&sid),
fsp->conn->connectpath));
DLIST_ADD((*qt_list),tmp_list_ent);
}
- sys_endpwent();
+ endpwent();
+ if (*qt_list == NULL) {
+ TALLOC_FREE(mem_ctx);
+ }
return 0;
}
static int quota_handle_destructor(SMB_NTQUOTA_HANDLE *handle)
{
- if (handle->quota_list)
- free_ntquota_list(&handle->quota_list);
+ free_ntquota_list(&handle->quota_list);
return 0;
}
SMB_NTQUOTA_HANDLE *qt_handle;
if (!mem_ctx)
- return False;
+ return NULL;
qt_handle = talloc_zero(mem_ctx,SMB_NTQUOTA_HANDLE);
if (qt_handle==NULL) {