int prefetch_filesys(struct query *q, char *argv[], client *cl);
int setup_ausr(struct query *q, char *argv[], client *cl);
int setup_dusr(struct query *q, char *argv[], client *cl);
-int setup_spop(struct query *q, char *argv[], client *cl);
int setup_dpob(struct query *q, char *argv[], client *cl);
int setup_dmac(struct query *q, char *argv[], client *cl);
int setup_dclu(struct query *q, char *argv[], client *cl);
/* prototypes from qsupport.pc */
int set_pobox(struct query *q, char *argv[], client *cl);
+int set_pobox_pop(struct query *q, char *argv[], client *cl);
int add_member_to_list(struct query *q, char *argv[], client *cl);
int delete_member_from_list(struct query *q, char *argv[], client *cl);
int register_user(struct query *q, char *argv[], client *cl);
}
-/* setup_spop: verify that there is already a valid POP machine_id in the
- * pop_id field. Also take care of keeping track of the post office usage.
- */
-int setup_spop(struct query *q, char *argv[], client *cl)
-{
- EXEC SQL BEGIN DECLARE SECTION;
- int id, mid;
- char type[USERS_POTYPE_SIZE];
- EXEC SQL END DECLARE SECTION;
-
- id = *(int *)argv[0];
- EXEC SQL SELECT potype, pop_id INTO :type, :mid FROM users
- WHERE users_id = :id;
- if (sqlca.sqlerrd[2] == 0)
- return MR_MACHINE;
- EXEC SQL SELECT mach_id INTO :mid FROM machine
- WHERE mach_id = :mid;
- if (sqlca.sqlerrd[2] == 0)
- return MR_MACHINE;
- if (strcmp(strtrim(type), "POP"))
- set_pop_usage(mid, 1);
- return MR_SUCCESS;
-}
-
-
/* setup_dpob: Take care of keeping track of the post office usage.
*/
int setup_dpob(struct query *q, char *argv[], client *cl)
/* set_pobox - this does all of the real work.
* argv = user_id, type, box
* if type is POP, then box should be a machine, and its ID should be put in
- * pop_id. If type is SMTP, then box should be a string and its ID should
- * be put in box_id. If type is NONE, then box doesn't matter.
+ * pop_id. If type is IMAP, then box should be a filesys, and its ID should
+ * be put in pop_id. If type is SMTP, then box should be a string and its
+ * ID should be put in box_id. If type is NONE, then box doesn't matter.
*/
-
int set_pobox(struct query *q, char **argv, client *cl)
{
EXEC SQL BEGIN DECLARE SECTION;
return MR_MACHINE;
else if (status)
return status;
- EXEC SQL UPDATE users SET potype = 'POP', pop_id = :id
+ EXEC SQL UPDATE users SET potype = 'POP', pop_id = :id, imap_id = 0
WHERE users_id = :user;
set_pop_usage(id, 1);
}
}
else if (!strcmp(argv[1], "IMAP"))
{
- status = name_to_id(box, FILESYS_TABLE, &id);
- if (status == MR_NO_MATCH)
+ EXEC SQL SELECT filsys_id INTO :id FROM filesys
+ WHERE label = :box AND type = 'IMAP';
+ if (sqlca.sqlcode)
return MR_FILESYS;
- else if (status)
- return status;
- EXEC SQL UPDATE users SET potype = 'IMAP', pop_id = :id
+ EXEC SQL UPDATE users SET potype = 'IMAP', imap_id = :id, pop_id = 0
WHERE users_id = :user;
}
else /* argv[1] == "NONE" */
return MR_SUCCESS;
}
+/* set_pobox_pop: Revert to existing POP or IMAP pobox.
+ * Also take care of keeping track of the post office usage.
+ */
+int set_pobox_pop(struct query *q, char **argv, client *cl)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ int id, pid, iid, mid;
+ char type[USERS_POTYPE_SIZE];
+ EXEC SQL END DECLARE SECTION;
+
+ id = *(int *)argv[0];
+ EXEC SQL SELECT potype, pop_id, imap_id INTO :type, :pid, :iid
+ FROM users WHERE users_id = :id;
+ if (sqlca.sqlerrd[2] == 0 || (pid == 0 && iid == 0))
+ return MR_MACHINE;
+
+ if (pid)
+ {
+ EXEC SQL SELECT mach_id INTO :mid FROM machine
+ WHERE mach_id = :pid;
+ if (sqlca.sqlerrd[2] == 0)
+ return MR_MACHINE;
+ EXEC SQL UPDATE users SET potype = 'POP' WHERE users_id = :id;
+ if (strcmp(strtrim(type), "POP"))
+ set_pop_usage(mid, 1);
+ }
+ else
+ {
+ EXEC SQL SELECT filsys_id INTO :mid FROM filesys
+ WHERE filsys_id = :iid;
+ if (sqlca.sqlerrd[2] == 0)
+ return MR_MACHINE;
+ EXEC SQL UPDATE users SET potype = 'IMAP' WHERE users_id = :id;
+ }
+
+ set_pobox_modtime(q, argv, cl);
+ EXEC SQL UPDATE tblstats SET updates = updates + 1, modtime = SYSDATE
+ WHERE table_name = 'users';
+ if (dbms_errno)
+ return mr_errcode;
+ return MR_SUCCESS;
+}
+
+
/* Add_member_to_list: do list flattening as we go! MAXLISTDEPTH is
* how many different ancestors a member is allowed to have.
*/
0,
0,
access_user,
- setup_spop,
- set_pobox_modtime,
+ 0,
+ set_pobox_pop,
};
static struct validate dpob_validate = /* DELETE_POBOX */
RETRIEVE,
"u",
USERS_TABLE,
- "login, potype, pop_id || ':' || box_id, TO_CHAR(pmodtime, 'DD-mon-YYYY HH24:MI:SS'), pmodby, pmodwith FROM users",
+ "login, potype, users_id, TO_CHAR(pmodtime, 'DD-mon-YYYY HH24:MI:SS'), pmodby, pmodwith FROM users",
gpob_fields,
6,
"users_id = %d",
RETRIEVE,
"u",
USERS_TABLE,
- "login, potype, pop_id || ':' || box_id FROM users",
+ "login, potype, users_id FROM users",
gpox_fields,
3,
"potype = 'POP'",
RETRIEVE,
"u",
USERS_TABLE,
- "login, potype, pop_id || ':' || box_id FROM users",
+ "login, potype, users_id FROM users",
gpox_fields,
3,
"potype = 'SMTP'",
UPDATE,
"u",
USERS_TABLE,
- "users SET potype = 'POP'",
+ 0,
spob_fields,
0,
- "users_id = %d",
- 1,
+ NULL,
+ 0,
NULL,
&spop_validate,
},