comparison src/lib/eacces-error.c @ 9168:2bbf175bb6d3 HEAD

Whenever file's group changing fails, show the group origin in the error message.
author Timo Sirainen <tss@iki.fi>
date Sat, 27 Jun 2009 20:39:30 -0400
parents c69a1d0a6bd6
children 6d7f6ea02e17
comparison
equal deleted inserted replaced
9167:5379a940d62a 9168:2bbf175bb6d3
86 const char *prev_path = path, *dir = "/", *p; 86 const char *prev_path = path, *dir = "/", *p;
87 const struct passwd *pw; 87 const struct passwd *pw;
88 const struct group *group; 88 const struct group *group;
89 string_t *errmsg; 89 string_t *errmsg;
90 struct stat st, dir_st; 90 struct stat st, dir_st;
91 int ret = -1; 91 int orig_errno, ret = -1;
92 92
93 orig_errno = errno;
93 errmsg = t_str_new(256); 94 errmsg = t_str_new(256);
94 str_printfa(errmsg, "%s(%s) failed: Permission denied (euid=%s", 95 str_printfa(errmsg, "%s(%s) failed: Permission denied (euid=%s",
95 func, path, dec2str(geteuid())); 96 func, path, dec2str(geteuid()));
96 97
97 pw = getpwuid(geteuid()); 98 pw = getpwuid(geteuid());
143 str_printfa(errmsg, " missing +w perm: %s", path); 144 str_printfa(errmsg, " missing +w perm: %s", path);
144 } else 145 } else
145 str_printfa(errmsg, " UNIX perms seem ok, ACL problem?"); 146 str_printfa(errmsg, " UNIX perms seem ok, ACL problem?");
146 } 147 }
147 str_append_c(errmsg, ')'); 148 str_append_c(errmsg, ')');
149 errno = orig_errno;
148 return str_c(errmsg); 150 return str_c(errmsg);
149 } 151 }
150 152
151 const char *eacces_error_get(const char *func, const char *path) 153 const char *eacces_error_get(const char *func, const char *path)
152 { 154 {
155 157
156 const char *eacces_error_get_creating(const char *func, const char *path) 158 const char *eacces_error_get_creating(const char *func, const char *path)
157 { 159 {
158 return eacces_error_get_full(func, path, TRUE); 160 return eacces_error_get_full(func, path, TRUE);
159 } 161 }
162
163 const char *eperm_error_get_chgrp(const char *func, const char *path,
164 gid_t gid, const char *gid_origin)
165 {
166 string_t *errmsg;
167 const struct group *group;
168 int orig_errno = errno;
169
170 errmsg = t_str_new(256);
171
172 str_printfa(errmsg, "%s(%s, -1, %s", func, path, dec2str(gid));
173 group = getgrgid(gid);
174 if (group != NULL)
175 str_printfa(errmsg, "(%s)", group->gr_name);
176
177 str_printfa(errmsg, ") failed: Operation not permitted (egid=%s",
178 dec2str(getegid()));
179 group = getgrgid(getegid());
180 if (group != NULL)
181 str_printfa(errmsg, "(%s)", group->gr_name);
182 if (gid_origin != NULL)
183 str_printfa(errmsg, ", group based on %s", gid_origin);
184 str_append_c(errmsg, ')');
185 errno = orig_errno;
186 return str_c(errmsg);
187 }